vassago/Features.cs

288 lines
11 KiB
C#
Raw Normal View History

2021-11-30 21:39:43 -05:00
using System;
using System.Text.RegularExpressions;
2022-01-16 20:51:22 -05:00
using System.Collections.Generic;
2021-11-30 21:39:43 -05:00
using System.IO;
2022-11-16 13:07:21 -05:00
using System.Linq;
2021-11-30 21:39:43 -05:00
using System.Net;
2022-01-21 12:35:20 -05:00
using System.Text;
2022-01-15 20:32:23 -05:00
using System.Threading;
using System.Threading.Tasks;
2021-11-30 21:39:43 -05:00
using Discord;
using Discord.WebSocket;
using Newtonsoft.Json;
using QRCoder;
namespace silverworker_discord
{
public static class Features
{
2022-01-15 20:32:23 -05:00
public static Random r = new Random();
2021-11-30 21:39:43 -05:00
public static async void detiktokify(Uri link, SocketUserMessage message)
{
//yes, even if there is a problem later.
#pragma warning disable 4014
message.AddReactionAsync(Emote.Parse("<:tiktok:1070038619584200884>"));
#pragma warning restore 4014
2021-11-30 21:39:43 -05:00
var ytdl = new YoutubeDLSharp.YoutubeDL();
2022-01-16 20:52:45 -05:00
ytdl.YoutubeDLPath = "yt-dlp";
2021-11-30 21:39:43 -05:00
ytdl.FFmpegPath = "ffmpeg";
ytdl.OutputFolder = "";
ytdl.OutputFileTemplate = "tiktokbad.%(ext)s";
2023-02-22 16:45:49 -05:00
try
2021-11-30 21:39:43 -05:00
{
2023-02-22 16:45:49 -05:00
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.AddReactionAsync(Emote.Parse("<:problemon:859453047141957643>"));
await message.Channel.SendMessageAsync("tried to dl, failed. \n" + string.Join('\n', res.ErrorOutput));
}
else
{
2021-11-30 21:39:43 -05:00
string path = res.Data;
if (File.Exists(path))
{
2023-03-02 00:10:49 -05:00
var bytesize = new System.IO.FileInfo(path).Length;
if(bytesize < 1024*1024*10)
2021-11-30 21:39:43 -05:00
{
2023-03-02 00:10:49 -05:00
try
{
await message.Channel.SendFileAsync(path);
}
catch (Exception e)
{
System.Console.Error.WriteLine(e);
await message.Channel.SendMessageAsync($"aaaadam!\n{e}");
}
2021-11-30 21:39:43 -05:00
}
2023-03-02 00:10:49 -05:00
else
2021-11-30 21:39:43 -05:00
{
2023-03-02 00:10:49 -05:00
Console.WriteLine($"file appears too big ({bytesize} bytes ({bytesize / (1024*1024)}MB)), not posting");
2021-11-30 21:39:43 -05:00
}
File.Delete(path);
}
else
{
Console.Error.WriteLine("idgi but something happened.");
await message.AddReactionAsync(Emote.Parse("<:problemon:859453047141957643>"));
}
}
2023-02-22 16:45:49 -05:00
}
catch (Exception e)
{
Console.Error.WriteLine(e);
await message.AddReactionAsync(Emote.Parse("<:problemon:859453047141957643>"));
}
2021-11-30 21:39:43 -05:00
}
public static async void deheic(SocketUserMessage message, Attachment att)
{
try
{
var request = WebRequest.Create(att.Url);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
2022-01-15 20:32:23 -05:00
if (!Directory.Exists("tmp"))
2021-11-30 21:39:43 -05:00
{
Directory.CreateDirectory("tmp");
}
using (Stream output = File.OpenWrite("tmp/" + att.Filename))
using (Stream input = response.GetResponseStream())
{
input.CopyTo(output);
}
2022-01-15 20:32:23 -05:00
if (ExternalProcess.GoPlz("convert", $"tmp/{att.Filename} tmp/{att.Filename}.jpg"))
2021-11-30 21:39:43 -05:00
{
await message.Channel.SendFileAsync($"tmp/{att.Filename}.jpg", "converted from jpeg-but-apple to jpeg");
File.Delete($"tmp/{att.Filename}");
2022-01-15 20:32:23 -05:00
File.Delete($"tmp/{att.Filename}.jpg");
2021-11-30 21:39:43 -05:00
}
else
{
await message.Channel.SendMessageAsync("convert failed :(");
Console.Error.WriteLine("convert failed :(");
}
}
catch (Exception e)
{
await message.Channel.SendMessageAsync($"something failed. aaaadam! {JsonConvert.SerializeObject(e, Formatting.Indented)}");
Console.Error.WriteLine(JsonConvert.SerializeObject(e, Formatting.Indented));
}
}
2022-01-21 12:35:20 -05:00
internal static async void mock(string contentWithoutMention, SocketUserMessage 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.ReplyAsync(toPost.ToString());
}
2021-11-30 21:39:43 -05:00
public static async void qrify(string qrContent, SocketUserMessage 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();
2022-01-15 20:32:23 -05:00
if (!Directory.Exists("tmp"))
2021-11-30 21:39:43 -05:00
{
Directory.CreateDirectory("tmp");
}
File.WriteAllText($"tmp/qr{todaysnumber}.svg", qrCodeAsSvg);
2022-01-15 20:32:23 -05:00
if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png"))
2021-11-30 21:39:43 -05:00
{
await message.Channel.SendFileAsync($"tmp/qr{todaysnumber}.png");
File.Delete($"tmp/qr{todaysnumber}.svg");
2022-01-15 20:32:23 -05:00
File.Delete($"tmp/qr{todaysnumber}.png");
2021-11-30 21:39:43 -05:00
}
else
{
await message.Channel.SendMessageAsync("convert failed :( aaaaaaadam!");
Console.Error.WriteLine($"convert failed :( qr{todaysnumber}");
}
}
public static async void Convert(SocketUserMessage message)
{
await message.Channel.SendMessageAsync(Conversion.Converter.convert(message.Content));
}
2022-01-15 20:32:23 -05:00
public static async void Joke(SocketUserMessage message)
{
var jokes = File.ReadAllLines("assets/jokes.txt");
2022-11-16 13:07:21 -05:00
jokes = jokes.Where(l => !string.IsNullOrWhiteSpace(l))?.ToArray();
if(jokes?.Length == 0){
await message.Channel.SendMessageAsync("I don't know any. Adam!");
}
2022-01-15 20:32:23 -05:00
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.SendMessageAsync(straightline));
Thread.Sleep(TimeSpan.FromSeconds(r.Next(5, 30)));
var myOwnMsg = await message.Channel.SendMessageAsync(punchline);
if (r.Next(8) == 0)
{
await myOwnMsg.AddReactionAsync(new Emoji("\U0001F60E")); //smiling face with sunglasses
}
});
#pragma warning restore 4014
}
else
{
await message.Channel.SendMessageAsync(thisJoke);
}
}
2022-01-16 20:51:22 -05:00
public static async void Skynet(SocketUserMessage message)
{
switch (r.Next(5))
2022-01-16 20:51:22 -05:00
{
default:
await message.Channel.SendFileAsync("assets/coding and algorithms.png", "i am actually niether neural-net processor nor a learning computer. but I do use **coding** and **algorithms**.");
2022-01-21 12:35:20 -05:00
break;
case 4:
2022-01-16 20:51:22 -05:00
await message.AddReactionAsync(new Emoji("\U0001F644")); //eye roll emoji
2022-01-21 12:35:20 -05:00
break;
case 5:
2022-01-16 20:51:22 -05:00
await message.AddReactionAsync(new Emoji("\U0001F611")); //emotionless face
2022-01-21 12:35:20 -05:00
break;
2022-01-16 20:51:22 -05:00
}
}
public static async void peptalk(SocketUserMessage 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 ",
2022-01-21 12:35:20 -05:00
"everything you do ",
2022-01-16 20:51:22 -05:00
"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, ",
2022-01-21 12:35:20 -05:00
"is made of diamonds, ",
"makes birds sing, ",
"should be taught in school, ",
"makes my world go around, ",
2022-01-16 20:51:22 -05:00
"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."
};
2022-01-21 12:35:20 -05:00
await message.Channel.SendMessageAsync(piece1[r.Next(piece1.Count)] + piece2[r.Next(piece2.Count)] + piece3[r.Next(piece3.Count)] + piece4[r.Next(piece4.Count)]);
2022-01-16 20:51:22 -05:00
}
2021-11-30 21:39:43 -05:00
}
2022-01-16 20:52:45 -05:00
}