hopefully resist double-connecting

This commit is contained in:
Adam R Grey 2022-01-31 13:59:41 -05:00
parent 53c1d956b3
commit 5b3a645406
2 changed files with 14 additions and 6 deletions

2
.vscode/launch.json vendored
View File

@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path. // 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": [], "args": [],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

View File

@ -18,6 +18,7 @@ namespace silverworker_discord
class Program class Program
{ {
private DiscordSocketClient _client; private DiscordSocketClient _client;
private bool eventsSignedUp = false;
private Random r = new Random(); private Random r = new Random();
IConfigurationRoot config = new ConfigurationBuilder() IConfigurationRoot config = new ConfigurationBuilder()
@ -53,11 +54,18 @@ namespace silverworker_discord
await _client.StartAsync(); await _client.StartAsync();
_client.Ready += () => Task.Run(() => _client.Ready += () => Task.Run(() =>
{
if (!eventsSignedUp)
{ {
Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready"); Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready");
_client.MessageReceived += MessageReceived; _client.MessageReceived += MessageReceived;
_client.UserJoined += UserJoined; _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. // Block this task until the program is closed.
await Task.Delay(-1); await Task.Delay(-1);
@ -77,9 +85,9 @@ namespace silverworker_discord
if (message.Author.IsWebhook || message.Author.IsBot) 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); var newText = Regex.Replace(message.Content, "<[^>]*>", message.Author.Username);
newText = Regex.Replace(newText, "level [\\d]+", "level -1"); newText = Regex.Replace(newText, "level [\\d]+", "level -1");