2023-06-15 23:29:07 -04:00
|
|
|
namespace vassago.Behavior;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using vassago.Models;
|
2023-06-20 21:26:44 -04:00
|
|
|
|
|
|
|
[StaticPlz]
|
2023-06-15 23:29:07 -04:00
|
|
|
public class Detiktokify : Behavior
|
|
|
|
{
|
|
|
|
public override string Name { get => "Detiktokify"; }
|
|
|
|
public override string Trigger { get => "post a link below vm.tiktok.com"; }
|
|
|
|
public override string Description { get => "re-host tiktok content"; }
|
|
|
|
|
|
|
|
private List<Uri> tiktokLinks = new List<Uri>();
|
|
|
|
private YoutubeDLSharp.YoutubeDL ytdl;
|
|
|
|
public Detiktokify()
|
|
|
|
{
|
|
|
|
ytdl = new YoutubeDLSharp.YoutubeDL();
|
|
|
|
ytdl.YoutubeDLPath = "yt-dlp";
|
|
|
|
ytdl.FFmpegPath = "ffmpeg";
|
|
|
|
ytdl.OutputFolder = "";
|
|
|
|
ytdl.OutputFileTemplate = "tiktokbad.%(ext)s";
|
|
|
|
}
|
2023-06-19 11:03:06 -04:00
|
|
|
public override bool ShouldAct(Message message)
|
2023-06-15 23:29:07 -04:00
|
|
|
{
|
2024-01-05 21:39:31 -05:00
|
|
|
|
|
|
|
if(Behaver.Instance.IsSelf(message.Author.Id))
|
2023-06-15 23:29:07 -04:00
|
|
|
return false;
|
|
|
|
|
2024-01-05 21:39:31 -05:00
|
|
|
if(message.Channel.EffectivePermissions.MaxAttachmentBytes == 0)
|
2023-06-28 00:14:32 -04:00
|
|
|
return false;
|
|
|
|
|
2023-06-15 23:29:07 -04:00
|
|
|
var wordLikes = message.Content.Split(' ', StringSplitOptions.TrimEntries);
|
|
|
|
var possibleLinks = wordLikes?.Where(wl => Uri.IsWellFormedUriString(wl, UriKind.Absolute)).Select(wl => new Uri(wl));
|
|
|
|
if (possibleLinks != null && possibleLinks.Count() > 0)
|
|
|
|
{
|
|
|
|
foreach (var link in possibleLinks)
|
|
|
|
{
|
|
|
|
if (link.Host.EndsWith(".tiktok.com"))
|
|
|
|
{
|
|
|
|
tiktokLinks.Add(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-22 14:58:44 -04:00
|
|
|
if(tiktokLinks.Any()){
|
|
|
|
Console.WriteLine($"Should Act on message id {message.ExternalId}; with content {message.Content}");
|
|
|
|
}
|
2023-06-15 23:29:07 -04:00
|
|
|
return tiktokLinks.Any();
|
|
|
|
}
|
2023-06-19 11:03:06 -04:00
|
|
|
public override async Task<bool> ActOn(Message message)
|
2023-06-15 23:29:07 -04:00
|
|
|
{
|
|
|
|
foreach(var link in tiktokLinks)
|
|
|
|
{
|
2023-08-22 14:58:44 -04:00
|
|
|
tiktokLinks.Remove(link);
|
2023-06-15 23:29:07 -04:00
|
|
|
try
|
|
|
|
{
|
2023-07-03 12:51:23 -04:00
|
|
|
Console.WriteLine($"detiktokifying {link}");
|
2023-06-19 12:56:40 -04:00
|
|
|
#pragma warning disable 4014
|
2023-06-28 00:14:32 -04:00
|
|
|
//await message.React("<:tiktok:1070038619584200884>");
|
2023-06-19 12:56:40 -04:00
|
|
|
#pragma warning restore 4014
|
|
|
|
|
2023-06-15 23:29:07 -04: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.React("problemon");
|
2024-01-26 17:55:09 -05:00
|
|
|
await message.Channel.SendMessage("tried to dl, failed. \n");
|
2023-06-15 23:29:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string path = res.Data;
|
|
|
|
if (File.Exists(path))
|
|
|
|
{
|
2023-06-28 00:14:32 -04:00
|
|
|
ulong bytesize = (ulong)((new System.IO.FileInfo(path)).Length);
|
2023-06-19 11:03:06 -04:00
|
|
|
if (bytesize < message.Channel.EffectivePermissions.MaxAttachmentBytes - 256)
|
2023-06-15 23:29:07 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await message.Channel.SendFile(path, null);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
System.Console.Error.WriteLine(e);
|
|
|
|
await message.Channel.SendMessage($"aaaadam!\n{e}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-20 21:38:25 -04:00
|
|
|
message.ActedOn = true;
|
2023-06-15 23:29:07 -04:00
|
|
|
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");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|