forked from adam/discord-bot-shtik
IsSelf fix for Definitely snarkiness
notes to self. 1) trust in upsert. an account has an external ID, a channel has an external ID w.r.t. its protocol. 2) as long as you can collapse a User, collapse Self.
This commit is contained in:
parent
451ace753d
commit
efb4ab00d2
@ -11,7 +11,8 @@ using System.Collections.Generic;
|
|||||||
public class Behaver
|
public class Behaver
|
||||||
{
|
{
|
||||||
private ChattingContext _db;
|
private ChattingContext _db;
|
||||||
public List<Account> Selves { get; internal set; } = new List<Account>();
|
private List<Account> SelfAccounts { get; set; } = new List<Account>();
|
||||||
|
private User SelfUser { get; set; }
|
||||||
public static List<Behavior> Behaviors { get; private set; } = new List<Behavior>();
|
public static List<Behavior> Behaviors { get; private set; } = new List<Behavior>();
|
||||||
internal Behaver()
|
internal Behaver()
|
||||||
{
|
{
|
||||||
@ -48,7 +49,7 @@ public class Behaver
|
|||||||
Console.WriteLine("acted on, moving forward");
|
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");
|
Console.WriteLine("providing bullshit nonanswer / admitting uselessness");
|
||||||
var responses = new List<string>(){
|
var responses = new List<string>(){
|
||||||
@ -60,5 +61,25 @@ public class Behaver
|
|||||||
}
|
}
|
||||||
return message.ActedOn;
|
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
|
#pragma warning restore 4014 //the "async not awaited" error
|
@ -14,7 +14,7 @@ public abstract class Behavior
|
|||||||
|
|
||||||
public virtual bool ShouldAct(Message message)
|
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 false;
|
||||||
return Regex.IsMatch(message.Content, $"{Trigger}\\b", RegexOptions.IgnoreCase);
|
return Regex.IsMatch(message.Content, $"{Trigger}\\b", RegexOptions.IgnoreCase);
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,11 @@ public class Detiktokify : Behavior
|
|||||||
}
|
}
|
||||||
public override bool ShouldAct(Message message)
|
public override bool ShouldAct(Message message)
|
||||||
{
|
{
|
||||||
if(message.Channel.EffectivePermissions.MaxAttachmentBytes == 0)
|
|
||||||
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id))
|
if(message.Channel.EffectivePermissions.MaxAttachmentBytes == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var wordLikes = message.Content.Split(' ', StringSplitOptions.TrimEntries);
|
var wordLikes = message.Content.Split(' ', StringSplitOptions.TrimEntries);
|
||||||
|
@ -21,8 +21,9 @@ public class FiximageHeic : Behavior
|
|||||||
private List<Attachment> heics = new List<Attachment>();
|
private List<Attachment> heics = new List<Attachment>();
|
||||||
public override bool ShouldAct(Message message)
|
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 false;
|
||||||
|
|
||||||
if (message.Attachments?.Count() > 0)
|
if (message.Attachments?.Count() > 0)
|
||||||
{
|
{
|
||||||
foreach (var att in message.Attachments)
|
foreach (var att in message.Attachments)
|
||||||
|
@ -19,7 +19,7 @@ public class GeneralSnarkCloudNative : Behavior
|
|||||||
public override string Trigger => "certain tech buzzwords that no human uses in normal conversation";
|
public override string Trigger => "certain tech buzzwords that no human uses in normal conversation";
|
||||||
public override bool ShouldAct(Message message)
|
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 false;
|
||||||
|
|
||||||
if(message.Channel.EffectivePermissions.ReactionsPossible)
|
if(message.Channel.EffectivePermissions.ReactionsPossible)
|
||||||
|
@ -20,8 +20,9 @@ public class GeneralSnarkGooglit : Behavior
|
|||||||
|
|
||||||
public override bool ShouldAct(Message message)
|
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 false;
|
||||||
|
|
||||||
return Regex.IsMatch(message.Content, $"(just )?google( (it|that|things|before))?\\b", RegexOptions.IgnoreCase);
|
return Regex.IsMatch(message.Content, $"(just )?google( (it|that|things|before))?\\b", RegexOptions.IgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
Behavior/GeneralSnarkMisspellDefinitely.cs
Normal file
62
Behavior/GeneralSnarkMisspellDefinitely.cs
Normal file
@ -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<string, string> snarkmap = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{"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<bool> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ public class GeneralSnarkPlaying : Behavior
|
|||||||
|
|
||||||
public override bool ShouldAct(Message message)
|
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 false;
|
||||||
|
|
||||||
if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium ||
|
if((MeannessFilterLevel)message.Channel.EffectivePermissions.MeannessFilterLevel < MeannessFilterLevel.Medium ||
|
||||||
|
@ -19,6 +19,10 @@ public class GeneralSnarkSkynet : Behavior
|
|||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
||||||
|
return false;
|
||||||
|
|
||||||
switch (Shared.r.Next(5))
|
switch (Shared.r.Next(5))
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
|
@ -18,8 +18,9 @@ public class Gratitude : Behavior
|
|||||||
|
|
||||||
public override bool ShouldAct(Message message)
|
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 false;
|
||||||
|
|
||||||
return Regex.IsMatch(message.Content, "\\bthank (yo)?u\\b", RegexOptions.IgnoreCase) && message.MentionsMe;
|
return Regex.IsMatch(message.Content, "\\bthank (yo)?u\\b", RegexOptions.IgnoreCase) && message.MentionsMe;
|
||||||
}
|
}
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
|
@ -69,9 +69,12 @@ public class LaughAtOwnJoke : Behavior
|
|||||||
}
|
}
|
||||||
public override bool ShouldAct(Message message)
|
public override bool ShouldAct(Message message)
|
||||||
{
|
{
|
||||||
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
||||||
|
return false;
|
||||||
|
|
||||||
Console.WriteLine($"{message.Content} == {_punchline}");
|
Console.WriteLine($"{message.Content} == {_punchline}");
|
||||||
return 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<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
|
@ -59,6 +59,9 @@ public class LinkClose : Behavior
|
|||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
{
|
{
|
||||||
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
||||||
|
return false;
|
||||||
|
|
||||||
var secondary = message.Author.IsUser;
|
var secondary = message.Author.IsUser;
|
||||||
if(_primary.IsUser.Id == secondary.Id)
|
if(_primary.IsUser.Id == secondary.Id)
|
||||||
{
|
{
|
||||||
|
@ -15,12 +15,13 @@ public class PepTalk : Behavior
|
|||||||
{
|
{
|
||||||
public override string Name => "PepTalk";
|
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 string Description => "assembles a pep talk from a few pieces";
|
||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
{var piece1 = new List<string>{
|
{
|
||||||
|
var piece1 = new List<string>{
|
||||||
"Champ, ",
|
"Champ, ",
|
||||||
"Fact: ",
|
"Fact: ",
|
||||||
"Everybody says ",
|
"Everybody says ",
|
||||||
|
@ -20,7 +20,6 @@ public class Channel
|
|||||||
public List<Message> Messages { get; set; }
|
public List<Message> Messages { get; set; }
|
||||||
public List<Account> Users { get; set; }
|
public List<Account> Users { get; set; }
|
||||||
public ChannelType ChannelType {get; set; }
|
public ChannelType ChannelType {get; set; }
|
||||||
//public Dictionary<string, string> EmoteOverrides{get;set;}
|
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public Func<string, string, Task> SendFile;
|
public Func<string, string, Task> SendFile;
|
||||||
|
@ -117,11 +117,11 @@ public class DiscordInterface
|
|||||||
|
|
||||||
private async Task SelfConnected()
|
private async Task SelfConnected()
|
||||||
{
|
{
|
||||||
var selfUser = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
|
var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
|
||||||
selfUser.DisplayName = client.CurrentUser.Username;
|
selfAccount.DisplayName = client.CurrentUser.Username;
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
Behaver.Instance.Selves.Add(selfUser);
|
|
||||||
|
Behaver.Instance.MarkSelf(selfAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MessageReceived(SocketMessage messageParam)
|
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 c = _db.Channels.FirstOrDefault(c => c.ExternalId == msg.Channel.Id.ToString());
|
||||||
//var preferredEmote = c.EmoteOverrides?[e] ?? e; //TODO: emote overrides
|
//var preferredEmote = c.EmoteOverrides?[e] ?? e; //TODO: emote overrides
|
||||||
var preferredEmote = e;
|
var preferredEmote = e;
|
||||||
Emoji emoji;
|
if (Emoji.TryParse(preferredEmote, out Emoji emoji))
|
||||||
if (Emoji.TryParse(preferredEmote, out emoji))
|
|
||||||
{
|
{
|
||||||
return msg.AddReactionAsync(emoji);
|
return msg.AddReactionAsync(emoji);
|
||||||
}
|
}
|
||||||
Emote emote;
|
if (!Emote.TryParse(preferredEmote, out Emote emote))
|
||||||
if (!Emote.TryParse(preferredEmote, out emote))
|
|
||||||
{
|
{
|
||||||
if (preferredEmote == e)
|
if (preferredEmote == e)
|
||||||
Console.Error.WriteLine($"never heard of emote {e}");
|
Console.Error.WriteLine($"never heard of emote {e}");
|
||||||
|
@ -2,6 +2,6 @@ namespace vassago.ProtocolInterfaces;
|
|||||||
|
|
||||||
public static class ProtocolList
|
public static class ProtocolList
|
||||||
{
|
{
|
||||||
public static List<DiscordInterface.DiscordInterface> discords = new List<DiscordInterface.DiscordInterface>();
|
public static List<DiscordInterface.DiscordInterface> discords = new();
|
||||||
public static List<TwitchInterface.TwitchInterface> twitchs = new List<TwitchInterface.TwitchInterface>();
|
public static List<TwitchInterface.TwitchInterface> twitchs = new();
|
||||||
}
|
}
|
@ -142,10 +142,10 @@ public class TwitchInterface
|
|||||||
|
|
||||||
private async void Client_OnConnected(object sender, OnConnectedArgs e)
|
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();
|
await _db.SaveChangesAsync();
|
||||||
Behaver.Instance.Selves.Add(selfUser);
|
Behaver.Instance.MarkSelf(selfAccount);
|
||||||
|
|
||||||
Console.WriteLine($"Connected to {e.AutoJoinChannel}");
|
Console.WriteLine($"Connected to {e.AutoJoinChannel}");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user