diff --git a/.gitignore b/.gitignore index 27ae6f1..c8208ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +appsettings.json + # ---> VisualStudio ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2419b19 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net5.0/silverworker-discord.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..8ded0b1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/silverworker-discord.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/silverworker-discord.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/silverworker-discord.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..60b16f7 --- /dev/null +++ b/Program.cs @@ -0,0 +1,94 @@ +using System; +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; + +namespace silverworker_discord +{ + class Program + { + private DiscordSocketClient _client; + private Random r = new Random(); + + IConfigurationRoot config = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", true, true) + .Build(); + + int initNonce; + private ISocketMessageChannel targetChannel = null; + + 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() + { + initNonce = r.Next(); + _client = new DiscordSocketClient(); + + _client.Log += Log; + + await _client.LoginAsync(TokenType.Bot, config["token"]); + await _client.StartAsync(); + + _client.MessageReceived += MessageReceived; + _client.UserJoined += UserJoined; + + _client.Ready += () => + { + Console.WriteLine("Bot is connected! this is the dumbest."); + var wh = new Discord.Webhook.DiscordWebhookClient(config["initWebhook"]); + return wh.SendMessageAsync(initNonce.ToString(), username: "silver loop"); + }; + // Block this task until the program is closed. + await Task.Delay(-1); + } + + private async Task MessageReceived(SocketMessage messageParam) + { + var message = messageParam as SocketUserMessage; + if (message == null) return; + if (message.Author.Id == _client.CurrentUser.Id) return; + + Console.WriteLine($"{message.Channel}, {message.Content}, {message.Id}"); + if(targetChannel == null && + message.Author.Username == "silver loop" && message.Content == initNonce.ToString()) + { + targetChannel = message.Channel; + Task.WaitAll(message.DeleteAsync(), targetChannel.SendMessageAsync("this initialization is nonsense lol")); + } + else if (message.Channel.Id != targetChannel.Id) + { + return; + } + + if(message.Attachments?.Count > 0) + { + Console.WriteLine(message.Attachments.Count); + foreach (var att in message.Attachments) + { + Console.WriteLine(att.Url); + await WebRequest.Create("http://192.168.1.151:3001/shortcuts?display_url=" + att.Url).GetResponseAsync(); + } + } + } + private Task UserJoined(SocketGuildUser arg) + { + Console.WriteLine($"user joined: {arg.Nickname}. Guid: {arg.Guild.Id}. Channel: {arg.Guild.DefaultChannel}"); + var abbreviatedNickname = arg.Nickname; + if(arg.Nickname.Length > 3){ + 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>"); + } + } +} \ No newline at end of file diff --git a/appsettings.example.json b/appsettings.example.json new file mode 100644 index 0000000..ca93aa4 --- /dev/null +++ b/appsettings.example.json @@ -0,0 +1,4 @@ +{ + "token": "59 chars", + "initWebhook": "https://discord.com/api/webhooks/ and then a bunch of other stuff, just make one and coyp it" +} \ No newline at end of file diff --git a/silverworker-discord.csproj b/silverworker-discord.csproj new file mode 100644 index 0000000..a3a3894 --- /dev/null +++ b/silverworker-discord.csproj @@ -0,0 +1,21 @@ + + + + Exe + net5.0 + silverworker_discord + + + + + + + + + + + + Always + + +