コード例 #1
0
ファイル: CommandHandler.cs プロジェクト: tandpfun/Globals
        private async Task HandleCommandAsync(SocketMessage pMsg)
        {
            SocketUserMessage message = pMsg as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            var context = new SocketCommandContext(bot, message);

            if (message.Author.IsBot)
            {
                return;
            }

            int argPos = 0;

            if (message.HasStringPrefix(BotConfig.Load().BotPrefix, ref argPos))
            {
                var result = await commands.ExecuteAsync(context, argPos, map);

                if (!result.IsSuccess && result.ErrorReason != "Unknown command.")
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
            else
            {
                if (!ProfanityFilter.HasProfanity(pMsg.Content.ToString()))
                {
                    await HandleGlobalMessageAsync(pMsg);
                }
                else
                {
                    var dbCon = DBConnection.Instance();
                    dbCon.DatabaseName = BotConfig.Load().DatabaseName;
                    if (dbCon.IsConnect())
                    {
                        await pMsg.DeleteAsync();

                        await Message.DeleteAsync(pMsg.Author, dbCon);

                        await UserProfile.AddWarningAsync(pMsg.Author, dbCon);

                        dbCon.Close();
                    }
                }
            }
        }
コード例 #2
0
        public async Task BanUserAsync(IUser User = null)
        {
            if (User != null)
            {
                var dbCon = DBConnection.Instance();
                dbCon.DatabaseName = BotConfig.Load().DatabaseName;
                if (dbCon.IsConnect())
                {
                    if (UserProfile.CanModerate(Context.User.Id, dbCon))
                    {
                        await Context.Message.DeleteAsync();

                        await Message.DeleteAsync(User, dbCon);

                        await UserProfile.AddWarningAsync(User, dbCon, true);

                        await Context.User.SendMessageAsync("You blacklisted " + User.Username + ".");
                    }
                    dbCon.Close();
                }
            }
        }