Ejemplo n.º 1
0
    protected async Task BroadcastUpdateAsync(BroadcastUpdateType type, ulong userId, TrustlistEntry entry)
    {
        TrustlistUser trustlistUser = null;
        DiscordEmbed  embed         = null;

        using IAsyncCursor <GuildConfig> guilds = await _guildConfig.FindAsync(c => c.BanLogChannel != 0 || c.JoinLogChannel != 0);

        await foreach (GuildConfig guildConfig in guilds.ToAsyncEnumerable())
        {
            try
            {
                DiscordGuild guild = await _discordClient.GetGuildAsync(guildConfig.Id);

                if (guild.Members.GetValueOrDefault(userId) is DiscordMember member)
                {
                    trustlistUser ??= await _trustlistClient.LookupUserAsync(userId);

                    embed ??= Utilities.BuildUserRecordEmbed(trustlistUser, member, entry);
                    DiscordChannel actionLogChannel = guild.GetChannel(guildConfig.BanLogChannel is not 0 ? guildConfig.BanLogChannel : guildConfig.JoinLogChannel);

                    await actionLogChannel.SendMessageAsync(embed : embed, content : type switch
                    {
                        BroadcastUpdateType.NewEntry => $"New Entry added by Emitter **{entry.Emitter.DisplayName}** (`{entry.Emitter.Login}`) for user {member.Mention} :",
                        BroadcastUpdateType.Escalation => $"Entry by Emitter **{entry.Emitter.DisplayName}** (`{entry.Emitter.Login}`) was escalated for user {member.Mention} :",
                        _ => throw new NotImplementedException()
                    });

                    if (trustlistUser.GetMaxEscalationLevel() >= 3 && guildConfig.AutoBanBlacklisted)
                    {
                        await member.BanAsync(0, $"[SocialGuard] \n{entry.EscalationNote}");

                        await actionLogChannel.SendMessageAsync($"User **{member.GetFullUsername()}** ({member.Mention}) banned from Autoban (entry sync).");
                    }
                }
            }
    public async Task OnMemberJoinedAsync(DiscordClient _, GuildMemberAddEventArgs e)
    {
        GuildConfig config = await _configRepository.FindOrCreateConfigAsync(e.Member.Guild.Id);

        if (config.JoinLogChannel is not 0)
        {
            _logger.LogDebug("Fetching Joinlog record for user {userId} in guild {guildId}.", e.Member.Id, e.Guild.Id);

            TrustlistUser user = await _client.LookupUserAsync(e.Member.Id);

            TrustlistEntry entry         = user?.GetLatestMaxEntry();
            byte           maxEscalation = user?.GetMaxEscalationLevel() ?? 0;
            DiscordEmbed   entryEmbed    = Utilities.BuildUserRecordEmbed(user, e.Member);

            if (maxEscalation is 0 && config.SuppressJoinlogCleanRecords)
            {
                _logger.LogDebug("Suppressed clean record for user {userId} in guild {guildId}.", e.Member.Id, e.Guild.Id);
            }
            else
            {
                DiscordChannel joinLog = e.Guild.GetChannel(config.JoinLogChannel);
                await joinLog.SendMessageAsync($"User **{e.Member.GetFullUsername()}** ({e.Member.Mention}) has joined the server.", entryEmbed);
            }

            if (maxEscalation >= 3 && config.AutoBanBlacklisted)
            {
                await e.Member.BanAsync(0, $"[SocialGuard] \n{entry.EscalationNote}");

                await e.Guild.GetChannel(config.BanLogChannel is not 0?config.BanLogChannel : config.JoinLogChannel)
                .SendMessageAsync($"User **{e.Member.GetFullUsername()}** ({e.Member.Mention}) banned on server join.", entryEmbed);
            }
        }
Ejemplo n.º 3
0
            public async Task RespondLookupAsync(CommandContext context, DiscordUser discordUser, bool silenceOnClear = false)
            {
                TrustlistUser user = await _trustlist.LookupUserAsync(discordUser.Id);

                if (!silenceOnClear || user.GetMaxEscalationLevel() is not 0)
                {
                    await context.RespondAsync(Utilities.BuildUserRecordEmbed(user, discordUser));
                }
            }