public async Task Say([Summary("message", "message content the bot shall write")] string message, [Summary("channel", "channel to write the message in, defaults to current")] ITextChannel channel = null) { if (channel is null && Context.Channel is not ITextChannel) { await Context.Interaction.RespondAsync(Translator.T().CmdOnlyTextChannel(), ephemeral : true); return; } if (channel is null) { channel = Context.Channel as ITextChannel; } try { IUserMessage createdMessage = await channel.SendMessageAsync(message); await Context.Interaction.RespondAsync(Translator.T().CmdSaySent(), ephemeral : true); try { GuildConfig guildConfig = await GuildConfigRepository.CreateDefault(ServiceProvider).GetGuildConfig(Context.Guild.Id); if (!string.IsNullOrEmpty(guildConfig.ModInternalNotificationWebhook)) { await DiscordAPI.ExecuteWebhook( guildConfig.ModInternalNotificationWebhook, null, Translator.T().CmdSaySentMod( Context.User, createdMessage, channel ), AllowedMentions.None ); } } catch (Exception ex) { Logger.LogError(ex, $"Something went wrong while sending the internal notification for the say command by {Context.User.Id} in {Context.Guild.Id}/{Context.Channel.Id}."); } } catch (HttpException e) { if (e.HttpCode == HttpStatusCode.Unauthorized) { await Context.Interaction.RespondAsync(Translator.T().CmdCannotViewOrDeleteInChannel(), ephemeral : true); } } catch (Exception e) { Logger.LogError(e, $"Error while writing message in channel {channel.Id}"); await Context.Interaction.RespondAsync(Translator.T().CmdSayFailed(), ephemeral : true); } }
public async Task Report(IMessage msg) { GuildConfig guildConfig = await GuildConfigRepository.CreateDefault(ServiceProvider).GetGuildConfig(Context.Guild.Id); if (string.IsNullOrEmpty(guildConfig.ModInternalNotificationWebhook)) { await Context.Interaction.RespondAsync(Translator.T().CmdNoWebhookConfigured(), ephemeral : true); return; } StringBuilder sb = new(); sb.AppendLine(Translator.T().CmdReportContent(Context.User, msg, msg.Channel as ITextChannel)); if (!string.IsNullOrEmpty(msg.Content)) { sb.Append("```\n"); sb.Append(msg.Content.Truncate(1024)); sb.Append("\n``` "); } if (msg.Attachments.Count > 0) { sb.AppendLine(Translator.T().Attachments()); foreach (IAttachment attachment in msg.Attachments.Take(5)) { sb.Append($"- <{attachment.Url}>\n"); } if (msg.Attachments.Count > 5) { sb.AppendLine(Translator.T().AndXMore(msg.Attachments.Count - 5)); } } try { await DiscordAPI.ExecuteWebhook(guildConfig.ModInternalNotificationWebhook, null, sb.ToString(), AllowedMentions.None); } catch (Exception e) { Logger.LogError(e, "Failed to send internal notification to moderators for report command."); await Context.Interaction.RespondAsync(Translator.T().CmdReportFailed(), ephemeral : true); return; } await Context.Interaction.RespondAsync(Translator.T().CmdReportSent(), ephemeral : true); }