2021-11-24 10:13:32 -05:00
|
|
|
|
//https://discord.com/oauth2/authorize?client_id=913003037348491264&permissions=274877942784
|
2021-08-29 05:17:35 -04:00
|
|
|
|
using System;
|
2021-06-11 23:12:10 -04:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2021-07-16 03:49:37 -04:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Text;
|
2021-06-11 23:12:10 -04:00
|
|
|
|
|
|
|
|
|
namespace silverworker_discord
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
private DiscordSocketClient _client;
|
|
|
|
|
|
|
|
|
|
IConfigurationRoot config = new ConfigurationBuilder()
|
|
|
|
|
.AddJsonFile("appsettings.json", true, true)
|
|
|
|
|
.Build();
|
2021-08-29 00:21:09 -04:00
|
|
|
|
|
2021-06-11 23:12:10 -04:00
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
=> new Program().MainAsync().GetAwaiter().GetResult();
|
|
|
|
|
private Task Log(LogMessage msg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(msg.ToString());
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
public async Task MainAsync()
|
|
|
|
|
{
|
|
|
|
|
_client = new DiscordSocketClient();
|
|
|
|
|
|
|
|
|
|
_client.Log += Log;
|
|
|
|
|
|
|
|
|
|
await _client.LoginAsync(TokenType.Bot, config["token"]);
|
|
|
|
|
await _client.StartAsync();
|
|
|
|
|
|
2021-08-29 00:21:09 -04:00
|
|
|
|
_client.Ready += () => Task.Run(() =>
|
|
|
|
|
{
|
2021-07-14 09:59:00 -04:00
|
|
|
|
Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready");
|
|
|
|
|
|
|
|
|
|
_client.MessageReceived += MessageReceived;
|
|
|
|
|
_client.UserJoined += UserJoined;
|
2021-08-29 00:21:09 -04:00
|
|
|
|
});
|
2021-06-11 23:12:10 -04:00
|
|
|
|
// Block this task until the program is closed.
|
|
|
|
|
await Task.Delay(-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 21:39:43 -05:00
|
|
|
|
#pragma warning disable 1998 //the "it's async but you're not awaiting anything".
|
2021-06-11 23:12:10 -04:00
|
|
|
|
private async Task MessageReceived(SocketMessage messageParam)
|
2021-11-30 21:39:43 -05:00
|
|
|
|
#pragma warning restore 1998
|
2021-06-11 23:12:10 -04:00
|
|
|
|
{
|
|
|
|
|
var message = messageParam as SocketUserMessage;
|
|
|
|
|
if (message == null) return;
|
|
|
|
|
if (message.Author.Id == _client.CurrentUser.Id) return;
|
|
|
|
|
|
2021-07-14 09:59:00 -04:00
|
|
|
|
Console.WriteLine($"{message.Channel}, {message.Content} (message id: {message.Id})");
|
|
|
|
|
|
2021-08-29 00:21:09 -04:00
|
|
|
|
if (message.Author.IsWebhook)
|
2021-07-14 09:59:00 -04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-06-11 23:12:10 -04:00
|
|
|
|
{
|
2021-11-24 10:13:32 -05:00
|
|
|
|
//any channel, from a user
|
2021-11-30 21:39:43 -05:00
|
|
|
|
if (message.Content.StartsWith("!qrplz "))
|
2021-06-11 23:12:10 -04:00
|
|
|
|
{
|
2021-11-30 21:39:43 -05:00
|
|
|
|
Features.qrify(message.Content.Substring("!qrplz ".Length), message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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)
|
2021-06-11 23:31:37 -04:00
|
|
|
|
{
|
2021-11-30 21:39:43 -05:00
|
|
|
|
foreach (var link in links)
|
2021-07-14 09:59:00 -04:00
|
|
|
|
{
|
2021-11-30 21:39:43 -05:00
|
|
|
|
if (link.Host == "vm.tiktok.com")
|
|
|
|
|
{
|
|
|
|
|
Features.detiktokify(link, message);
|
|
|
|
|
}
|
2021-07-14 09:59:00 -04:00
|
|
|
|
}
|
2021-06-11 23:31:37 -04:00
|
|
|
|
}
|
2021-11-24 10:13:32 -05:00
|
|
|
|
|
2021-11-30 21:39:43 -05:00
|
|
|
|
if (message.Attachments?.Count > 0)
|
2021-08-29 00:21:09 -04:00
|
|
|
|
{
|
2021-11-30 21:39:43 -05:00
|
|
|
|
Console.WriteLine($"{message.Attachments.Count} attachments");
|
|
|
|
|
var appleReactions = false;
|
|
|
|
|
foreach (var att in message.Attachments)
|
2021-08-29 00:21:09 -04:00
|
|
|
|
{
|
2021-11-30 21:39:43 -05:00
|
|
|
|
if (att.Filename?.EndsWith(".heic") == true)
|
|
|
|
|
{
|
|
|
|
|
Features.deheic(message, att);
|
|
|
|
|
appleReactions = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (appleReactions)
|
|
|
|
|
{
|
|
|
|
|
#pragma warning disable 4014 //the "you're not awaiting this" warning. yeah I know, that's the beauty of an async method lol
|
|
|
|
|
message.AddReactionAsync(new Emoji("\U0001F34F"));
|
|
|
|
|
#pragma warning restore 4014
|
2021-08-29 00:21:09 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-29 05:47:55 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-29 00:21:09 -04:00
|
|
|
|
}
|
2021-06-11 23:12:10 -04:00
|
|
|
|
private Task UserJoined(SocketGuildUser arg)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"user joined: {arg.Nickname}. Guid: {arg.Guild.Id}. Channel: {arg.Guild.DefaultChannel}");
|
|
|
|
|
var abbreviatedNickname = arg.Nickname;
|
2021-08-29 00:21:09 -04:00
|
|
|
|
if (arg.Nickname.Length > 3)
|
|
|
|
|
{
|
2021-06-11 23:12:10 -04:00
|
|
|
|
abbreviatedNickname = arg.Nickname.Substring(0, arg.Nickname.Length / 3);
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine($"imma call him {abbreviatedNickname}");
|
|
|
|
|
return arg.Guild.DefaultChannel.SendMessageAsync($"oh hey {abbreviatedNickname}- IPLAYTHESEALOFORICHALCOS <:ORICHALCOS:852749196633309194>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|