From da7078f535baee9327f0ea6a13640a36481ab16a Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Tue, 22 Aug 2023 14:58:44 -0400 Subject: [PATCH] clear out detiktokable links when done fixes #18 --- Behavior/Behaver.cs | 7 +-- Behavior/Detiktokify.cs | 4 ++ .../TwitchInterface/TwitchInterface.cs | 50 ++++++++++--------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Behavior/Behaver.cs b/Behavior/Behaver.cs index 77817de..5615386 100644 --- a/Behavior/Behaver.cs +++ b/Behavior/Behaver.cs @@ -45,6 +45,7 @@ public class Behaver { behavior.ActOn(message); message.ActedOn = true; + Console.WriteLine("acted on, moving forward"); } } if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) @@ -52,15 +53,11 @@ public class Behaver Console.WriteLine("providing bullshit nonanswer / admitting uselessness"); var responses = new List(){ @"Well, that's a great question, and there are certainly many different possible answers. Ultimately, the decision will depend on a variety of factors, including your personal interests and goals, as well as any practical considerations (like the economy). I encourage you to do your research, speak with experts and educators, and explore your options before making a decision that's right for you.", - @"┐(゚ ~゚ )┌",@"¯\_(ツ)_/¯",@"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭" + @"┐(゚ ~゚ )┌", @"¯\_(ツ)_/¯", @"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭" }; await message.Channel.SendMessage(responses[Shared.r.Next(responses.Count)]); message.ActedOn = true; } - if (message.ActedOn) - { - _db.SaveChanges(); - } return message.ActedOn; } } diff --git a/Behavior/Detiktokify.cs b/Behavior/Detiktokify.cs index 25b8ca3..839c036 100644 --- a/Behavior/Detiktokify.cs +++ b/Behavior/Detiktokify.cs @@ -44,12 +44,16 @@ public class Detiktokify : Behavior } } } + if(tiktokLinks.Any()){ + Console.WriteLine($"Should Act on message id {message.ExternalId}; with content {message.Content}"); + } return tiktokLinks.Any(); } public override async Task ActOn(Message message) { foreach(var link in tiktokLinks) { + tiktokLinks.Remove(link); try { Console.WriteLine($"detiktokifying {link}"); diff --git a/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs b/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs index 200be27..3389d4f 100644 --- a/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs +++ b/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs @@ -69,10 +69,10 @@ public class TwitchInterface await SetupTwitchChannel(); WebSocketClient customClient = new WebSocketClient(new ClientOptions - { - MessagesAllowedInPeriod = 750, - ThrottlingPeriod = TimeSpan.FromSeconds(30) - } + { + MessagesAllowedInPeriod = 750, + ThrottlingPeriod = TimeSpan.FromSeconds(30) + } ); client = new TwitchClient(customClient); client.Initialize(new ConnectionCredentials(tc.username, tc.oauth, capabilities: new Capabilities())); @@ -92,30 +92,34 @@ public class TwitchInterface private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e) { Console.WriteLine($"whisper#{e.WhisperMessage.Username}[{DateTime.Now}][{e.WhisperMessage.DisplayName} [id={e.WhisperMessage.Username}]][msg id: {e.WhisperMessage.MessageId}] {e.WhisperMessage.Message}"); + if (_db.Messages.Select(m => m.ExternalId == e.WhisperMessage.MessageId) != null) + { + Console.WriteLine("already seent it"); + return; + } var m = UpsertMessage(e.WhisperMessage); m.Channel.IsDM = true; - m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b"); + _db.SaveChanges(); - if (await Behaver.Instance.ActOn(m)) - { - m.ActedOn = true; - } + await Behaver.Instance.ActOn(m); _db.SaveChanges(); } private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e) { Console.WriteLine($"#{e.ChatMessage.Channel}[{DateTime.Now}][{e.ChatMessage.DisplayName} [id={e.ChatMessage.Username}]][msg id: {e.ChatMessage.Id}] {e.ChatMessage.Message}"); + if (_db.Messages.Select(m => m.ExternalId == e.ChatMessage.Id) != null) + { + Console.WriteLine("already seent it"); + return; + } var m = UpsertMessage(e.ChatMessage); - m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") || e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername; + _db.SaveChanges(); - if (await Behaver.Instance.ActOn(m)) - { - m.ActedOn = true; - } + await Behaver.Instance.ActOn(m); _db.SaveChanges(); } @@ -154,10 +158,10 @@ public class TwitchInterface //acc.IsBot = acc.Protocol = PROTOCOL; - if(hadToAdd) + if (hadToAdd) { acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol)); - if(acc.IsUser == null) + if (acc.IsUser == null) { acc.IsUser = new vassago.Models.User() { Accounts = new List() { acc } }; _db.Users.Add(acc.IsUser); @@ -181,8 +185,8 @@ public class TwitchInterface c.Protocol = PROTOCOL; c.ParentChannel = protocolAsChannel; c.SubChannels = c.SubChannels ?? new List(); - c.SendMessage = (t) => { return Task.Run(() => {client.SendMessage(channelName, t); }); }; - c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; + c.SendMessage = (t) => { return Task.Run(() => { client.SendMessage(channelName, t); }); }; + c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; return c; throw new NotImplementedException(); } @@ -201,8 +205,8 @@ public class TwitchInterface c.Protocol = PROTOCOL; c.ParentChannel = protocolAsChannel; c.SubChannels = c.SubChannels ?? new List(); - c.SendMessage = (t) => { return Task.Run(() => {client.SendWhisper(whisperWith, t); }); }; - c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; + c.SendMessage = (t) => { return Task.Run(() => { client.SendWhisper(whisperWith, t); }); }; + c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; return c; throw new NotImplementedException(); } @@ -214,7 +218,7 @@ public class TwitchInterface { m = new Message(); _db.Messages.Add(m); - m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); + m.Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); } m.Content = chatMessage.Message; @@ -234,7 +238,7 @@ public class TwitchInterface { m = new Message(); _db.Messages.Add(m); - m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); + m.Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); } m.Content = whisperMessage.Message; @@ -244,7 +248,7 @@ public class TwitchInterface m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id); m.Author.SeenInChannel = m.Channel; - m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });}; + m.Reply = (t) => { return Task.Run(() => { client.SendWhisper(whisperMessage.Username, t); }); }; m.React = (e) => { throw new InvalidOperationException($"twitch cannot react"); }; return m; }