diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index 7501500..fd31791 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -600,8 +600,9 @@ public class ChatBot _logger.Info($"BossmanJack stream event came in. isLive => {isLive}"); if (isLive) { + var restream = Helpers.GetValue(BuiltIn.Keys.RestreamUrl).Result.Value; SendChatMessage("BossmanJack just went live on Twitch! https://www.twitch.tv/thebossmanjack\r\n" + - "Ad-free re-stream at https://bossmanjack.tv courtesy of @Kees H"); + $"Ad-free re-stream at {restream} courtesy of @Kees H"); IsBmjLive = true; return; } diff --git a/KfChatDotNetBot/Commands/RestreamCommands.cs b/KfChatDotNetBot/Commands/RestreamCommands.cs new file mode 100644 index 0000000..118095f --- /dev/null +++ b/KfChatDotNetBot/Commands/RestreamCommands.cs @@ -0,0 +1,44 @@ +using System.Text.RegularExpressions; +using KfChatDotNetBot.Models.DbModels; +using KfChatDotNetBot.Settings; +using KfChatDotNetWsClient.Models.Events; + +namespace KfChatDotNetBot.Commands; + +public class GetRestreamCommand : ICommand +{ + public List Patterns => [ + new Regex("^restream$") + ]; + + public string? HelpText => "Grab restream URL"; + public UserRight RequiredRight => UserRight.Guest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, + CancellationToken ctx) + { + var url = await Helpers.GetValue(BuiltIn.Keys.RestreamUrl); + botInstance.SendChatMessage($"@{message.Author.Username}, restream URL: {url.Value}", true); + } + +} + +public class SetRestreamCommand : ICommand +{ + public List Patterns => [ + new Regex("^restream set (?.+)$") + ]; + + public string? HelpText => "Set restream URL"; + public UserRight RequiredRight => UserRight.TrueAndHonest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, + CancellationToken ctx) + { + await Helpers.SetValue(BuiltIn.Keys.RestreamUrl, arguments["url"].Value); + botInstance.SendChatMessage($"@{message.Author.Username}, updated URL", true); + } + +} \ No newline at end of file diff --git a/KfChatDotNetBot/Settings/BuiltIn.cs b/KfChatDotNetBot/Settings/BuiltIn.cs index 8e34f48..79a49a9 100644 --- a/KfChatDotNetBot/Settings/BuiltIn.cs +++ b/KfChatDotNetBot/Settings/BuiltIn.cs @@ -420,6 +420,16 @@ public static class BuiltIn Default = "TheBossmanJack", IsSecret = false, CacheDuration = TimeSpan.FromHours(1) + }, + new BuiltInSettingsModel + { + Key = Keys.RestreamUrl, + Regex = ".+", + Description = "URL for the restream", + Default = "No URL set", + IsSecret = false, + // No cache as it's infrequently accessed and should take effect immediately if a user updates it + CacheDuration = TimeSpan.Zero } ]; @@ -459,5 +469,6 @@ public static class BuiltIn public static string FlareSolverrApiUrl = "FlareSolverr.ApiUrl"; public static string FlareSolverrProxy = "FlareSolverr.Proxy"; public static string ChipsggBmjUsername = "Chipsgg.BmjUsername"; + public static string RestreamUrl = "RestreamUrl"; } } \ No newline at end of file