Skip to content

Commit

Permalink
Fetch forum channel auto-warn fallback on startup
Browse files Browse the repository at this point in the history
Also adds handling for when this config value is missing
  • Loading branch information
FloatingMilkshake committed Sep 1, 2024
1 parent 51ec75d commit 54380eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ static async Task DeleteAndWarnAsync(MockDiscordMessage message, string reason,
_ = message.DeleteAsync();
else
if (channel.Type is DiscordChannelType.GuildForum)
channel = await client.GetChannelAsync(Program.cfgjson.ForumChannelAutoWarnFallbackChannel);
if (Program.cfgjson.ForumChannelAutoWarnFallbackChannel == 0)
Program.discord.Logger.LogWarning("A warning in forum channel {channelId} was attempted, but may fail due to the fallback channel not being set. Please set 'forumChannelAutoWarnFallbackChannel' in config.json to avoid this.", channel.Id);
else
channel = Program.ForumChannelAutoWarnFallbackChannel;

try
{
Expand Down Expand Up @@ -147,7 +150,8 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
if (wasAutoModBlock)
{
Program.discord.Logger.LogDebug("Processing AutoMod-blocked message in {channelId} by user {userId}", channel.Id, message.Author.Id);
if (channel.Type == DiscordChannelType.GuildForum) channel = await client.GetChannelAsync(Program.cfgjson.ForumChannelAutoWarnFallbackChannel);
if (channel.Type == DiscordChannelType.GuildForum && Program.cfgjson.ForumChannelAutoWarnFallbackChannel != 0)
channel = Program.ForumChannelAutoWarnFallbackChannel;
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Program : BaseCommandModule
static public readonly HttpClient httpClient = new();

public static List<ServerApiResponseJson> serverApiList = new();

public static DiscordChannel ForumChannelAutoWarnFallbackChannel;

public static void UpdateLists()
{
Expand Down Expand Up @@ -237,6 +239,9 @@ static async Task Main(string[] _)
await discord.ConnectAsync();

await ReadyEvent.OnStartup(discord);

if (cfgjson.ForumChannelAutoWarnFallbackChannel != 0)
ForumChannelAutoWarnFallbackChannel = await discord.GetChannelAsync(cfgjson.ForumChannelAutoWarnFallbackChannel);

// Only wait 3 seconds before the first set of tasks.
await Task.Delay(3000);
Expand Down
2 changes: 1 addition & 1 deletion Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public class ConfigJson
public bool VoiceChannelPurge { get; private set; } = true;

[JsonProperty("forumChannelAutoWarnFallbackChannel")]
public ulong ForumChannelAutoWarnFallbackChannel { get; private set; }
public ulong ForumChannelAutoWarnFallbackChannel { get; private set; } = 0;
}

public enum Level { Information, Warning, Error, Debug, Verbose }
Expand Down

0 comments on commit 54380eb

Please sign in to comment.