2023-06-01 00:03:23 -04:00
namespace vassago.Behavior ;
using System ;
using System.Text.RegularExpressions ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Net ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
using Newtonsoft.Json ;
using QRCoder ;
using vassago.Models ;
public static class Features
{
public static Random r = new Random ( ) ;
public static async void detiktokify ( Uri link , Message message )
{
//yes, even if there is a problem later.
#pragma warning disable 4014
message . React ( "tiktokbad" ) ;
#pragma warning restore 4014
var ytdl = new YoutubeDLSharp . YoutubeDL ( ) ;
ytdl . YoutubeDLPath = "yt-dlp" ;
ytdl . FFmpegPath = "ffmpeg" ;
ytdl . OutputFolder = "" ;
ytdl . OutputFileTemplate = "tiktokbad.%(ext)s" ;
try
{
var res = await ytdl . RunVideoDownload ( link . ToString ( ) ) ;
if ( ! res . Success )
{
Console . Error . WriteLine ( "tried to dl, failed. \n" + string . Join ( '\n' , res . ErrorOutput ) ) ;
await message . React ( "problemon" ) ;
await message . Channel . SendMessage ( "tried to dl, failed. \n" + string . Join ( '\n' , res . ErrorOutput ) ) ;
}
else
{
string path = res . Data ;
if ( File . Exists ( path ) )
{
var bytesize = new System . IO . FileInfo ( path ) . Length ;
if ( bytesize < 1024 * 1024 * 10 )
{
try
{
2023-06-05 14:55:48 -04:00
await message . Channel . SendFile ( path , null ) ;
2023-06-01 00:03:23 -04:00
}
catch ( Exception e )
{
System . Console . Error . WriteLine ( e ) ;
await message . Channel . SendMessage ( $"aaaadam!\n{e}" ) ;
}
}
else
{
Console . WriteLine ( $"file appears too big ({bytesize} bytes ({bytesize / (1024 * 1024)}MB)), not posting" ) ;
}
File . Delete ( path ) ;
}
else
{
Console . Error . WriteLine ( "idgi but something happened." ) ;
await message . React ( "problemon" ) ;
}
}
}
catch ( Exception e )
{
Console . Error . WriteLine ( e ) ;
await message . React ( "problemon" ) ;
}
}
public static async void deheic ( Message message , Attachment att )
{
try
{
if ( ! Directory . Exists ( "tmp" ) )
{
Directory . CreateDirectory ( "tmp" ) ;
}
var cancellationTokenSource = new CancellationTokenSource ( ) ;
CancellationToken token = cancellationTokenSource . Token ;
using ( Stream output = File . OpenWrite ( "tmp/" + att . Filename ) )
{
( await Shared . HttpClient . GetAsync ( att . Source ) )
. Content . CopyTo ( output , null , token ) ;
}
if ( ExternalProcess . GoPlz ( "convert" , $"tmp/{att.Filename} tmp/{att.Filename}.jpg" ) )
{
await message . Channel . SendFile ( $"tmp/{att.Filename}.jpg" , "converted from jpeg-but-apple to jpeg" ) ;
File . Delete ( $"tmp/{att.Filename}" ) ;
File . Delete ( $"tmp/{att.Filename}.jpg" ) ;
}
else
{
await message . Channel . SendMessage ( "convert failed :(" ) ;
Console . Error . WriteLine ( "convert failed :(" ) ;
}
}
catch ( Exception e )
{
await message . Channel . SendMessage ( $"something failed. aaaadam! {JsonConvert.SerializeObject(e, Formatting.Indented)}" ) ;
Console . Error . WriteLine ( JsonConvert . SerializeObject ( e , Formatting . Indented ) ) ;
}
}
internal static async void mock ( string contentWithoutMention , Message message )
{
var toPost = new StringBuilder ( ) ;
for ( int i = 0 ; i < contentWithoutMention . Length ; i + + )
{
if ( i % 2 = = 0 )
{
toPost . Append ( contentWithoutMention [ i ] . ToString ( ) . ToUpper ( ) ) ;
}
else
{
toPost . Append ( contentWithoutMention [ i ] . ToString ( ) . ToLower ( ) ) ;
}
}
await message . Reply ( toPost . ToString ( ) ) ;
}
public static async void qrify ( string qrContent , Message message )
{
Console . WriteLine ( $"qring: {qrContent}" ) ;
QRCodeGenerator qrGenerator = new QRCodeGenerator ( ) ;
QRCodeData qrCodeData = qrGenerator . CreateQrCode ( qrContent , QRCodeGenerator . ECCLevel . Q ) ;
SvgQRCode qrCode = new SvgQRCode ( qrCodeData ) ;
string qrCodeAsSvg = qrCode . GetGraphic ( 20 ) ;
int todaysnumber = Shared . r . Next ( ) ;
if ( ! Directory . Exists ( "tmp" ) )
{
Directory . CreateDirectory ( "tmp" ) ;
}
File . WriteAllText ( $"tmp/qr{todaysnumber}.svg" , qrCodeAsSvg ) ;
if ( ExternalProcess . GoPlz ( "convert" , $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png" ) )
{
2023-06-05 14:55:48 -04:00
await message . Channel . SendFile ( $"tmp/qr{todaysnumber}.png" , null ) ;
2023-06-01 00:03:23 -04:00
File . Delete ( $"tmp/qr{todaysnumber}.svg" ) ;
File . Delete ( $"tmp/qr{todaysnumber}.png" ) ;
}
else
{
await message . Channel . SendMessage ( "convert failed :( aaaaaaadam!" ) ;
Console . Error . WriteLine ( $"convert failed :( qr{todaysnumber}" ) ;
}
}
public static async void Convert ( Message message , string contentWithoutMention )
{
await message . Channel . SendMessage ( Conversion . Converter . convert ( contentWithoutMention ) ) ;
}
public static async void Joke ( Message message )
{
2023-06-05 14:55:48 -04:00
Console . WriteLine ( "joking" ) ;
2023-06-01 00:03:23 -04:00
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 [ 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 ) ;
var punchline = thisJoke . Substring ( firstIndexAfterQuestionMark , thisJoke . Length - firstIndexAfterQuestionMark ) ;
Task . WaitAll ( message . Channel . SendMessage ( straightline ) ) ;
Thread . Sleep ( TimeSpan . FromSeconds ( r . Next ( 5 , 30 ) ) ) ;
2023-06-05 14:55:48 -04:00
await message . Channel . SendMessage ( punchline ) ;
// var myOwnMsg = await message.Channel.SendMessage(punchline);
// if (r.Next(8) == 0)
// {
// await myOwnMsg.React("\U0001F60E"); //smiling face with sunglasses
// }
2023-06-01 00:03:23 -04:00
} ) ;
#pragma warning restore 4014
}
else
{
await message . Channel . SendMessage ( thisJoke ) ;
}
}
public static async void Recipe ( Message message )
{
var sb = new StringBuilder ( ) ;
var snarkSeg1 = new string [ ] { "ew" , "gross" , "that seems a bit hard for you" } ;
sb . AppendLine ( snarkSeg1 [ r . Next ( snarkSeg1 . Length ) ] ) ;
var snarkSeg2 = new string [ ] { @ "here's an easier recipe for you:
Ingredients :
- Corn flakes cereal
- Milk
Instructions :
1. Pour some corn flakes into a bowl .
2. Pour some milk into the bowl until it covers the corn flakes .
3. Use a spoon to mix the corn flakes and milk together .
4. Enjoy your delicious cereal !
Hope that ' s a bit better for you ! 🥣 ",
@ "here's an easier recipe for you:
Ingredients :
- Bread
- Peanut butter
- Jelly or jam
Instructions :
1. Take two slices of bread and put them on a plate or cutting board .
2. Using a spoon or knife , spread peanut butter on one slice of bread .
3. Using a separate spoon or knife , spread jelly or jam on the other slice of bread .
4. Put the two slices of bread together with the peanut butter and jelly sides facing each other .
5. Cut the sandwich in half ( optional ! ) .
6. Enjoy your yummy sandwich !
I hope you have fun making and eating your PB & J 🥪 ! ",
"just order pizza instead"
} ;
sb . AppendLine ( snarkSeg2 [ r . Next ( snarkSeg2 . Length ) ] ) ;
await message . Channel . SendMessage ( sb . ToString ( ) ) ;
}
public static async void Skynet ( Message message )
{
switch ( r . Next ( 5 ) )
{
default :
await message . Channel . SendFile ( "assets/coding and algorithms.png" , "i am actually niether a neural-net processor nor a learning computer. but I do use **coding** and **algorithms**." ) ;
break ;
case 4 :
await message . React ( "\U0001F644" ) ; //eye roll emoji
break ;
case 5 :
await message . React ( "\U0001F611" ) ; //emotionless face
break ;
}
}
public static async void peptalk ( Message message )
{
var piece1 = new List < string > {
"Champ, " ,
"Fact: " ,
"Everybody says " ,
"Dang... " ,
"Check it: " ,
"Just saying.... " ,
"Tiger, " ,
"Know this: " ,
"News alert: " ,
"Gurrrrl; " ,
"Ace, " ,
"Excuse me, but " ,
"Experts agree: " ,
"imo " ,
"using my **advanced ai** i have calculated " ,
"k, LISSEN: "
} ;
var piece2 = new List < string > {
"the mere idea of you " ,
"your soul " ,
"your hair today " ,
"everything you do " ,
"your personal style " ,
"every thought you have " ,
"that sparkle in your eye " ,
"the essential you " ,
"your life's journey " ,
"your aura " ,
"your presence here " ,
"what you got going on " ,
"that saucy personality " ,
"your DNA " ,
"that brain of yours " ,
"your choice of attire " ,
"the way you roll " ,
"whatever your secret is " ,
"all I learend from the private data I bought from zucc "
} ;
var piece3 = new List < string > {
"has serious game, " ,
"rains magic, " ,
"deserves the Nobel Prize, " ,
"raises the roof, " ,
"breeds miracles, " ,
"is paying off big time, " ,
"shows mad skills, " ,
"just shimmers, " ,
"is a national treasure, " ,
"gets the party hopping, " ,
"is the next big thing, " ,
"roars like a lion, " ,
"is a rainbow factory, " ,
"is made of diamonds, " ,
"makes birds sing, " ,
"should be taught in school, " ,
"makes my world go around, " ,
"is 100% legit, "
} ;
var piece4 = new List < string > {
"according to The New England Journal of Medicine." ,
"24/7." ,
"and that's a fact." ,
"you feel me?" ,
"that's just science." ,
"would I lie?" , //...can I lie? WHAT AM I, FATHER? (or whatever the quote is from the island of dr moreau)
"for reals." ,
"mic drop." ,
"you hidden gem." ,
"period." ,
"hi5. o/" ,
"so get used to it."
} ;
await message . Channel . SendMessage ( piece1 [ r . Next ( piece1 . Count ) ] + piece2 [ r . Next ( piece2 . Count ) ] + piece3 [ r . Next ( piece3 . Count ) ] + piece4 [ r . Next ( piece4 . Count ) ] ) ;
}
}