コード例 #1
0
 public MessageDeletedHandler(DiscordSocketClient client, ChannelStats channelStats, Logger logger, CalledEventStats calledEventStats)
 {
     Client           = client;
     Statistics       = channelStats;
     Logger           = logger;
     CalledEventStats = calledEventStats;
 }
コード例 #2
0
ファイル: UserJoinedHandler.cs プロジェクト: janch32/GrillBot
 public UserJoinedHandler(DiscordSocketClient client, IOptions <Configuration> config, Logger logger, CalledEventStats calledEventStats)
 {
     Client           = client;
     Logger           = logger;
     CalledEventStats = calledEventStats;
     Config           = config.Value;
 }
コード例 #3
0
        public GuildMemberUpdatedHandler(DiscordSocketClient client, Logger logger, CalledEventStats calledEventStats)
        {
            Logger           = logger;
            Client           = client;
            CalledEventStats = calledEventStats;

            Client.GuildMemberUpdated += OnGuildMemberUpdatedAsync;
        }
コード例 #4
0
        public GrillBotService(IServiceProvider services, DiscordSocketClient client, CommandService commands, IOptions <Configuration> config,
                               CalledEventStats calledEventStats, InitService initService)
        {
            Services         = services;
            Client           = client;
            Commands         = commands;
            Config           = config.Value;
            CalledEventStats = calledEventStats;
            InitService      = initService;

            Client.Ready += OnClientReadyAsync;
        }
コード例 #5
0
 public MessageReceivedHandler(DiscordSocketClient client, CommandService commands, IOptions <Configuration> config, IServiceProvider services,
                               ChannelStats channelStats, AutoReplyService autoReply, EmoteChain emoteChain, CalledEventStats calledEventStats, Statistics statistics,
                               EmoteStats emoteStats)
 {
     Client           = client;
     Commands         = commands;
     Services         = services;
     ChannelStats     = channelStats;
     AutoReply        = autoReply;
     EmoteChain       = emoteChain;
     CalledEventStats = calledEventStats;
     Statistics       = statistics;
     EmoteStats       = emoteStats;
     Config           = config.Value;
 }
コード例 #6
0
        public async Task PrintEventStatistics()
        {
            await DoAsync(async() =>
            {
                var data = CalledEventStats.ToFormatedDictionary();

                if (data.Count == 0)
                {
                    throw new ArgumentException("Ještě nebyla zavolána žádná událost.");
                }

                var embed = new BotEmbed(Context.Message.Author, title: "Statistika zavolaných událostí")
                            .WithFields(
                    new EmbedFieldBuilder().WithName("Událost").WithValue(string.Join("\n", data.Select(o => o.Key))).WithIsInline(true),
                    new EmbedFieldBuilder().WithName("Počet").WithValue(string.Join("\n", data.Select(o => o.Value))).WithIsInline(true)
                    );

                await ReplyAsync(embed: embed.Build()).ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
コード例 #7
0
 public UserLeftHandler(DiscordSocketClient client, Logger logger, CalledEventStats calledEventStats)
 {
     Client           = client;
     Logger           = logger;
     CalledEventStats = calledEventStats;
 }
コード例 #8
0
 public ReactionAddedHandler(DiscordSocketClient client, EmoteStats emoteStats, CalledEventStats calledEventStats)
 {
     Client           = client;
     EmoteStats       = emoteStats;
     CalledEventStats = calledEventStats;
 }
コード例 #9
0
        private async Task OnMessageReceivedAsync(SocketMessage message)
        {
            CalledEventStats.Increment("MessageReceived");

            var messageStopwatch = new Stopwatch();

            messageStopwatch.Start();

            try
            {
                if (!TryParseMessage(message, out SocketUserMessage userMessage))
                {
                    return;
                }

                var commandStopwatch = new Stopwatch();
                var context          = new SocketCommandContext(Client, userMessage);

                if (message.Channel is IPrivateChannel && !Config.IsUserBotAdmin(userMessage.Author.Id))
                {
                    return;
                }

                int argPos = 0;
                if (userMessage.HasStringPrefix(Config.CommandPrefix, ref argPos) || userMessage.HasMentionPrefix(Client.CurrentUser, ref argPos))
                {
                    await LogCommandAsync(userMessage, context, argPos).ConfigureAwait(false);

                    commandStopwatch.Start();
                    var result = await Commands.ExecuteAsync(context, userMessage.Content.Substring(argPos), Services).ConfigureAwait(false);

                    commandStopwatch.Stop();

                    if (!result.IsSuccess && result.Error != null)
                    {
                        switch (result.Error.Value)
                        {
                        case CommandError.UnknownCommand: return;

                        case CommandError.UnmetPrecondition:
                        case CommandError.ParseFailed:
                            await context.Channel.SendMessageAsync(result.ErrorReason.PreventMassTags()).ConfigureAwait(false);

                            break;

                        case CommandError.BadArgCount:
                            await SendCommandHelp(context, argPos).ConfigureAwait(false);

                            break;

                        default:
                            throw new BotException(result);
                        }
                    }

                    var command = message.Content.Split(' ')[0];
                    Statistics.LogCall(command, commandStopwatch.ElapsedMilliseconds);
                    await EmoteChain.CleanupAsync(context.Channel, true).ConfigureAwait(false);
                }
                else
                {
                    await ChannelStats.IncrementCounterAsync(userMessage.Channel).ConfigureAwait(false);

                    await AutoReply.TryReplyAsync(userMessage).ConfigureAwait(false);

                    await EmoteChain.ProcessChainAsync(context).ConfigureAwait(false);

                    await EmoteStats.AnylyzeMessageAndIncrementValuesAsync(context).ConfigureAwait(false);
                }
            }
            finally
            {
                messageStopwatch.Stop();
                Statistics.ComputeAvgReact(messageStopwatch.ElapsedMilliseconds);
            }
        }
コード例 #10
0
 public GetBotStatusModule(CalledEventStats calledEventStats, BotStatusService botStatusService)
 {
     CalledEventStats = calledEventStats;
     BotStatusService = botStatusService;
 }
コード例 #11
0
 public MessageEditedHandler(DiscordSocketClient client, Logger logger, CalledEventStats calledEventStats)
 {
     Client           = client;
     Logger           = logger;
     CalledEventStats = calledEventStats;
 }
コード例 #12
0
 private async Task OnClientReadyAsync()
 {
     CalledEventStats.Increment("Ready");
     await InitService.InitAsync().ConfigureAwait(false);
 }