public async Task DeWhitenUserCommand([Remainder] SocketGuildUser u = null)
        {
            u = u ?? (SocketGuildUser)Context.User;

            var caller = _db.FirstOrDefault <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == Context.User.Id));
            var target = _db.FirstOrDefault <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == u.Id));

            if (caller != null)
            {
                if (target != null)
                {
                    if (target.Id == caller.Id || caller.IsOwner)
                    {
                        _db.DeleteEntity <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == u.Id));
                        Defined.BuildSuccessMessage(_eBuilder, Context, $"Successfully removed the User **{u.Username}#{u.Discriminator}** from the Whitelist");
                    }
                    else
                    {
                        Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E410, null, "remove a User who isn't yourself from the Whitelist");
                    }
                }
                else
                {
                    Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, $"{u.Username}#{u.Discriminator}", "User", "the Whitelist");
                }
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E409, null, "remove a User from the Whitelist");
            }
            await ReplyAsync(embed : _eBuilder.Build());
        }
        public async Task AddEmoteToDatabase(Emote em, string nick, ulong userId)
        {
            var emotes = _db.GetAll <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME);

            if (_db.Exists <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME, (x => x.Name.ToLower() == em.Name.ToLower() && x.AdderId == userId)))
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E405, em.ToString(), "Emote", "the Emote Database");
                await Task.CompletedTask;
            }
            else
            {
                bool isDef = !_db.Exists <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME, (x => x.Name.ToLower() == em.Name.ToLower()));

                var result = await AddEmoteToEmoteGuilds(em);

                EeveeEmote nEmote = new EeveeEmote(result.emote, result.guildId, userId, isDef);
                _db.AddEntity(Defined.EEVEE_EMOTES_TABLE_NAME, nEmote);

                _eBuilder.WithTitle(nEmote.Name)
                .WithImageUrl(nEmote.Url)
                .WithUrl(nEmote.Url);

                if (nick != null)
                {
                    AddAliasEmote(nick, nEmote, nEmote.Name, false);
                }
            }
        }
        public async Task RelaunchBotCommand()
        {
            var           whitelist = _db.GetAll <WhitelistUser>(Defined.WHITELIST_TABLE_NAME);
            DirectoryInfo dInfo     = new DirectoryInfo(Directory.GetCurrentDirectory());
            var           path      = dInfo.Parent.FullName + "\\Executions\\";

            if (whitelist.FirstOrDefault(x => x.Id == (Context.User).Id) != null)
            {
                ProcessStartInfo ProcessInfo = new ProcessStartInfo($"{path}Run {_config.Bot_Name}.bat")
                {
                    UseShellExecute = false,
                    CreateNoWindow  = false
                };

                await Task.Run(() => Process.Start(ProcessInfo));

                await Context.Client.LogoutAsync();

                Environment.Exit(0);
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E409, null, $"relaunch {_config.Bot_Name}");
            }
            await ReplyAsync(embed : _eBuilder.Build());
        }
        public async Task WhitenUserCommand([Remainder] SocketGuildUser u = null)
        {
            u = u ?? (SocketGuildUser)Context.User;
            if (u.IsBot)
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E411, null, "added to the Whitelist");
            }
            else
            {
                if (_db.Exists <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == Context.User.Id)))
                {
                    if (!_db.Exists <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == u.Id)))
                    {
                        _db.AddEntity(Defined.WHITELIST_TABLE_NAME, new WhitelistUser(u.Id, _db.IsEmpty <WhitelistUser>((Defined.WHITELIST_TABLE_NAME))));
                        if (_db.Exists <BlacklistUser>(Defined.BLACKLIST_TABLE_NAME, (x => x.Id == Context.User.Id)))
                        {
                            _db.DeleteEntity <BlacklistUser>(Defined.BLACKLIST_TABLE_NAME, (x => x.Id == Context.User.Id));
                        }
                    }

                    Defined.BuildSuccessMessage(_eBuilder, Context, $"Successfully added the User **{u.Username}#{u.Discriminator}** to the Whitelist");
                }
                else
                {
                    Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E410, null, "add a User to the Whitelist");
                }
            }
            await ReplyAsync(embed : _eBuilder.Build());
        }
 public async Task AddEmoteCommand(string emoteCode, [Remainder] string nick = null)
 {
     if (Emote.TryParse(emoteCode, out Emote em))
     {
         await AddEmoteToDatabase(em, nick, Context.User.Id);
     }
     else
     {
         Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, emoteCode, "Emote", "Discord");
     }
     await ReplyAsync(string.Empty, embed : _eBuilder.Build());
 }
        public async Task SudoCommand(SocketGuildUser user, [Remainder] string args)
        {
            var whitelist = _db.GetAll <WhitelistUser>(Defined.WHITELIST_TABLE_NAME);

            if (!_db.Exists <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.IsOwner && x.Id == Context.User.Id)))
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E410, null, "use the Sudo Command");
                await ReplyAsync(embed : _eBuilder.Build());
            }
            else
            {
                var context = new SudoCommandContext(Context.Client, Context.Guild, Context.Channel, user, null);
            }
        }
        public async Task ChangeOwnerCommand([Remainder] SocketGuildUser u = null)
        {
            u = u ?? (SocketGuildUser)Context.User;

            var whitelist = _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).FindAll();

            if (whitelist.FirstOrDefault(x => x.IsOwner) == null)
            {
                var tUser = whitelist.FirstOrDefault(x => x.Id == u.Id);
                if (tUser == null)
                {
                    tUser = new WhitelistUser(u.Id, true);
                    _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Insert(tUser);
                }
                else
                {
                    tUser.IsOwner = true;
                    _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Update(tUser);
                }
            }
            else if (whitelist.FirstOrDefault(x => x.IsOwner).Id == Context.User.Id)
            {
                if (u.Id != Context.User.Id)
                {
                    var currUser = whitelist.FirstOrDefault(x => x.Id == Context.User.Id);
                    currUser.IsOwner = false;

                    var tUser = whitelist.FirstOrDefault(x => x.Id == u.Id);
                    if (tUser == null)
                    {
                        tUser = new WhitelistUser(u.Id, true);
                        _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Insert(tUser);
                    }
                    else
                    {
                        tUser.IsOwner = true;
                        _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Update(tUser);
                    }

                    _db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Update(currUser);
                }
                Defined.BuildSuccessMessage(_eBuilder, Context, $"Successfully changed the Owner of {_config.Bot_Name}");
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E410, null, "change the Owner");
            }
            await ReplyAsync(embed : _eBuilder.Build());
        }
        public async Task SendEmoteCommand([Remainder] string name)
        {
            name = name.Replace(":", string.Empty).ToLower();

            EeveeEmote emote = _db.TryEmoteAssociation(Context.User.Id, name);

            if (emote != null)
            {
                await ReplyAsync(emote.ToString());
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, name, "Emote", "the Emote Database");
                await ReplyAsync(string.Empty, embed : _eBuilder.Build());
            }
        }
        public async Task QuitCommand()
        {
            var whitelist = _db.GetAll <WhitelistUser>(Defined.WHITELIST_TABLE_NAME);

            if (!_db.Exists <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.IsOwner && x.Id == Context.User.Id)))
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E410, null, "use the Quit Command");
                await ReplyAsync(embed : _eBuilder.Build());
            }
            else
            {
                await Context.Client.LogoutAsync();

                Environment.Exit(0);
            }
        }
 private bool CanEvaluate()
 {
     if (!Directory.Exists("Code Evaluation"))
     {
         Directory.CreateDirectory("Code Evaluation");
     }
     if (_db.GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).Count(x => x.Id == Context.User.Id) > 0)
     {
         return(true);
     }
     else
     {
         Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E409, null, "use the Code Evaluation Command");
     }
     return(false);
 }
        public async Task SendEmoteInfo([Remainder] string name)
        {
            name = name.Replace(":", string.Empty).ToLower();
            EeveeEmote emote = _db.TryEmoteAssociation(Context.User.Id, name);

            if (emote != null)
            {
                var aliases = emote.Aliases.Where(x => x.OwnerId == Context.User.Id);

                _eBuilder.WithTitle($"{emote.Name} info:")
                .WithDescription($"Emote information for the user {Context.User.Mention}.")
                .AddField(x =>
                {
                    x.Name     = "__Emote ID__";
                    x.Value    = emote.Id;
                    x.IsInline = true;
                })
                .AddField(x =>
                {
                    x.Name     = "__Owner ID__";
                    x.Value    = emote.AdderId;
                    x.IsInline = true;
                })
                .AddField(x =>
                {
                    x.Name     = "__Is Default?__";
                    x.Value    = emote.IsDefault;
                    x.IsInline = true;
                })
                .AddField(x =>
                {
                    x.Name     = "__Available Aliases__";
                    x.Value    = aliases.Count() > 0 ? string.Join("\n", aliases.Select(y => y.Alias)) : "None.";
                    x.IsInline = true;
                })
                .WithUrl(emote.Url)
                .WithThumbnailUrl(emote.Url);
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, name, "Emote", "the Emote Database");
            }

            await ReplyAsync(string.Empty, embed : _eBuilder.Build());
        }
