Nullable incoming module config
This commit is contained in:
parent
11ac7418c6
commit
9d04d22a71
9 changed files with 9 additions and 9 deletions
|
@ -12,7 +12,7 @@ internal class AutoResponder : RegexbotModule {
|
||||||
DiscordClient.MessageReceived += DiscordClient_MessageReceived;
|
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);
|
if (config == null) return Task.FromResult<object?>(null);
|
||||||
var defs = new List<Definition>();
|
var defs = new List<Definition>();
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ internal sealed class EntryRole : RegexbotModule, IDisposable {
|
||||||
return Task.CompletedTask;
|
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 == null) return Task.FromResult<object?>(null);
|
||||||
|
|
||||||
if (config.Type != JTokenType.Object)
|
if (config.Type != JTokenType.Object)
|
||||||
|
|
|
@ -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);
|
if (config == null) return Task.FromResult<object?>(null);
|
||||||
|
|
||||||
var conf = new ModuleConfig(this, config);
|
var conf = new ModuleConfig(this, config);
|
||||||
|
|
|
@ -15,7 +15,7 @@ internal partial class ModLogs : RegexbotModule {
|
||||||
bot.SharedEventReceived += HandleReceivedSharedEvent;
|
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 == null) return Task.FromResult<object?>(null);
|
||||||
if (config.Type != JTokenType.Object)
|
if (config.Type != JTokenType.Object)
|
||||||
throw new ModuleLoadException("Configuration for this section is invalid.");
|
throw new ModuleLoadException("Configuration for this section is invalid.");
|
||||||
|
|
|
@ -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 == null) return Task.FromResult<object?>(null);
|
||||||
if (config.Type != JTokenType.Object)
|
if (config.Type != JTokenType.Object)
|
||||||
throw new ModuleLoadException("Configuration for this section is invalid.");
|
throw new ModuleLoadException("Configuration for this section is invalid.");
|
||||||
|
|
|
@ -12,7 +12,7 @@ internal class RegexModerator : RegexbotModule {
|
||||||
DiscordClient.MessageUpdated += DiscordClient_MessageUpdated;
|
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);
|
if (config == null) return Task.FromResult<object?>(null);
|
||||||
var defs = new List<ConfDefinition>();
|
var defs = new List<ConfDefinition>();
|
||||||
|
|
||||||
|
|
|
@ -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 == null) return Task.FromResult<object?>(null);
|
||||||
if (config.Type != JTokenType.Object)
|
if (config.Type != JTokenType.Object)
|
||||||
throw new ModuleLoadException("Configuration for this section is invalid.");
|
throw new ModuleLoadException("Configuration for this section is invalid.");
|
||||||
|
|
|
@ -43,7 +43,7 @@ public abstract class RegexbotModule {
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// An object instance containing state and/or configuration information for the guild currently being processed.
|
/// An object instance containing state and/or configuration information for the guild currently being processed.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public abstract Task<object?> CreateGuildStateAsync(ulong guildID, JToken config);
|
public abstract Task<object?> CreateGuildStateAsync(ulong guildID, JToken? config);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the state object that corresponds with the given guild.
|
/// Retrieves the state object that corresponds with the given guild.
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ModuleStateService : Service {
|
||||||
foreach (var module in BotClient.Modules) {
|
foreach (var module in BotClient.Modules) {
|
||||||
var t = module.GetType();
|
var t = module.GetType();
|
||||||
try {
|
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);
|
newStates.Add(t, state);
|
||||||
} catch (ModuleLoadException ex) {
|
} catch (ModuleLoadException ex) {
|
||||||
Log($"{module.Name} failed to read configuration for {guild.Name}: {ex.Message}");
|
Log($"{module.Name} failed to read configuration for {guild.Name}: {ex.Message}");
|
||||||
|
|
Loading…
Reference in a new issue