-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactEventHandler.cs
More file actions
64 lines (60 loc) · 2.93 KB
/
Copy pathReactEventHandler.cs
File metadata and controls
64 lines (60 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Amazon.EC2;
using Discord;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StartBot
{
public class ReactEventHandler
{
private bool debounce = false;
public async Task Handle(SocketMessageComponent? smc, bool web = false)
{
if(!debounce && !ServerStateManager.Instance().IsWorking) // ignore attempts to spam the button
{
debounce = true;
var status = await ServerStateManager.Instance().GetState();
if(status.InstanceState.Code == 80)
{
if (!web)
{
await Program.ModLog("Server Started From Discord", "Initated by " + smc.User.Id + " / " + smc.User.Mention);
Console.WriteLine("User ID" + smc.User.Id + " initated a server start.");
}
else
{
await Program.ModLog("Server Started From Web Portal", "");
}
ThreadPool.QueueUserWorkItem(async delegate
{
try
{
await ServerStateManager.Instance().StartServer();
}
catch (AmazonEC2Exception e)
{
Console.WriteLine("AWS threw an error.");
Console.Write(e.Message);
ServerStateManager.Instance().IsWorking = false;
await Embeds.EditMessage(Embeds.ServerStopped("The server could not be started previously due to an error. Please wait a bit and try again, or ask an admin if this persists. This mainly happens after starting a server when it's just been stopped."));
}
});
}
else
{
Console.WriteLine("Rejecting refresh as server is not stopped.");
if (smc != null && Program._client.GetUser(smc.User.Id) != null)
{
var usr = await smc.Channel.GetUserAsync(smc.User.Id);
await usr.SendMessageAsync(embed: Embeds.Error("The server must be stopped for the refresh button to work."));
}
}
debounce = false;
}
}
}
}