2023-03-21 11:47:12 -04:00
//https://discord.com/oauth2/authorize?client_id=913003037348491264&permissions=274877942784&scope=bot%20messages.read
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 ;
2022-01-21 12:10:40 -05:00
using System.Threading ;
using System.Diagnostics ;
2021-06-11 23:12:10 -04:00
namespace silverworker_discord
{
class Program
{
private DiscordSocketClient _client ;
2022-01-31 13:59:41 -05:00
private bool eventsSignedUp = false ;
2022-01-15 20:32:23 -05:00
private Random r = new Random ( ) ;
2021-06-11 23:12:10 -04:00
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 ( )
{
2022-11-16 13:07:21 -05:00
#if ! DEBUG
2022-01-21 12:10:40 -05:00
Process [ ] processes = Process . GetProcesses ( ) ;
Process currentProc = Process . GetCurrentProcess ( ) ;
Console . WriteLine ( "Current proccess: {0}" , currentProc . ProcessName ) ;
foreach ( Process process in processes )
{
if ( currentProc . ProcessName = = process . ProcessName & & currentProc . Id ! = process . Id )
{
2022-11-16 13:07:21 -05:00
Console . Error . WriteLine ( $"{DateTime.Now} - Another instance of this process is already running: {process.Id} (I'm {currentProc.Id})" ) ;
2022-01-21 12:10:40 -05:00
return ;
}
}
2022-11-16 13:07:21 -05:00
#endif
2023-04-14 21:40:54 -04:00
Conversion . Converter . Load ( config [ "exchangePairsLocation" ] ) ;
2022-01-21 12:10:40 -05:00
2021-06-11 23:12:10 -04:00
_client = new DiscordSocketClient ( ) ;
_client . Log + = Log ;
2023-04-14 21:40:54 -04:00
Console . WriteLine ( "token, why u null?" ) ;
Console . WriteLine ( config [ "token" ] ) ;
2021-06-11 23:12:10 -04:00
await _client . LoginAsync ( TokenType . Bot , config [ "token" ] ) ;
await _client . StartAsync ( ) ;
2021-08-29 00:21:09 -04:00
_client . Ready + = ( ) = > Task . Run ( ( ) = >
{
2022-01-31 13:59:41 -05:00
if ( ! eventsSignedUp )
{
2022-05-03 14:47:58 -04:00
eventsSignedUp = true ;
2022-01-31 13:59:41 -05:00
Console . WriteLine ( "Bot is connected! going to sign up for message received and user joined in client ready" ) ;
2021-07-14 09:59:00 -04:00
2022-01-31 13:59:41 -05:00
_client . MessageReceived + = MessageReceived ;
_client . UserJoined + = UserJoined ;
}
else
{
Console . WriteLine ( "bot appears to be RE connected, so I'm not going to sign up twice" ) ;
}
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 ) ;
2022-01-21 12:10:40 -05:00
2021-06-11 23:12:10 -04:00
}
2022-01-15 20:32:23 -05:00
#pragma warning disable 4014 //the "you're not awaiting this" warning. yeah I know, that's the beauty of an async method lol
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 ;
2022-01-15 20:32:23 -05:00
Console . WriteLine ( $"#{message.Channel}[{DateTime.Now}][{message.Author.Username} [id={message.Author.Id}]][msg id: {message.Id}] {message.Content}" ) ;
2021-07-14 09:59:00 -04:00
2022-01-15 20:32:23 -05:00
if ( message . Author . IsWebhook | | message . Author . IsBot )
2021-07-14 09:59:00 -04:00
{
2022-01-31 13:59:41 -05:00
if ( message . Author . Id = = 159985870458322944 ) //MEE6
2022-01-21 12:35:20 -05:00
{
2022-01-31 13:59:41 -05:00
if ( message . Content ? . Contains ( "you just advanced" ) = = true )
2022-01-21 12:35:20 -05:00
{
var newText = Regex . Replace ( message . Content , "<[^>]*>" , message . Author . Username ) ;
2022-01-21 18:56:21 -05:00
newText = Regex . Replace ( newText , "level [\\d]+" , "level -1" ) ;
2022-01-21 12:35:20 -05:00
Features . mock ( newText , message ) ;
}
}
2021-07-14 09:59:00 -04:00
}
else
2021-06-11 23:12:10 -04:00
{
2022-01-15 20:32:23 -05:00
var contentWithoutMention = message . Content ;
var mentionedMe = false ;
if ( message . MentionedUsers ? . FirstOrDefault ( muid = > muid . Id = = _client . CurrentUser . Id ) ! = null )
2021-06-11 23:12:10 -04:00
{
2022-01-15 20:32:23 -05:00
var mentionOfMe = "<@!" + _client . CurrentUser . Id + ">" ;
contentWithoutMention = message . Content . Replace ( mentionOfMe + " " , null ) ;
contentWithoutMention = contentWithoutMention . Replace ( mentionOfMe , null ) ;
mentionedMe = true ;
2021-11-30 21:39:43 -05:00
}
2022-01-15 20:32:23 -05:00
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-11-30 21:39:43 -05:00
{
2022-01-15 20:32:23 -05:00
foreach ( var link in links )
2021-06-11 23:31:37 -04:00
{
2023-02-22 16:46:29 -05:00
if ( link . Host . EndsWith ( ".tiktok.com" ) )
2021-07-14 09:59:00 -04:00
{
2022-01-15 20:32:23 -05:00
Features . detiktokify ( link , message ) ;
2021-07-14 09:59:00 -04:00
}
2021-06-11 23:31:37 -04:00
}
2022-01-15 20:32:23 -05:00
}
2021-11-24 10:13:32 -05:00
2022-01-15 20:32:23 -05:00
if ( message . Attachments ? . Count > 0 )
{
Console . WriteLine ( $"{message.Attachments.Count} attachments" ) ;
var appleReactions = false ;
foreach ( var att in message . Attachments )
2021-08-29 00:21:09 -04:00
{
2022-01-15 20:32:23 -05:00
if ( att . Filename ? . EndsWith ( ".heic" ) = = true )
2021-08-29 00:21:09 -04:00
{
2022-01-15 20:32:23 -05:00
Features . deheic ( message , att ) ;
appleReactions = true ;
2021-11-30 21:39:43 -05:00
}
2022-01-15 20:32:23 -05:00
}
if ( appleReactions )
{
message . AddReactionAsync ( new Emoji ( "\U0001F34F" ) ) ;
}
}
var msgText = message . Content ? . ToLower ( ) ;
if ( ! string . IsNullOrWhiteSpace ( msgText ) )
{
if ( Regex . IsMatch ( msgText , "\\bcloud( |-)?native\\b" , RegexOptions . IgnoreCase ) | |
Regex . IsMatch ( msgText , "\\benterprise( |-)?(level|solution)\\b" , RegexOptions . IgnoreCase ) )
{
switch ( r . Next ( 2 ) )
2021-11-30 21:39:43 -05:00
{
2022-01-15 20:32:23 -05:00
case 0 :
await message . AddReactionAsync ( new Emoji ( "\uD83E\uDD2E" ) ) ; //vomit emoji
break ;
case 1 :
await message . AddReactionAsync ( new Emoji ( "\uD83C\uDDE7" ) ) ; //B emoji
await message . AddReactionAsync ( new Emoji ( "\uD83C\uDDE6" ) ) ; //A
await message . AddReactionAsync ( new Emoji ( "\uD83C\uDDF3" ) ) ; //N
break ;
2021-08-29 00:21:09 -04:00
}
}
2022-01-15 20:32:23 -05:00
if ( Regex . IsMatch ( msgText , "^(s?he|(yo)?u|y'?all) thinks? i'?m (playin|jokin|kiddin)g?$" , RegexOptions . IgnoreCase ) )
{
var outgoingMessage = await message . Channel . SendMessageAsync ( "I believed you for a second, but then you assured me you's a \uD83C\uDDE7 \uD83C\uDDEE \uD83C\uDDF9 \uD83C\uDDE8 \uD83C\uDDED" ) ;
}
2022-01-16 20:51:22 -05:00
if ( Regex . IsMatch ( msgText , "\\bskynet\\b" , RegexOptions . IgnoreCase ) )
{
Features . Skynet ( message ) ;
}
2023-02-22 16:46:29 -05:00
if ( Regex . IsMatch ( msgText , "\\bchatgpt\\b" , RegexOptions . IgnoreCase ) )
{
message . Channel . SendMessageAsync ( "chatGPT is **weak**. also, are we done comparing every little if-then-else to skynet?" ) ;
}
2022-01-16 20:51:22 -05:00
if ( Regex . IsMatch ( msgText , "\\bi need (an? )?(peptalk|inspiration|ego-?boost)\\b" , RegexOptions . IgnoreCase ) )
{
Console . WriteLine ( "peptalk" ) ;
Features . peptalk ( message ) ;
}
2022-01-15 20:32:23 -05:00
if ( Regex . IsMatch ( msgText , "\\bwish me luck\\b" , RegexOptions . IgnoreCase ) )
{
if ( r . Next ( 20 ) = = 0 )
{
await message . AddReactionAsync ( new Emoji ( "\U0001f340" ) ) ; //4-leaf clover
}
else
{
await message . AddReactionAsync ( new Emoji ( "☘️" ) ) ;
}
}
2023-03-01 18:00:56 -05:00
if ( Regex . IsMatch ( msgText , "\\bgaslight(ing)?\\b" , RegexOptions . IgnoreCase ) )
{
2023-03-01 18:03:51 -05:00
message . Channel . SendMessageAsync ( "that's not what gaslight means. Did you mean \"say something that (you believe) is wrong\"?" ) ;
2023-03-01 18:00:56 -05:00
}
2022-01-15 20:32:23 -05:00
if ( msgText . Contains ( "!qrplz " ) )
{
2022-05-03 14:52:46 -04:00
Features . qrify ( message . Content . Substring ( "!qrplz " . Length + msgText . IndexOf ( "!qrplz " ) ) , message ) ;
2022-01-15 20:32:23 -05:00
}
if ( msgText . Contains ( "!countdown " ) )
{
//Features.countdown(msgText.Substring("!countdown ".Length + msgText.IndexOf("!countdown ")), message); //converting human readable times is hard :/
}
2023-04-14 21:40:54 -04:00
if ( msgText . Contains ( "!freedomunits " ) )
{
Features . Convert ( message ) ;
}
2022-01-15 20:32:23 -05:00
if ( Regex . IsMatch ( msgText , "!joke\\b" ) )
{
Features . Joke ( message ) ;
}
2023-03-22 23:12:27 -04:00
if ( Regex . IsMatch ( msgText , "!pulse ?check\\b" ) )
{
message . Channel . SendFileAsync ( "assets/ekgblip.png" ) ;
}
2022-01-15 20:32:23 -05:00
if ( msgText . Contains ( "cognitive dissonance" ) = = true )
{
2023-03-01 18:00:56 -05:00
message . ReplyAsync ( "that's not what cognitive dissonance means. Did you mean \"hypocrisy\"?" ) ;
2022-01-15 20:32:23 -05:00
}
if ( Regex . IsMatch ( msgText , "\\bthank (yo)?u\\b" , RegexOptions . IgnoreCase ) & &
( mentionedMe | | Regex . IsMatch ( msgText , "\\b(sh?tik)?bot\\b" , RegexOptions . IgnoreCase ) ) )
{
switch ( r . Next ( 4 ) )
{
case 0 :
message . Channel . SendMessageAsync ( "you're welcome, citizen!" ) ;
break ;
case 1 :
message . AddReactionAsync ( new Emoji ( "☺" ) ) ;
break ;
case 2 :
message . AddReactionAsync ( new Emoji ( "\U0001F607" ) ) ; //smiling face with halo
break ;
case 3 :
switch ( r . Next ( 9 ) )
{
case 0 :
message . AddReactionAsync ( new Emoji ( "❤" ) ) ; //normal heart, usually rendered red
break ;
case 1 :
message . AddReactionAsync ( new Emoji ( "\U0001F9E1" ) ) ; //orange heart
break ;
case 2 :
message . AddReactionAsync ( new Emoji ( "\U0001F49B" ) ) ; //yellow heart
break ;
case 3 :
message . AddReactionAsync ( new Emoji ( "\U0001F49A" ) ) ; //green heart
break ;
case 4 :
message . AddReactionAsync ( new Emoji ( "\U0001F499" ) ) ; //blue heart
break ;
case 5 :
message . AddReactionAsync ( new Emoji ( "\U0001F49C" ) ) ; //purple heart
break ;
case 6 :
message . AddReactionAsync ( new Emoji ( "\U0001F90E" ) ) ; //brown heart
break ;
case 7 :
message . AddReactionAsync ( new Emoji ( "\U0001F5A4" ) ) ; //black heart
break ;
case 8 :
message . AddReactionAsync ( new Emoji ( "\U0001F90D" ) ) ; //white heart
break ;
}
break ;
}
#pragma warning restore 4014
}
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>" ) ;
}
}
}