From c0c8ba655f9c87b00f623e6929ed2898168d8dbe Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:40:44 +0800 Subject: [PATCH] Added Gamba Sesh presence detection, cooldown on start to prevent responding to chat buffer, super basic commands, notifications, message forwarding from Kick, memory so that it doesn't answer messages already seen (too bad if you edit) --- KfChatDotNetKickBot/KickBot.cs | 63 ++++++++++++++++++++++++++++++++++ KfChatDotNetKickBot/Models.cs | 4 +++ 2 files changed, 67 insertions(+) diff --git a/KfChatDotNetKickBot/KickBot.cs b/KfChatDotNetKickBot/KickBot.cs index d1eb1a6..8b8bf84 100644 --- a/KfChatDotNetKickBot/KickBot.cs +++ b/KfChatDotNetKickBot/KickBot.cs @@ -18,6 +18,12 @@ public class KickBot private Models.ConfigModel _config; private Thread _pingThread; private bool _pingEnabled = true; + private bool _gambaSeshPresent = false; + // Oh no it's an ever expanding list that may never get cleaned up! + // BUY MORE RAM + private List _seenMsgIds = new List(); + // Suppresses the command handler on initial start so it doesn't pick up things already handled on restart + private bool _initialStartCooldown = true; public KickBot() { @@ -54,6 +60,7 @@ public class KickBot _kickClient.OnChatMessage += OnKickChatMessage; _kickClient.OnWsReconnect += OnPusherWsReconnected; _kickClient.OnPusherSubscriptionSucceeded += OnPusherSubscriptionSucceeded; + _kickClient.OnStopStreamBroadcast += OnStopStreamBroadcast; _kfClient.StartWsClient().Wait(); _kfClient.JoinRoom(_config.KfChatRoomId); @@ -82,6 +89,7 @@ public class KickBot _logger.Debug("Pinging KF and Pusher"); _kfClient.SendMessage("/ping"); _kickClient.SendPusherPing(); + if (_initialStartCooldown) _initialStartCooldown = false; } } @@ -94,7 +102,26 @@ public class KickBot private void OnStreamerIsLive(object sender, KickModels.StreamerIsLiveEventModel? e) { + if (_config.EnableGambaSeshDetect && _gambaSeshPresent) + { + AnsiConsole.MarkupLine("[red]Suppressing live stream notification as GambaSesh is present[/]"); + return; + } + AnsiConsole.MarkupLine("[green]Streamer is live!!![/]"); + _kfClient.SendMessage($"Bossman Live! {e?.Livestream.SessionTitle} https://kick.com/bossmanjack [i]This action was automated"); + } + + private void OnStopStreamBroadcast(object sender, KickModels.StopStreamBroadcastEventModel? e) + { + if (_config.EnableGambaSeshDetect && _gambaSeshPresent) + { + AnsiConsole.MarkupLine("[red]Suppressing live stream notification as GambaSesh is present[/]"); + return; + } + + AnsiConsole.MarkupLine("[green]Stream stopped!!![/]"); + _kfClient.SendMessage("The stream is so over. [i]This action was automated"); } private void OnKfChatMessage(object sender, List messages, MessagesJsonModel jsonPayload) @@ -103,6 +130,24 @@ public class KickBot foreach (var message in messages) { AnsiConsole.MarkupLine($"[yellow]KF[/] <{message.Author.Username}> {message.Message.EscapeMarkup()} ({message.MessageDate.LocalDateTime.ToShortTimeString()})"); + if (!(!_gambaSeshPresent && _config.EnableGambaSeshDetect) && !_seenMsgIds.Contains(message.MessageId) && !_initialStartCooldown) + { + if (message.MessageRaw.StartsWith("!time")) + { + var bmt = new DateTimeOffset(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, + TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").BaseUtcOffset); + _kfClient.SendMessage($"It's currently {bmt:h:mm:ss tt} BMT"); + } + else if (message.MessageRaw.StartsWith("!twisted")) + { + _kfClient.SendMessage("🦍 🗣 GET IT TWISTED 🌪 , GAMBLE ✅ . PLEASE START GAMBLING 👍 . GAMBLING IS AN INVESTMENT 🎰 AND AN INVESTMENT ONLY 👍 . YOU WILL PROFIT 💰 , YOU WILL WIN ❗ ️. YOU WILL DO ALL OF THAT 💯 , YOU UNDERSTAND ⁉ ️ YOU WILL BECOME A BILLIONAIRE 💵 📈 AND REBUILD YOUR FUCKING LIFE 🤯"); + } + else if (message.MessageRaw.StartsWith("!insanity")) + { + _kfClient.SendMessage("definition of insanity = doing the same thing over and over and over excecting a different result, and heres my dumbass trying to get rich every day and losing everythign i fucking touch every fucking time FUCK this bullshit FUCK MY LIEFdefinition of insanity = doing the same thing over and over and over excecting a different result, and heres my dumbass trying to get rich every day and losing everythign i fucking touch every fucking time FUCK this bullshit FUCK MY LIEF"); + } + } + _seenMsgIds.Add(message.MessageId); } } @@ -110,7 +155,17 @@ public class KickBot { if (e == null) return; AnsiConsole.MarkupLine($"[green]Kick[/] <{e.Sender.Username}> {e.Content.EscapeMarkup()} ({e.CreatedAt.LocalDateTime.ToShortTimeString()})"); + AnsiConsole.MarkupLine($"[cyan]BB Code Translation: {e.Content.TranslateKickEmotes().EscapeMarkup()}[/]"); + if (_gambaSeshPresent && _config.EnableGambaSeshDetect) + { + return; + } + if (e.Sender.Slug == "bossmanjack") + { + AnsiConsole.MarkupLine("[green]Message from BossmanJack[/]"); + _kfClient.SendMessage($"[img]{_config.KickIcon}[/img] BossmanJack: {e.Content.TranslateKickEmotes()}"); + } } private void OnUsersJoined(object sender, List users, UsersJsonModel jsonPayload) @@ -118,12 +173,20 @@ public class KickBot _logger.Debug($"Received {users.Count} user join events"); foreach (var user in users) { + if (user.Id == _config.GambaSeshUserId && _config.EnableGambaSeshDetect) + { + _gambaSeshPresent = true; + } AnsiConsole.MarkupLine($"[green]{user.Username.EscapeMarkup()} joined![/]"); } } private void OnUsersParted(object sender, List userIds) { + if (userIds.Contains(_config.GambaSeshUserId) && _config.EnableGambaSeshDetect) + { + _gambaSeshPresent = false; + } _logger.Debug($"Received {userIds.Count} user part events"); foreach (var id in userIds) { diff --git a/KfChatDotNetKickBot/Models.cs b/KfChatDotNetKickBot/Models.cs index 5e6c60f..8fcba8e 100644 --- a/KfChatDotNetKickBot/Models.cs +++ b/KfChatDotNetKickBot/Models.cs @@ -20,5 +20,9 @@ public class Models public int PusherReconnectTimeout { get; set; } = 30; // Todo: Find a way to extract this from the browser as it's not valid forever public string? XfTokenValue { get; set; } + // Because his shitty bot crashed and it's annoying not having notifications + public bool EnableGambaSeshDetect { get; set; } = true; + public int GambaSeshUserId { get; set; } = 168162; + public string KickIcon { get; set; } = "https://i.ibb.co/pzB1Jrq/kick.png"; } } \ No newline at end of file