2023-06-01 00:03:23 -04:00
namespace vassago.Behavior ;
#pragma warning disable 4014 //the "not awaited" error
using vassago.Models ;
using System ;
using System.Linq ;
using System.Text ;
using System.Text.RegularExpressions ;
using System.Threading.Tasks ;
using System.Collections.Generic ;
2023-06-15 23:29:07 -04:00
public class Behaver
2023-06-01 00:03:23 -04:00
{
2023-06-18 22:10:51 -04:00
private static List < Behavior > behaviors { get ; set ; } = new List < Behavior > ( ) ;
internal Behaver ( )
{
var subtypes = AppDomain . CurrentDomain . GetAssemblies ( )
. SelectMany ( domainAssembly = > domainAssembly . GetTypes ( ) )
. Where ( type = > type . IsSubclassOf ( typeof ( Behavior ) ) & & ! type . IsAbstract )
. ToList ( ) ;
foreach ( var subtype in subtypes )
{
behaviors . Add ( ( Behavior ) Activator . CreateInstance ( subtype ) ) ;
}
}
2023-06-15 23:29:07 -04:00
static Behaver ( ) { }
2023-06-01 00:03:23 -04:00
2023-06-15 23:29:07 -04:00
private static readonly Behaver _instance = new Behaver ( ) ;
2023-06-01 00:03:23 -04:00
2023-06-15 23:29:07 -04:00
public static Behaver Instance
2023-06-01 00:03:23 -04:00
{
get { return _instance ; }
}
public async Task < bool > ActOn ( Message message )
{
2023-06-18 22:10:51 -04:00
var permissions = new PermissionSettings ( ) ; //TODO: get combined permissions for author and channel
2023-06-01 00:03:23 -04:00
var contentWithoutMention = message . Content ;
2023-06-15 23:29:07 -04:00
2023-06-18 22:10:51 -04:00
foreach ( var behavior in behaviors )
{
if ( behavior . ShouldAct ( permissions , message ) )
{
behavior . ActOn ( permissions , message ) ;
message . ActedOn = true ;
}
}
if ( message . ActedOn = = false & & message . MentionsMe & & contentWithoutMention . Contains ( '?' ) )
{
Console . WriteLine ( "providing bullshit nonanswer / admitting uselessness" ) ;
var responses = new List < string > ( ) {
@"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 )
{
Shared . dbContext . SaveChanges ( ) ;
}
2023-06-15 23:29:07 -04:00
///behavior exists
// var wordLikes = message.Content.Split(' ', StringSplitOptions.TrimEntries);
// var links = wordLikes?.Where(wl => Uri.IsWellFormedUriString(wl, UriKind.Absolute)).Select(wl => new Uri(wl));
// if (links != null && links.Count() > 0)
2023-06-01 00:03:23 -04:00
// {
2023-06-15 23:29:07 -04:00
// foreach (var link in links)
2023-06-01 00:03:23 -04:00
// {
2023-06-15 23:29:07 -04:00
// if (link.Host.EndsWith(".tiktok.com"))
// {
// Features.detiktokify(link, message);
2023-06-18 22:10:51 -04:00
// // }
2023-06-15 23:29:07 -04:00
// }
// }
// if (message.Attachments?.Count() > 0)
// {
// Console.WriteLine($"{message.Attachments.Count()} attachments");
// var appleReactions = false;
// foreach (var att in message.Attachments)
// {
// if (att.Filename?.EndsWith(".heic") == true)
// {
// Features.deheic(message, att);
// appleReactions = true;
2023-06-18 22:10:51 -04:00
// // }
2023-06-15 23:29:07 -04:00
// }
// if (appleReactions)
// {
// message.React("\U0001F34F");
2023-06-01 00:03:23 -04:00
// }
// }
var msgText = message . Content ? . ToLower ( ) ;
if ( ! string . IsNullOrWhiteSpace ( msgText ) )
{
if ( Regex . IsMatch ( msgText , "\\bcloud( |-)?native\\b" , RegexOptions . IgnoreCase ) | |
Regex . IsMatch ( msgText , "\\benterprise( |-)?(level|solution)\\b" , RegexOptions . IgnoreCase ) )
{
switch ( Shared . r . Next ( 2 ) )
{
case 0 :
await message . React ( "\uD83E\uDD2E" ) ; //vomit emoji
break ;
case 1 :
await message . React ( "\uD83C\uDDE7" ) ; //B emoji
await message . React ( "\uD83C\uDDE6" ) ; //A
await message . React ( "\uD83C\uDDF3" ) ; //N
break ;
}
}
if ( Regex . IsMatch ( msgText , "^(s?he|(yo)?u|y'?all) thinks? i'?m (playin|jokin|kiddin)g?$" , RegexOptions . IgnoreCase ) )
{
await message . Channel . SendMessage ( "I believed you for a second, but then you assured me you's a \uD83C\uDDE7 \uD83C\uDDEE \uD83C\uDDF9 \uD83C\uDDE8 \uD83C\uDDED" ) ;
}
if ( Regex . IsMatch ( msgText , "\\bskynet\\b" , RegexOptions . IgnoreCase ) )
{
Features . Skynet ( message ) ;
}
if ( Regex . IsMatch ( msgText , "\\bchatgpt\\b" , RegexOptions . IgnoreCase ) )
{
message . Channel . SendMessage ( "chatGPT is **weak**. also, are we done comparing every little if-then-else to skynet?" ) ;
}
if ( Regex . IsMatch ( msgText , "\\bi need (an? )?(peptalk|inspiration|ego-?boost)\\b" , RegexOptions . IgnoreCase ) )
{
Console . WriteLine ( "peptalk" ) ;
Features . peptalk ( message ) ;
}
if ( Regex . IsMatch ( msgText , "\\bwish me luck\\b" , RegexOptions . IgnoreCase ) )
{
if ( Shared . r . Next ( 20 ) = = 0 )
{
await message . React ( "\U0001f340" ) ; //4-leaf clover
}
else
{
await message . React ( "☘️" ) ;
}
}
if ( Regex . IsMatch ( msgText , "\\bgaslight(ing)?\\b" , RegexOptions . IgnoreCase ) )
{
message . Channel . SendMessage ( "that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?" ) ;
}
2023-06-15 23:29:07 -04:00
// if (msgText.Contains("!qrplz "))
// {
// Features.qrify(message.Content.Substring("!qrplz ".Length + msgText.IndexOf("!qrplz ")), message);
2023-06-18 22:10:51 -04:00
// // }
2023-06-01 00:03:23 -04:00
if ( msgText . Contains ( "!freedomunits " ) )
{
Features . Convert ( message , contentWithoutMention ) ;
}
if ( Regex . IsMatch ( msgText , "!joke\\b" ) )
{
2023-06-05 14:55:48 -04:00
Console . WriteLine ( "joking" ) ;
2023-06-01 00:03:23 -04:00
Features . Joke ( message ) ;
}
if ( Regex . IsMatch ( msgText , "!pulse ?check\\b" ) )
{
2023-06-05 14:55:48 -04:00
message . Channel . SendFile ( "assets/ekgblip.png" , null ) ;
2023-06-01 00:03:23 -04:00
Console . WriteLine ( Conversion . Converter . DebugInfo ( ) ) ;
}
2023-06-05 14:55:48 -04:00
if ( message . MentionsMe & & ( Regex . IsMatch ( msgText , "\\brecipe for .+" ) | | Regex . IsMatch ( msgText , ".+ recipe\\b" ) ) )
2023-06-01 00:03:23 -04:00
{
Features . Recipe ( message ) ;
}
if ( msgText . Contains ( "cognitive dissonance" ) = = true )
{
message . Reply ( "that's not what cognitive dissonance means. Did you mean \"hypocrisy\"?" ) ;
}
2023-06-05 14:55:48 -04:00
if ( message . MentionsMe & & Regex . IsMatch ( msgText , "what'?s the longest (six|6)(-| )?letter word( in english)?\\b" ) )
2023-06-01 00:03:23 -04:00
{
Task . Run ( async ( ) = >
{
await message . Channel . SendMessage ( "mother." ) ;
await Task . Delay ( 3000 ) ;
await message . Channel . SendMessage ( "oh, longest? I thought you said fattest." ) ;
} ) ;
}
if ( Regex . IsMatch ( msgText , "\\bthank (yo)?u\\b" , RegexOptions . IgnoreCase ) & &
2023-06-05 14:55:48 -04:00
( message . MentionsMe | | Regex . IsMatch ( msgText , "\\b(sh?tik)?bot\\b" , RegexOptions . IgnoreCase ) ) )
2023-06-01 00:03:23 -04:00
{
switch ( Shared . r . Next ( 4 ) )
{
case 0 :
message . Channel . SendMessage ( "you're welcome, citizen!" ) ;
break ;
case 1 :
message . React ( "☺" ) ;
break ;
case 2 :
message . React ( "\U0001F607" ) ; //smiling face with halo
break ;
case 3 :
switch ( Shared . r . Next ( 9 ) )
{
case 0 :
message . React ( "❤" ) ; //normal heart, usually rendered red
break ;
case 1 :
message . React ( "\U0001F9E1" ) ; //orange heart
break ;
case 2 :
message . React ( "\U0001F49B" ) ; //yellow heart
break ;
case 3 :
message . React ( "\U0001F49A" ) ; //green heart
break ;
case 4 :
message . React ( "\U0001F499" ) ; //blue heart
break ;
case 5 :
message . React ( "\U0001F49C" ) ; //purple heart
break ;
case 6 :
message . React ( "\U0001F90E" ) ; //brown heart
break ;
case 7 :
message . React ( "\U0001F5A4" ) ; //black heart
break ;
case 8 :
message . React ( "\U0001F90D" ) ; //white heart
break ;
}
break ;
}
}
}
2023-06-18 22:10:51 -04:00
return message . ActedOn ;
2023-06-01 00:03:23 -04:00
}
internal Task OnJoin ( User u , Channel defaultChannel )
{
throw new NotImplementedException ( ) ;
}
}
#pragma warning restore 4014 //the "async not awaited" error