Refactored to fix compiler warnings

This commit is contained in:
barelyprofessional
2025-07-07 20:12:07 -05:00
parent bcc3bde6c9
commit 5f189cb9cc
28 changed files with 279 additions and 228 deletions

View File

@@ -88,6 +88,7 @@ public class NewKickChannelCommand : ICommand
{
var channels = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.KickChannels)).JsonDeserialize<List<KickChannelModel>>();
var channelId = Convert.ToInt32(arguments["channel_id"].Value);
channels ??= [];
if (channels.Any(channel => channel.ChannelId == channelId))
{
await botInstance.SendChatMessageAsync("Channel is already in the database", true);
@@ -119,6 +120,7 @@ public class RemoveKickChannelCommand : ICommand
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var channels = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.KickChannels)).JsonDeserialize<List<KickChannelModel>>();
if (channels == null) throw new Exception("Caught a null when deserializing Kick channels");
var channelId = Convert.ToInt32(arguments["channel_id"].Value);
var channel = channels.FirstOrDefault(ch => ch.ChannelId == channelId);
if (channel == null)
@@ -144,6 +146,11 @@ public class ReconnectKickCommand : ICommand
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
if (botInstance.BotServices.KickClient == null)
{
await botInstance.SendChatMessageAsync("Kick client is not initialized", true);
return;
}
botInstance.BotServices.KickClient.Disconnect();
await botInstance.SendChatMessageAsync("Disconnected from Kick. Client should reconnect shortly.", true);
}
@@ -365,6 +372,11 @@ public class SetAlmanacIntervalCommand : ICommand
return;
}
await SettingsProvider.SetValueAsync(BuiltIn.Keys.BotAlmanacInterval, arguments["interval"].Value);
if (botInstance.BotServices.AlmanacShill == null)
{
await botInstance.SendChatMessageAsync("Value has been saved but almanac shill has not been initialized", true);
return;
}
await botInstance.BotServices.AlmanacShill.StopShillTaskAsync();
botInstance.BotServices.AlmanacShill.StartShillTask();
await botInstance.SendChatMessageAsync($"@{message.Author.Username}, updated interval and restarted the shill task", true);
@@ -383,6 +395,11 @@ public class StopAlmanacCommand : ICommand
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
if (botInstance.BotServices.AlmanacShill == null)
{
await botInstance.SendChatMessageAsync("AlmanacShill is null", true);
return;
}
if (!botInstance.BotServices.AlmanacShill.IsShillTaskRunning())
{
await botInstance.SendChatMessageAsync("Looks like the task isn't even running", true);
@@ -407,6 +424,11 @@ public class StartAlmanacCommand : ICommand
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
if (botInstance.BotServices.AlmanacShill == null)
{
await botInstance.SendChatMessageAsync("AlmanacShill is null", true);
return;
}
if (botInstance.BotServices.AlmanacShill.IsShillTaskRunning())
{
await botInstance.SendChatMessageAsync("Looks like the task is already running", true);

View File

@@ -79,7 +79,7 @@ public class ExceptionTestCommand : ICommand
public UserRight RequiredRight => UserRight.Admin;
// Increased timeout as it has to wait for Sneedchat to echo the message and that can be slow sometimes
public TimeSpan Timeout => TimeSpan.FromSeconds(15);
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
public Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
throw new Exception("Caused by the test exception command");
}

View File

@@ -64,8 +64,14 @@ public class GetVersionCommand : ICommand
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var version = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
var version = Assembly.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (version == null)
{
await botInstance.SendChatMessageAsync($"Caught a null when trying to retrieve the bot's assembly version.",
true);
return;
}
await botInstance.SendChatMessageAsync($"Bot compiled against {version.Split('+')[1]}", true);
}
}