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 } } }
public async Task ForceLoginAsync(CommandContext ctx) { await _apiAuthService.ClearTokenAsync(ctx.Guild.Id); await _apiAuthService.GetOrUpdateAuthTokenAsync(ctx.Guild.Id); await ctx.RespondAsync("Auth Token successfully refreshed."); logger.LogDebug("Auth Token refreshed for guild {guildId}.", ctx.Guild.Id); }
public async Task GetEmitterAsync(CommandContext context) { GuildConfig config = await guildConfig.FindOrCreateConfigAsync(context.Guild.Id); if (config.ApiLogin is null) { await context.RespondAsync("Please set API Credentials first."); return; } Emitter emitter = await _emitterClient.GetEmitterAsync(await _apiAuthService.GetOrUpdateAuthTokenAsync(context.Guild.Id)); if (emitter is null) { await context.RespondAsync("No Emitter set for provided credentials."); } else { await context.RespondAsync(embed : Utilities.BuildEmitterEmbed(emitter)); } }
public async Task GetEmitterAsync(InteractionContext ctx) { await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new() { IsEphemeral = true }); GuildConfig config = await guildConfig.FindOrCreateConfigAsync(ctx.Guild.Id); if (config.ApiLogin is null) { await ctx.FollowUpAsync("Please set API Credentials first."); return; } Emitter emitter = await _emitterClient.GetEmitterAsync(await _apiAuthService.GetOrUpdateAuthTokenAsync(ctx.Guild.Id)); if (emitter is null) { await ctx.FollowUpAsync("No Emitter set for provided credentials."); } else { await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(Utilities.BuildEmitterEmbed(emitter))); } }