From 5b3a6454064855bfe673638661f2c57b8cc8975b Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Mon, 31 Jan 2022 13:59:41 -0500 Subject: [PATCH] hopefully resist double-connecting --- .vscode/launch.json | 2 +- Program.cs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2419b19..b42dcd0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "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", + "program": "${workspaceFolder}/bin/Debug/net6.0/silverworker-discord.dll", "args": [], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/Program.cs b/Program.cs index 4f1f70f..18f3bf6 100644 --- a/Program.cs +++ b/Program.cs @@ -18,6 +18,7 @@ namespace silverworker_discord class Program { private DiscordSocketClient _client; + private bool eventsSignedUp = false; private Random r = new Random(); IConfigurationRoot config = new ConfigurationBuilder() @@ -54,10 +55,17 @@ namespace silverworker_discord _client.Ready += () => Task.Run(() => { - Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready"); + if (!eventsSignedUp) + { + Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready"); - _client.MessageReceived += MessageReceived; - _client.UserJoined += UserJoined; + _client.MessageReceived += MessageReceived; + _client.UserJoined += UserJoined; + } + else + { + Console.WriteLine("bot appears to be RE connected, so I'm not going to sign up twice"); + } }); // Block this task until the program is closed. await Task.Delay(-1); @@ -77,9 +85,9 @@ namespace silverworker_discord if (message.Author.IsWebhook || message.Author.IsBot) { - if(message.Author.Id == 159985870458322944) //MEE6 + if (message.Author.Id == 159985870458322944) //MEE6 { - if(message.Content?.Contains("you just advanced") == true) + if (message.Content?.Contains("you just advanced") == true) { var newText = Regex.Replace(message.Content, "<[^>]*>", message.Author.Username); newText = Regex.Replace(newText, "level [\\d]+", "level -1");