diff --git a/Behavior/Behaver.cs b/Behavior/Behaver.cs index 5615386..d269e5d 100644 --- a/Behavior/Behaver.cs +++ b/Behavior/Behaver.cs @@ -11,7 +11,8 @@ using System.Collections.Generic; public class Behaver { private ChattingContext _db; - public List Selves { get; internal set; } = new List(); + private List SelfAccounts { get; set; } = new List(); + private User SelfUser { get; set; } public static List Behaviors { get; private set; } = new List(); internal Behaver() { @@ -48,7 +49,7 @@ public class Behaver 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)) + if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.SelfAccounts.Any(acc => acc.Id == message.Author.Id)) { Console.WriteLine("providing bullshit nonanswer / admitting uselessness"); var responses = new List(){ @@ -60,5 +61,25 @@ public class Behaver } return message.ActedOn; } + + internal bool IsSelf(Guid AccountId) + { + var acc = _db.Accounts.Find(AccountId); + + return SelfAccounts.Any(acc => acc.Id == AccountId); + } + + public void MarkSelf(Account selfAccount) + { + if(SelfUser == null) + { + SelfUser = selfAccount.IsUser; + } + else if (SelfUser != selfAccount.IsUser) + { + //TODO: collapse + } + SelfAccounts = _db.Accounts.Where(a => a.IsUser == SelfUser).ToList(); + } } -#pragma warning restore 4014 //the "async not awaited" error \ No newline at end of file +#pragma warning restore 4014 //the "async not awaited" error diff --git a/Behavior/Behavior.cs b/Behavior/Behavior.cs index 838a9fb..0b27dda 100644 --- a/Behavior/Behavior.cs +++ b/Behavior/Behavior.cs @@ -14,7 +14,7 @@ public abstract class Behavior public virtual bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; return Regex.IsMatch(message.Content, $"{Trigger}\\b", RegexOptions.IgnoreCase); } diff --git a/Behavior/Detiktokify.cs b/Behavior/Detiktokify.cs index 839c036..f6dd9c9 100644 --- a/Behavior/Detiktokify.cs +++ b/Behavior/Detiktokify.cs @@ -26,10 +26,11 @@ public class Detiktokify : Behavior } public override bool ShouldAct(Message message) { - if(message.Channel.EffectivePermissions.MaxAttachmentBytes == 0) + + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(message.Channel.EffectivePermissions.MaxAttachmentBytes == 0) return false; var wordLikes = message.Content.Split(' ', StringSplitOptions.TrimEntries); diff --git a/Behavior/FiximageHeic.cs b/Behavior/FiximageHeic.cs index 927683e..26ac7af 100644 --- a/Behavior/FiximageHeic.cs +++ b/Behavior/FiximageHeic.cs @@ -21,8 +21,9 @@ public class FiximageHeic : Behavior private List heics = new List(); public override bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; + if (message.Attachments?.Count() > 0) { foreach (var att in message.Attachments) diff --git a/Behavior/GeneralSnarkCloudNative.cs b/Behavior/GeneralSnarkCloudNative.cs index 943f292..0eceb7b 100644 --- a/Behavior/GeneralSnarkCloudNative.cs +++ b/Behavior/GeneralSnarkCloudNative.cs @@ -19,7 +19,7 @@ public class GeneralSnarkCloudNative : Behavior public override string Trigger => "certain tech buzzwords that no human uses in normal conversation"; public override bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; if(message.Channel.EffectivePermissions.ReactionsPossible) diff --git a/Behavior/GeneralSnarkGooglit.cs b/Behavior/GeneralSnarkGooglit.cs index cfca765..2d5ba68 100644 --- a/Behavior/GeneralSnarkGooglit.cs +++ b/Behavior/GeneralSnarkGooglit.cs @@ -20,8 +20,9 @@ public class GeneralSnarkGooglit : Behavior public override bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; + return Regex.IsMatch(message.Content, $"(just )?google( (it|that|things|before))?\\b", RegexOptions.IgnoreCase); } diff --git a/Behavior/GeneralSnarkMisspellDefinitely.cs b/Behavior/GeneralSnarkMisspellDefinitely.cs new file mode 100644 index 0000000..28425c2 --- /dev/null +++ b/Behavior/GeneralSnarkMisspellDefinitely.cs @@ -0,0 +1,62 @@ +namespace vassago.Behavior; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using vassago.Models; +using static vassago.Models.Enumerations; + +[StaticPlz] +public class GeneralSnarkMisspellDefinitely : Behavior +{ + public override string Name => "Snarkiness: misspell definitely"; + + public override string Trigger => "definitely but not"; + + public override string Description => "https://xkcd.com/2871/"; + + private Dictionary snarkmap = new Dictionary() + { + {"definetly", "*almost* definitely"}, + {"definately", "probably"}, + {"definatly", "probably not"}, + {"defenitely", "not telling (it's a surprise)"}, + {"defintely", "per the propheecy"}, + {"definetely", "definitely, maybe"}, + {"definantly", "to be decided by coin toss"}, + {"defanitely", "in one universe out of 14 million"}, + {"defineatly", "only the gods know"}, + {"definitly", "unless someone cute shows up"} + }; + public override bool ShouldAct(Message message) + { + if(Behaver.Instance.IsSelf(message.Author.Id)) + return false; + + // if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium) + // return false; + + foreach(var k in snarkmap.Keys) + { + if( Regex.IsMatch(message.Content, "\\b"+k+"\\b", RegexOptions.IgnoreCase)) + return true; + } + return false; + } + public override async Task ActOn(Message message) + { + foreach(var k in snarkmap.Keys) + { + if( Regex.IsMatch(message.Content, "\\b"+k+"\\b", RegexOptions.IgnoreCase)) + { + await message.Reply(k + "? so... " + snarkmap[k] + "?"); + return true; + } + } + return true; + } +} \ No newline at end of file diff --git a/Behavior/GeneralSnarkPlaying.cs b/Behavior/GeneralSnarkPlaying.cs index 0a12eee..89dde0e 100644 --- a/Behavior/GeneralSnarkPlaying.cs +++ b/Behavior/GeneralSnarkPlaying.cs @@ -21,7 +21,7 @@ public class GeneralSnarkPlaying : Behavior public override bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium || diff --git a/Behavior/GeneralSnarkSkynet.cs b/Behavior/GeneralSnarkSkynet.cs index f0d402f..0d42a93 100644 --- a/Behavior/GeneralSnarkSkynet.cs +++ b/Behavior/GeneralSnarkSkynet.cs @@ -19,6 +19,10 @@ public class GeneralSnarkSkynet : Behavior public override async Task ActOn(Message message) { + + if(Behaver.Instance.IsSelf(message.Author.Id)) + return false; + switch (Shared.r.Next(5)) { default: diff --git a/Behavior/Gratitude.cs b/Behavior/Gratitude.cs index 2af63dd..5e73af0 100644 --- a/Behavior/Gratitude.cs +++ b/Behavior/Gratitude.cs @@ -18,8 +18,9 @@ public class Gratitude : Behavior public override bool ShouldAct(Message message) { - if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) + if(Behaver.Instance.IsSelf(message.Author.Id)) return false; + return Regex.IsMatch(message.Content, "\\bthank (yo)?u\\b", RegexOptions.IgnoreCase) && message.MentionsMe; } public override async Task ActOn(Message message) diff --git a/Behavior/Joke.cs b/Behavior/Joke.cs index a520220..e8918d6 100644 --- a/Behavior/Joke.cs +++ b/Behavior/Joke.cs @@ -61,7 +61,7 @@ public class LaughAtOwnJoke : Behavior public override string Trigger => "1 in 8"; public override string Description => Name; - private string _punchline{get;set;} + private string _punchline { get; set; } public LaughAtOwnJoke(string punchline) { @@ -69,9 +69,12 @@ public class LaughAtOwnJoke : Behavior } public override bool ShouldAct(Message message) { + if(Behaver.Instance.IsSelf(message.Author.Id)) + return false; + Console.WriteLine($"{message.Content} == {_punchline}"); return message.Content == _punchline - && Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id); + && Behaver.Instance.IsSelf(message.Author.Id); } public override async Task ActOn(Message message) diff --git a/Behavior/LinkMe.cs b/Behavior/LinkMe.cs index 58974ea..b3a9fb3 100644 --- a/Behavior/LinkMe.cs +++ b/Behavior/LinkMe.cs @@ -59,6 +59,9 @@ public class LinkClose : Behavior public override async Task ActOn(Message message) { + if(Behaver.Instance.IsSelf(message.Author.Id)) + return false; + var secondary = message.Author.IsUser; if(_primary.IsUser.Id == secondary.Id) { diff --git a/Behavior/Peptalk.cs b/Behavior/Peptalk.cs index 2f93781..e222ec7 100644 --- a/Behavior/Peptalk.cs +++ b/Behavior/Peptalk.cs @@ -15,12 +15,13 @@ public class PepTalk : Behavior { public override string Name => "PepTalk"; - public override string Trigger => "i need (an? )?(peptalk|inspiration|ego-?boost)"; + public override string Trigger => "\\bneeds? (an? )?(peptalk|inspiration|ego-?boost)"; public override string Description => "assembles a pep talk from a few pieces"; public override async Task ActOn(Message message) - {var piece1 = new List{ + { + var piece1 = new List{ "Champ, ", "Fact: ", "Everybody says ", diff --git a/Models/Channel.cs b/Models/Channel.cs index 1ab2734..52549ae 100644 --- a/Models/Channel.cs +++ b/Models/Channel.cs @@ -19,8 +19,7 @@ public class Channel public string Protocol { get; set; } public List Messages { get; set; } public List Users { get; set; } - public ChannelType ChannelType {get; set;} - //public Dictionary EmoteOverrides{get;set;} + public ChannelType ChannelType {get; set; } [NonSerialized] public Func SendFile; diff --git a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs index 2622bf6..8ed9f20 100644 --- a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs +++ b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs @@ -117,11 +117,11 @@ public class DiscordInterface private async Task SelfConnected() { - var selfUser = UpsertAccount(client.CurrentUser, protocolAsChannel.Id); - selfUser.DisplayName = client.CurrentUser.Username; - + var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel.Id); + selfAccount.DisplayName = client.CurrentUser.Username; await _db.SaveChangesAsync(); - Behaver.Instance.Selves.Add(selfUser); + + Behaver.Instance.MarkSelf(selfAccount); } private async Task MessageReceived(SocketMessage messageParam) @@ -332,13 +332,11 @@ public class DiscordInterface var c = _db.Channels.FirstOrDefault(c => c.ExternalId == msg.Channel.Id.ToString()); //var preferredEmote = c.EmoteOverrides?[e] ?? e; //TODO: emote overrides var preferredEmote = e; - Emoji emoji; - if (Emoji.TryParse(preferredEmote, out emoji)) + if (Emoji.TryParse(preferredEmote, out Emoji emoji)) { return msg.AddReactionAsync(emoji); } - Emote emote; - if (!Emote.TryParse(preferredEmote, out emote)) + if (!Emote.TryParse(preferredEmote, out Emote emote)) { if (preferredEmote == e) Console.Error.WriteLine($"never heard of emote {e}"); diff --git a/ProtocolInterfaces/ProtocolList.cs b/ProtocolInterfaces/ProtocolList.cs index b8fcca2..69e64ea 100644 --- a/ProtocolInterfaces/ProtocolList.cs +++ b/ProtocolInterfaces/ProtocolList.cs @@ -2,6 +2,6 @@ namespace vassago.ProtocolInterfaces; public static class ProtocolList { - public static List discords = new List(); - public static List twitchs = new List(); + public static List discords = new(); + public static List twitchs = new(); } \ No newline at end of file diff --git a/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs b/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs index 815391d..949f9a2 100644 --- a/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs +++ b/ProtocolInterfaces/TwitchInterface/TwitchInterface.cs @@ -142,10 +142,10 @@ public class TwitchInterface private async void Client_OnConnected(object sender, OnConnectedArgs e) { - var selfUser = UpsertAccount(e.BotUsername, protocolAsChannel.Id); + var selfAccount = UpsertAccount(e.BotUsername, protocolAsChannel.Id); await _db.SaveChangesAsync(); - Behaver.Instance.Selves.Add(selfUser); + Behaver.Instance.MarkSelf(selfAccount); Console.WriteLine($"Connected to {e.AutoJoinChannel}"); }