示例#1
0
        private async Task OnReactionAddedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            InternalStatistics.IncrementEvent("ReactionAdded");

            using var scope = Provider.CreateScope();
            await scope.ServiceProvider.GetService <EmoteStats>().IncrementFromReactionAsync(reaction);

            if (reaction.User.IsSpecified && reaction.User.Value.IsUser())
            {
                await PaginationService.HandleReactionAsync(reaction);

                await scope.ServiceProvider.GetService <UserReactionsService>().IncrementReactionStatsAsync(reaction);

                await scope.ServiceProvider.GetService <ReminderService>().HandleRemindCopyAsync(reaction);

                if (channel is SocketTextChannel textChannel)
                {
                    await scope.ServiceProvider.GetService <PointsService>().IncrementPointsAsync(textChannel.Guild, reaction);
                }

                if (message.HasValue)
                {
                    await scope.ServiceProvider.GetService <ReminderService>().PostponeReminderAsync(message.Value, reaction);
                }
            }
        }
        private async Task OnMessageDeletedAsync(Cacheable <IMessage, ulong> message, ISocketMessageChannel channel)
        {
            InternalStatistics.IncrementEvent("MessageDeleted");
            if (channel is IPrivateChannel || (message.HasValue && !message.Value.Author.IsUser()))
            {
                return;
            }

            SocketGuildUser user = null;

            if (message.HasValue && message.Value.Author is SocketGuildUser guildUser)
            {
                user = guildUser;
            }
            else if (MessageCache.Exists(message.Id))
            {
                var author = MessageCache.Get(message.Id).Author;
                user = author is SocketGuildUser socketGuildUser ? socketGuildUser : null;
            }

            using var scope = Provider.CreateScope();

            if (user != null)
            {
                await scope.ServiceProvider.GetService <UserMessagesService>().DecrementMessageStats(user.Guild, user, channel);
            }

            await Logger.OnMessageDelete(message, channel).ConfigureAwait(false);

            PaginationService.DeleteEmbed(message.Id);
        }
示例#3
0
        private async Task OnUserLeftAsync(SocketGuildUser user)
        {
            InternalStatistics.IncrementEvent("UserLeft");
            await Logger.OnUserLeft(user).ConfigureAwait(false);

            using var scope = Provider.CreateScope();
            await scope.ServiceProvider.GetService <UnverifyService>().OnUserLeftGuildAsync(user);
        }
示例#4
0
        private async Task OnClientReadyAsync()
        {
            InternalStatistics.IncrementEvent("Ready");

            await InitService.InitAsync();

            await SetActivityAsync();
        }
示例#5
0
        private async Task OnUserUnbannedAsync(SocketUser user, SocketGuild guild)
        {
            InternalStatistics.IncrementEvent("UserUnbanned");

            using var scope = ServiceProvider.CreateScope();
            var auditService = scope.ServiceProvider.GetService <AuditService>();

            await auditService.RunTaskAsync(ActionType.Unban, guild);
        }
示例#6
0
        private async Task OnReactionAddedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            InternalStatistics.IncrementEvent("ReactionAdded");

            EmoteStats.IncrementFromReaction(reaction);
            await PaginationService.HandleReactionAsync(reaction);

            UserService.IncrementReaction(reaction);
        }
示例#7
0
        private async Task OnUserJoinedOnServerAsync(SocketGuildUser user)
        {
            InternalStatistics.IncrementEvent("UserJoined");

            await Logger.OnUserJoined(user).ConfigureAwait(false);

            using var scope = Services.CreateScope();
            var inviteTracker = scope.ServiceProvider.GetService <InviteTrackerService>();
            await inviteTracker.OnUserJoinedAsync(user);
        }
示例#8
0
        private async Task OnReactionRemovedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            InternalStatistics.IncrementEvent("ReactionRemoved");

            using var scope = Provider.CreateScope();

            await scope.ServiceProvider.GetService <EmoteStats>().DecrementFromReactionAsync(reaction);

            await scope.ServiceProvider.GetService <UserReactionsService>().DecrementReactionStatsAsync(reaction);
        }
