Nullable incoming module config

This commit is contained in:
Noi 2022-10-22 17:47:23 -07:00
parent 11ac7418c6
commit 9d04d22a71
9 changed files with 9 additions and 9 deletions

View file

@ -12,7 +12,7 @@ internal class AutoResponder : RegexbotModule {
DiscordClient.MessageReceived += DiscordClient_MessageReceived;
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
var defs = new List<Definition>();

View file

@ -52,7 +52,7 @@ internal sealed class EntryRole : RegexbotModule, IDisposable {
return Task.CompletedTask;
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
if (config.Type != JTokenType.Object)

View file

@ -15,7 +15,7 @@ internal class ModCommands : RegexbotModule {
}
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
var conf = new ModuleConfig(this, config);

View file

@ -15,7 +15,7 @@ internal partial class ModLogs : RegexbotModule {
bot.SharedEventReceived += HandleReceivedSharedEvent;
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
if (config.Type != JTokenType.Object)
throw new ModuleLoadException("Configuration for this section is invalid.");

View file

@ -41,7 +41,7 @@ internal class PendingOutRole : RegexbotModule {
}
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
if (config.Type != JTokenType.Object)
throw new ModuleLoadException("Configuration for this section is invalid.");

View file

@ -12,7 +12,7 @@ internal class RegexModerator : RegexbotModule {
DiscordClient.MessageUpdated += DiscordClient_MessageUpdated;
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
var defs = new List<ConfDefinition>();

View file

@ -43,7 +43,7 @@ internal class VoiceRoleSync : RegexbotModule {
}
}
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken config) {
public override Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config) {
if (config == null) return Task.FromResult<object?>(null);
if (config.Type != JTokenType.Object)
throw new ModuleLoadException("Configuration for this section is invalid.");

View file

@ -43,7 +43,7 @@ public abstract class RegexbotModule {
/// <returns>
/// An object instance containing state and/or configuration information for the guild currently being processed.
/// </returns>
public abstract Task<object?> CreateGuildStateAsync(ulong guildID, JToken config);
public abstract Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config);
/// <summary>
/// Retrieves the state object that corresponds with the given guild.

View file

@ -76,7 +76,7 @@ class ModuleStateService : Service {
foreach (var module in BotClient.Modules) {
var t = module.GetType();
try {
var state = await module.CreateGuildStateAsync(guild.Id, guildConf[module.Name]!);
var state = await module.CreateGuildStateAsync(guild.Id, guildConf[module.Name]);
newStates.Add(t, state);
} catch (ModuleLoadException ex) {
Log($"{module.Name} failed to read configuration for {guild.Name}: {ex.Message}");