示例#1
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }
            if (msg.Author.IsBot)
            {
                return;
            }

            var context = new CommandContext(_client, msg);

            AuditLog.AddMessageEvent(s);
            StatsLog.AddMessageEvent(s);

            // Check if sender is gagged
            if (AdminModule.mutedNicknames.Contains(s.Author.Username))
            {
                await s.DeleteAsync(); return;
            }

            int argPos = 0;

            if (msg.HasStringPrefix(Config.Load().BotPrefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                await Program.Log(new LogMessage(LogSeverity.Info, "", msg.Author + ": \"" + msg.Content + "\""));

                var result = await _cmds.ExecuteAsync(context, argPos, _services);

                AuditLog.AddCommandResultEvent(result);
                if (!result.IsSuccess)
                {
                    await context.Channel.SendMessageAsync(result.ToString());
                }
            }
            else
            {
                await Program.Log(new LogMessage(LogSeverity.Verbose, "", msg.Author + ": \"" + msg.Content + "\""));
            }
        }
示例#2
0
        /// <summary>
        /// Main problem start
        /// </summary>
        /// <returns></returns>
        public async Task MainAsync()
        {
            await Log(new LogMessage(LogSeverity.Verbose, "", "Bot Started..."));

            Console.ForegroundColor = ConsoleColor.White;

            Config.EnsureExists();
            AuditLog.EnsureExists();
            StatsLog.EnsureExists();

            var botdata = Config.Load();

            // Check if the .json file contains "BotPrefix"
            _client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel         = LogSeverity.Verbose,
                MessageCacheSize = 2000,
            });

            _client.Log += Log;

            _auditLog = new AuditLog();
            _auditLog.Mount(_client);

            _statsLog = new StatsLog();
            _statsLog.Mount(_client);
            // Allow problem to use Auditing

            _cmdHandler = new CommandHandler();
            await _cmdHandler.InstallCommands(_client);

            // Inserts commands into bot

            await Login(botdata);

            await Task.Delay(-1);
        }