Esempio n. 12
0
        public async Task SendHelpCommand([Remainder] string arg = null)
        {
            _eBuilder.WithThumbnailUrl(Defined.COOKIE_THUMBNAIL);

            if (arg == null)
            {
                _eBuilder.WithTitle("All Commands")
                .WithDescription($"Use **{_config.Prefixes[0]}**help <module / command name> for help in a specific **Module** or **Command**");
                foreach (var mod in _cmdService.Modules.OrderByDescending(x => x.Commands.Count))
                {
                    _eBuilder.AddField(x =>
                    {
                        x.Name     = $"{mod.Name}";
                        x.Value    = string.Join("\n", mod.Commands.GroupBy(z => z.Name).Select(y => y.FirstOrDefault().Name));
                        x.IsInline = true;
                    });
                }

                await ReplyAsync(string.Empty, embed : _eBuilder.Build());
            }
            else
            {
                arg = arg.ToLower();
                var module = _cmdService.Modules
                             .FirstOrDefault(x => x.Aliases.Select(y => y.ToLower()).Contains(arg));

                if (module != null)
                {
                    await PrepareHelp(module);
                }
                else if (module == null)
                {
                    var command = _cmdService.Commands.FirstOrDefault(x => x.Aliases.Select(y => y.ToLower()).Contains(arg));

                    if (command != null)
                    {
                        await PrepareHelp(command);
                    }
                    else
                    {
                        Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, arg, "Command", _config.Bot_Name);
                    }
                }
            }
        }
 public async Task AddEmoteCommand(ulong emoteId, [Remainder] string nick = null)
 {
     try
     {
         GuildEmote em = Context.Client.Guilds.SelectMany(x => x.Emotes).FirstOrDefault(x => x.Id == emoteId);
         if (em != null)
         {
             await AddEmoteToDatabase(em, nick, Context.User.Id);
         }
         else
         {
             Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, emoteId, "Emote associated with the ID", "Discord");
         }
     }
     catch (Exception)
     {
         Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, emoteId, "Emote associated with the ID", "Discord");
     }
     await ReplyAsync(string.Empty, embed : _eBuilder.Build());
 }
        public async Task DeleteEmoteNicknameCommand([Remainder] string nick)
        {
            nick = nick.Replace(":", string.Empty).ToLower();

            EeveeEmote emote = _db.TryEmoteAssociation(Context.User.Id, nick);

            if (emote != null)
            {
                emote.Aliases.RemoveAll(x => x.Alias.ToLower() == nick);

                _db.UpdateEntity(Defined.EEVEE_EMOTES_TABLE_NAME, emote);

                Defined.BuildSuccessMessage(_eBuilder, Context, $"Deleted the Nickname **{nick}** from the Emote {emote}.");
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, nick, "Alias", "the Emote Database");
            }

            await ReplyAsync(string.Empty, embed : _eBuilder.Build());
        }
        public void AddAliasEmote(string nick, EeveeEmote emote, string name, bool overrideinfo = true)
        {
            if (nick.Length < Defined.NICKNAME_LENGTH_MIN)
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E406, Defined.NICKNAME_LENGTH_MIN, "Nickname (Alias)");
            }
            else if (!_db.Exists <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME, (x => x.Name.ToLower() == nick || x.Aliases.Where(y => y.OwnerId == Context.User.Id).Count(y => y.Alias == nick) > 0)))
            {
                if (emote != null)
                {
                    if (emote.Aliases.Count(x => x.OwnerId == Context.User.Id) > Defined.NICKNAME_COUNT_MAX)
                    {
                        Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E408, null, $"You have exceeded the Aliases capacity limit for this Emote!" +
                                                  $"\nIf you'd really like to add this one, please use {_config.Prefixes[0] }emotes delnick <nick> on " +
                                                  $"one of the following:\n{string.Join("\n", emote.Aliases.Where(x => x.OwnerId == Context.User.Id).Select(x => x.Alias))}");
                    }
                    else
                    {
                        emote.Aliases.Add(new EeveeEmoteAlias()
                        {
                            AssociatedEmoteId = emote.Id,
                            Alias             = nick,
                            OwnerId           = Context.User.Id
                        });

                        _db.UpdateEntity(Defined.EEVEE_EMOTES_TABLE_NAME, emote);
                        Defined.BuildSuccessMessage(_eBuilder, Context, $"Added the Alias **{nick}** to the Emote {emote}.", overrideinfo);
                    }
                }
                else
                {
                    Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, name, "Emote", "the Emote Database", overrideinfo);
                }
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E405, name, "Alias or Emote", "the Emote Database", overrideinfo);
            }
        }
        public async Task DeleteEmoteCommand([Remainder] string name)
        {
            if (_db.Exists <WhitelistUser>(Defined.WHITELIST_TABLE_NAME, (x => x.Id == Context.User.Id)))
            {
                var emotes = _db.GetWhere <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME, (x => x.TryAssociation(name, Context.User.Id)));

                if (emotes.Count() > 0)
                {
                    string pickMesasge = "Please pick one of the following:\n" + string.Join("\n", emotes.Select(x => $"{emotes.ToList().IndexOf(x)} : {x} \\{x}"));
                    await ReplyAsync(pickMesasge);

                    var emote = emotes.FirstOrDefault();


                    _db.DeleteEntity <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME, (x => x.Id == emote.Id));
                    var guild = Context.Client.GetGuild(emote.GuildId);
                    await guild.DeleteEmoteAsync(await guild.GetEmoteAsync(emote.Id));

                    if (guild.Emotes.Count(x => x.Id == emote.Id) < 1)
                    {
                        Defined.BuildSuccessMessage(_eBuilder, Context, $"Successfully deleted the Emote **{name}** from Discord and the Database.");

                        await ReplyAsync(string.Empty, embed : _eBuilder.Build());
                    }
                }
                else
                {
                    Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E404, name, "Emote", "the Emote Database");
                }
            }
            else
            {
                Defined.BuildErrorMessage(_eBuilder, Context, ErrorTypes.E409, null, "delete an Emote from the Database");
            }

            await ReplyAsync(string.Empty, embed : _eBuilder.Build());
        }