Example #1
0
        public Task RemovePhrase(int index = -1)
        {
            List <Admin>    allAdmin = Admins.GetAllAdmins();
            SocketGuildUser user     = Context.Guild.GetUser(Context.User.Id);
            Admin           admin    = allAdmin.Where(x => x.Id == user.Id).FirstOrDefault();
            string          phrase   = String.Empty;

            if (admin.Phrases.Count == 0)
            {
                return(ReplyAsync(embed: GetErrorEmbed().WithDescription("You don't even have any phrases idiot!").Build()));
            }
            else if (index < 0 || index > admin.Phrases.Count)
            {
                return(ReplyAsync(embed: GetErrorEmbed().WithDescription("**Oops!** You typed the wrong position").Build()));
            }

            phrase = admin.Phrases[index];
            admin.Phrases.RemoveAt(index);
            admin.Nickname = user.Nickname;
            admin.Username = user.Username;

            using (StreamWriter file = File.CreateText(Admins.PhrasePath))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, allAdmin);
            }
            var embed = new EmbedBuilder()
            {
                Title  = $"{Context.User.Username} removed **{phrase}** from their phrases!",
                Author = new EmbedAuthorBuilder()
                {
                    IconUrl = Context.User.GetAvatarUrl(), Name = user.Nickname ?? user.Username
                },
                Color = Color.Orange
            };

            return(ReplyAsync(embed: embed.Build()));
        }
Example #2
0
        public Task AddPhrase([Remainder] string phrase)
        {
            SocketGuildUser user    = Context.Guild.GetUser(Context.User.Id);
            SocketRole      theRole = Context.Guild.Roles.Where(x => x.Id == Admins.AdminId).FirstOrDefault();

            if (!user.Roles.Contains(theRole))
            {
                return(ReplyAsync(embed: GetErrorEmbed().WithDescription($"**{Context.User.Username}** is not a {theRole.Name}").Build()));
            }

            List <Admin> allAdmins = Admins.GetAllAdmins();

            Admin currentAdmin = allAdmins?.Where(x => x.Id == user.Id).FirstOrDefault();

            if (currentAdmin == null)
            {
                Admin newAdmin = new Admin
                {
                    Id       = user.Id,
                    Nickname = user.Nickname,
                    Username = user.Username,
                    Phrases  = new List <string>()
                    {
                        phrase
                    }
                };
                allAdmins.Add(newAdmin);
            }
            else
            {
                currentAdmin.Nickname = user.Nickname;
                currentAdmin.Username = user.Username;
                if (currentAdmin.Phrases.Count < 25)
                {
                    currentAdmin.Phrases.Add(phrase);
                }
                else
                {
                    return(ReplyAsync(embed: GetErrorEmbed().WithDescription("MAXED OUT PHRASES!").Build()));
                }
            }


            using (StreamWriter file = File.CreateText(Admins.PhrasePath))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, allAdmins);
            }

            var embed = new EmbedBuilder()
            {
                Title  = $"{Context.User.Username} added **{phrase}** as their new phrase!",
                Author = new EmbedAuthorBuilder()
                {
                    IconUrl = Context.User.GetAvatarUrl(), Name = user.Nickname ?? user.Username
                },
                Color = Color.Orange
            };

            return(ReplyAsync(embed: embed.Build()));
        }