示例#1
0
 public async ValueTask HandleLeftGuild(object sender, LeftGuildEventArgs e)
 {
     foreach (var service in LeftGuildServices)
     {
         await ExecuteAsync((service, e) => service.OnLeftGuild(e), service, e).ConfigureAwait(false);
     }
 }
示例#2
0
        public async Task OnLeaveAsync(LeftGuildEventArgs args)
        {
            _logger.Debug(LogSource.Volte, "Left a guild.");
            if (!Config.GuildLogging.Enabled)
            {
                return;
            }
            var joinLeave = Config.GuildLogging;

            if (joinLeave.GuildId is 0 || joinLeave.ChannelId is 0)
            {
                _logger.Error(LogSource.Volte,
                              "Invalid value set for the GuildId or ChannelId in the JoinLeaveLog config option. " +
                              "To fix, set Enabled to false, or correctly fill in your options.");
                return;
            }

            var channel = _client.GetGuild(joinLeave.GuildId).GetTextChannel(joinLeave.ChannelId);

            if (channel is null)
            {
                _logger.Error(LogSource.Volte,
                              "Invalid JoinLeaveLog.GuildId/JoinLeaveLog.ChannelId configuration.");
                return;
            }

            await new EmbedBuilder()
            .WithAuthor(args.Guild.Owner)
            .WithTitle("Left Guild")
            .AddField("Name", args.Guild.Name, true)
            .AddField("ID", args.Guild.Id, true)
            .WithThumbnailUrl(args.Guild.IconUrl)
            .WithErrorColor()
            .SendToAsync(channel);
        }
示例#3
0
        private ValueTask LeftGuildAsync(object sender, LeftGuildEventArgs e)
        {
            if (_guildBuckets.TryRemove(e.GuildId, out var bucket))
            {
                bucket.Complete();
            }

            return(ValueTask.CompletedTask);
        }
示例#4
0
        private async Task OnLeaveAsync(LeftGuildEventArgs args)
        {
            _logger.Debug(LogSource.Volte, "Left a guild.");
            if (!Config.GuildLogging.EnsureValidConfiguration(_client, out var channel))
            {
                _logger.Error(LogSource.Volte, "Invalid guild_logging.guild_id/guild_logging.channel_id configuration. Check your IDs and try again.");
                return;
            }

            await new EmbedBuilder()
            .WithAuthor(args.Guild.Owner)
            .WithTitle("Left Guild")
            .AddField("Name", args.Guild.Name, true)
            .AddField("ID", args.Guild.Id, true)
            .WithThumbnailUrl(args.Guild.IconUrl)
            .WithErrorColor()
            .SendToAsync(channel);
        }
示例#5
0
        private async Task OnGuildLeft(LeftGuildEventArgs args)
        {
            var guild = args.Guild;

            this._logger.LogInformation("Left {guild}", guild.Name);

            using var scope         = this.CreateScope();
            await using var context = scope.ServiceProvider.GetRequiredService <EspeonDbContext>();

            this._logger.LogDebug("Removing {guild}", guild.Name);
            var guildId  = guild.Id.RawValue;
            var prefixes = await context.GuildPrefixes.FindAsync(guildId);

            context.GuildPrefixes.Remove(prefixes);
            var tags = await context.GuildTags.FindAsync(guildId);

            context.GuildTags.Remove(tags);
            await context.SaveChangesAsync();
        }
示例#6
0
        public async Task HandleAsync(LeftGuildEventArgs args)
        {
            using var ctx = new AdminDatabaseContext(_provider);
            var changes = false;

            if (await ctx.Guilds.FindAsync(args.Guild.Id) is { } guild)
            {
                ctx.Guilds.Remove(guild);
                changes = true;
            }

            var channels = await ctx.LoggingChannels.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (channels.Count > 0)
            {
                ctx.LoggingChannels.RemoveRange(channels);
                changes = true;
            }

            var roles = await ctx.SpecialRoles.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (roles.Count > 0)
            {
                ctx.SpecialRoles.RemoveRange(roles);
                changes = true;
            }

            var reactionRoles = await ctx.ReactionRoles.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (reactionRoles.Count > 0)
            {
                ctx.ReactionRoles.RemoveRange(reactionRoles);
                changes = true;
            }

            var users = await ctx.GuildUsers.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (users.Count > 0)
            {
                ctx.GuildUsers.RemoveRange(users);
                changes = true;
            }

            var starboard = await ctx.Starboard.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (starboard.Count > 0)
            {
                ctx.Starboard.RemoveRange(starboard);
                changes = true;
            }

            var aliases = await ctx.CommandAliases.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (aliases.Count > 0)
            {
                ctx.CommandAliases.RemoveRange(aliases);
                changes = true;
            }

            var highlights = await ctx.Highlights.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (highlights.Count > 0)
            {
                ctx.Highlights.RemoveRange(highlights);
                changes = true;
            }

            var rewards = await ctx.LevelRewards.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (rewards.Count > 0)
            {
                ctx.LevelRewards.RemoveRange(rewards);
                changes = true;
            }

            var messages = await ctx.ModmailMessages.Include(x => x.Source).Where(x => x.Source.GuildId == args.Guild.Id).ToListAsync();

            if (messages.Count > 0)
            {
                ctx.ModmailMessages.RemoveRange(messages);
                changes = true;
            }

            var modmails = await ctx.Modmails.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (modmails.Count > 0)
            {
                ctx.Modmails.RemoveRange(modmails);
                changes = true;
            }

            var reminders = await ctx.Reminders.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (reminders.Count > 0)
            {
                ctx.Reminders.RemoveRange(reminders);
                changes = true;
            }

            var punishments = await ctx.Punishments.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (punishments.Count > 0)
            {
                ctx.Punishments.RemoveRange(punishments);
                changes = true;
            }

            var permissions = await ctx.Permissions.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (permissions.Count > 0)
            {
                ctx.Permissions.RemoveRange(permissions);
                changes = true;
            }

            var tags = await ctx.Tags.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (tags.Count > 0)
            {
                ctx.Tags.RemoveRange(tags);
                changes = true;
            }

            var warningPunishments = await ctx.WarningPunishments.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (warningPunishments.Count > 0)
            {
                ctx.WarningPunishments.RemoveRange(warningPunishments);
                changes = true;
            }

            var suggestions = await ctx.Suggestions.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (suggestions.Count > 0)
            {
                ctx.Suggestions.RemoveRange(suggestions);
                changes = true;
            }

            var emojis = await ctx.SpecialEmojis.Where(x => x.GuildId == args.Guild.Id).ToListAsync();

            if (emojis.Count > 0)
            {
                ctx.SpecialEmojis.RemoveRange(emojis);
                changes = true;
            }

            if (changes)
            {
                await ctx.SaveChangesAsync();
            }
        }
 protected internal virtual ValueTask OnLeftGuild(LeftGuildEventArgs e)
 => default;