示例#9
0
        private async Task OnUserJoinedOnServerAsync(SocketGuildUser user)
        {
            InternalStatistics.IncrementEvent("UserJoined");

            using var scope = Services.CreateScope();

            await scope.ServiceProvider.GetService <AuditService>().LogUserJoinAsync(user);

            await scope.ServiceProvider.GetService <InviteTrackerService>().OnUserJoinedAsync(user);
        }
        private async Task OnGuildMemberUpdatedAsync(SocketGuildUser guildUserBefore, SocketGuildUser guildUserAfter)
        {
            if (LastEventAt != DateTime.MinValue && (DateTime.UtcNow - LastEventAt).TotalSeconds < 1.0D)
            {
                return;
            }

            InternalStatistics.IncrementEvent("GuildMemberUpdated");

            using var scope = Provider.CreateScope();
            await scope.ServiceProvider.GetService <AuditService>().ProcessBoostChangeAsync(guildUserBefore, guildUserAfter);

            LastEventAt = DateTime.UtcNow;
        }
示例#11
0
        private async Task OnMessageUpdatedAsync(Cacheable <IMessage, ulong> messageBefore, SocketMessage messageAfter, ISocketMessageChannel channel)
        {
            InternalStatistics.IncrementEvent("MessageUpdated");

            if (!messageAfter.Author.IsUser() || channel is IPrivateChannel)
            {
                return;
            }
            if (channel is SocketGuildChannel guildChannel)
            {
                using var scope = Provider.CreateScope();

                await scope.ServiceProvider.GetService <AuditService>().LogMessageEditedAsync(messageBefore, messageAfter, channel, guildChannel.Guild);
            }
        }
示例#12
0
        private async Task OnMessageReceivedAsync(SocketMessage message)
        {
            InternalStatistics.IncrementEvent("MessageReceived");
            if (!TryParseMessage(message, out SocketUserMessage userMessage))
            {
                return;
            }

            var context = new SocketCommandContext(Client, userMessage);

            if (context.IsPrivate)
            {
                return;
            }

            int argPos = 0;

            if (IsCommand(userMessage, ref argPos))
            {
                BotState.RunningCommands.Add(message);
                await Commands.ExecuteAsync(context, userMessage.Content[argPos..], Services).ConfigureAwait(false);
示例#13
0
        private async Task OnMessageReceivedAsync(SocketMessage message)
        {
            InternalStatistics.IncrementEvent("MessageReceived");

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

            var context = new SocketCommandContext(Client, userMessage);

            if (context.IsPrivate)
            {
                return;
            }

            int argPos = 0;

            if (userMessage.HasStringPrefix(Config.CommandPrefix, ref argPos) || userMessage.HasMentionPrefix(Client.CurrentUser, ref argPos))
            {
                await Commands.ExecuteAsync(context, userMessage.Content.Substring(argPos), Services).ConfigureAwait(false);

                if (context.Guild != null)
                {
                    EmoteChain.CleanupAsync((SocketGuildChannel)context.Channel);
                }
            }
            else
            {
                if (context.Guild != null)
                {
                    UserService.IncrementMessage(context.User as SocketGuildUser, context.Guild, context.Channel as SocketGuildChannel);
                    await AutoReply.TryReplyAsync(context.Guild, userMessage).ConfigureAwait(false);
                }

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

                EmoteStats.AnylyzeMessageAndIncrementValues(context);
            }
        }
示例#14
0
 private async Task OnReactionRemovedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
 {
     InternalStatistics.IncrementEvent("ReactionRemoved");
     EmoteStats.DecrementFromReaction(reaction);
     UserService.DecrementReaction(reaction);
 }
示例#15
0
 private async Task OnClientReadyAsync()
 {
     InternalStatistics.IncrementEvent("Ready");
     await InitService.InitAsync().ConfigureAwait(false);
 }