Пример #1
0
            private async Task InsertUserAsync(CommandContext context, DiscordUser user, byte level, string reason, bool banUser)
            {
                if (user?.Id == context.User.Id)
                {
                    await context.RespondAsync("You cannot insert yourself in the Trustlist.");
                }
                else if (user.IsBot)
                {
                    await context.RespondAsync("You cannot insert a Bot in the Trustlist.");
                }
                else if ((user as DiscordMember)?.Roles.Any(r => r.Permissions == (r.Permissions & Permissions.ManageGuild)) ?? false)
                {
                    await context.RespondAsync("You cannot insert a server operator in the Trustlist. Demote them first.");
                }
                else if (reason.Length < 5)
                {
                    await context.RespondAsync("Reason is too short");
                }
                else
                {
                    try
                    {
                        GuildConfig config = await guildConfig.FindOrCreateConfigAsync(context.Guild.Id);

                        if (config.ApiLogin is not null)
                        {
                            await _trustlist.SubmitEntryAsync(user.Id, new()
                            {
                                EscalationLevel = level,
                                EscalationNote  = reason
                            }, (await _apiAuth.GetOrUpdateAuthTokenAsync(context.Guild.Id)).Token);

                            string userMention = (user as DiscordMember)?.Mention ?? user.Id.ToString();

                            DiscordEmbed embed = await _trustlist.GetLookupEmbedAsync(user);

                            await context.RespondAsync($"User '{userMention}' successfully inserted into Trustlist.", embed);

                            if (banUser || (config.AutoBanBlacklisted && level >= 3))
                            {
                                await context.Guild.BanMemberAsync(user.Id, 0, $"[SocialGuard] {reason}");

                                await context.Guild.GetChannel(config.BanLogChannel).SendMessageAsync($"Banned user '{userMention}'.", embed);
                            }
                        }
                        else
                        {
                            await context.RespondAsync($"No API Credentials set. Use ``{context.Prefix}sg config accesskey <key>`` to set an Access Key.");
                        }
                    }
                    catch (ApplicationException e)
                    {
                        await context.RespondAsync(e.Message);

#if DEBUG
                        throw;
#endif
                    }
                }
            }
            protected async Task LookupAsync(BaseContext ctx, DiscordUser user)
            {
                await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new() { IsEphemeral = true });

                await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(await _trustlist.GetLookupEmbedAsync(user)));
            }