2023-06-19 01:14:04 -04:00
|
|
|
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;
|
|
|
|
|
2023-06-20 21:26:44 -04:00
|
|
|
[StaticPlz]
|
2023-06-19 01:14:04 -04:00
|
|
|
public class Joke : Behavior
|
|
|
|
{
|
|
|
|
public override string Name => "Joke";
|
|
|
|
|
|
|
|
public override string Trigger => "!joke";
|
|
|
|
|
|
|
|
public override string Description => "tell a joke";
|
|
|
|
|
2023-06-19 11:03:06 -04:00
|
|
|
public override async Task<bool> ActOn(Message message)
|
2023-06-19 01:14:04 -04:00
|
|
|
{
|
|
|
|
Console.WriteLine("joking");
|
|
|
|
var jokes = File.ReadAllLines("assets/jokes.txt");
|
|
|
|
jokes = jokes.Where(l => !string.IsNullOrWhiteSpace(l))?.ToArray();
|
|
|
|
if (jokes?.Length == 0)
|
|
|
|
{
|
|
|
|
await message.Channel.SendMessage("I don't know any. Adam!");
|
|
|
|
}
|
|
|
|
var thisJoke = jokes[Shared.r.Next(jokes.Length)];
|
|
|
|
if (thisJoke.Contains("?") && !thisJoke.EndsWith('?'))
|
|
|
|
{
|
|
|
|
#pragma warning disable 4014
|
|
|
|
Task.Run(async () =>
|
|
|
|
{
|
|
|
|
var firstIndexAfterQuestionMark = thisJoke.LastIndexOf('?') + 1;
|
|
|
|
var straightline = thisJoke.Substring(0, firstIndexAfterQuestionMark);
|
2023-06-20 21:26:44 -04:00
|
|
|
var punchline = thisJoke.Substring(firstIndexAfterQuestionMark, thisJoke.Length - firstIndexAfterQuestionMark).Trim();
|
2023-06-19 01:14:04 -04:00
|
|
|
Task.WaitAll(message.Channel.SendMessage(straightline));
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(Shared.r.Next(5, 30)));
|
2023-07-04 12:58:21 -04:00
|
|
|
if (message.Channel.EffectivePermissions.ReactionsPossible == true && Shared.r.Next(8) == 0)
|
2023-06-19 01:14:04 -04:00
|
|
|
{
|
2023-06-20 21:26:44 -04:00
|
|
|
Behaver.Behaviors.Add(new LaughAtOwnJoke(punchline));
|
2023-06-19 01:14:04 -04:00
|
|
|
}
|
2023-06-19 12:56:40 -04:00
|
|
|
await message.Channel.SendMessage(punchline);
|
|
|
|
// var myOwnMsg = await message.Channel.SendMessage(punchline);
|
2023-06-19 01:14:04 -04:00
|
|
|
});
|
|
|
|
#pragma warning restore 4014
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await message.Channel.SendMessage(thisJoke);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-01 14:02:47 -05:00
|
|
|
}
|
|
|
|
public class LaughAtOwnJoke : Behavior
|
|
|
|
{
|
|
|
|
public override string Name => "Laugh at own jokes";
|
|
|
|
|
|
|
|
public override string Trigger => "1 in 8";
|
|
|
|
|
|
|
|
public override string Description => Name;
|
2024-01-05 21:39:31 -05:00
|
|
|
private string _punchline { get; set; }
|
2023-12-01 14:02:47 -05:00
|
|
|
|
|
|
|
public LaughAtOwnJoke(string punchline)
|
|
|
|
{
|
|
|
|
_punchline = punchline;
|
|
|
|
}
|
|
|
|
public override bool ShouldAct(Message message)
|
|
|
|
{
|
2024-01-05 21:39:31 -05:00
|
|
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
|
|
|
return false;
|
|
|
|
|
2023-12-01 14:02:47 -05:00
|
|
|
Console.WriteLine($"{message.Content} == {_punchline}");
|
|
|
|
return message.Content == _punchline
|
2024-01-05 21:39:31 -05:00
|
|
|
&& Behaver.Instance.IsSelf(message.Author.Id);
|
2023-12-01 14:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<bool> ActOn(Message message)
|
|
|
|
{
|
|
|
|
await message.React("\U0001F60E"); //smiling face with sunglasses
|
|
|
|
Behaver.Behaviors.Remove(this);
|
|
|
|
return true;
|
|
|
|
}
|
2023-06-19 01:14:04 -04:00
|
|
|
}
|