This repository was archived by the owner on Apr 24, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathMaster.cs
More file actions
157 lines (129 loc) · 5.93 KB
/
Copy pathMaster.cs
File metadata and controls
157 lines (129 loc) · 5.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using Discord;
using Discord.WebSocket;
using MothBot.modules;
namespace MothBot
{
internal class Master
{
public const string PATH_TOKEN = "../data/token.txt";
//See data module for parameters
public static DiscordSocketClient client = new DiscordSocketClient();
public static Random rand = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
public static void Main(string[] args) //Initialization
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(ProcessExit);
Console.CancelKeyPress += new ConsoleCancelEventHandler(ProcessExit);
Logging.Log($"System rebooted at [{DateTime.UtcNow}] {args}");
//Keep at bottom of init
try
{
new Master().MainAsync().GetAwaiter().GetResult(); //Start Runtime
}
catch (Exception e)
{
Logging.LogtoConsoleandFile($"**********\nPROGRAM CRASH: \n{e.Message}\n**********");
}
}
private static async Task Client_MessageRecieved(SocketMessage msg)
{
// Filter messages
if (msg.Author.IsBot) //If message author is a bot, ignore
return;
string input = msg.Content.ToLower();
if (input.StartsWith($"{Data.PREFIX} ")) //Filter out messages starting with prefix but not as a whole word (eg. if prefix is 'bot' we want to look at 'bot command' but not 'bots command'
try
{
await RootCommandHandler(msg);
}
catch (Exception ex)
{
string errmsg = $"**Command Failed!** Error: \"{ex.Message}\"";
await msg.Channel.SendMessageAsync(errmsg);
await Logging.LogtoConsoleandFileAsync(errmsg);
}
}
private static void ProcessExit(object sender, EventArgs e)
{
client.LogoutAsync(); //So mothbot doesn't hang out as a ghost for a few minutes
}
private static async Task RootCommandHandler(SocketMessage msg)
{
string guildid = "";
if (msg.Channel is ITextChannel)
guildid = $", {(msg.Channel as ITextChannel).Guild.Name} [{(msg.Channel as ITextChannel).GuildId}]";
await Logging.LogtoConsoleandFileAsync($@"[{msg.Timestamp.UtcDateTime}][{msg.Author}][{msg.Author.Id}] said ({msg.Content}) in #{msg.Channel}{guildid}");
Data.CommandSplitter(msg.Content.Substring($"{Data.PREFIX} ".Length), out string keyword, out string args);
//It is extremely important that any free field directives like 'say' sanitize out role pings such as @everyone using ScrubAnyRolePings
switch (keyword)
{
case "hello":
case "hi":
case "hey":
await msg.Channel.SendMessageAsync($@"Hi, {msg.Author.Mention}!");
break;
case "rogue":
case "malf":
if (Data.PREFIX == "ai")
await msg.Channel.SendFileAsync(Data.PATH_GAYBEE);
break;
case "help":
case "commands":
await msg.Channel.SendMessageAsync(Data.Program_GetCommandList());
break;
case "laws":
case "state":
await msg.Channel.SendMessageAsync(Data.Program_GetLaws());
break;
case "say":
if (!Chatterbot.ContentsBlacklisted(msg.Content))
await msg.Channel.SendMessageAsync(Sanitize.ScrubMentions(msg.Content, false).Substring(Data.PREFIX.Length + "say ".Length));
await msg.DeleteAsync();
break;
case "minesweeper":
await Minesweeper.MinesweeperHandlerAsync(msg.Channel);
break;
case "give":
await Imagesearch.ImageSearchHandlerAsync(msg.Channel, args);
break;
case "roll":
await Dice.Roll(msg.Channel, args);
break;
case "chatter":
await Chatterbot.CommandHandler(msg, args);
break;
case "ping":
await msg.Channel.SendMessageAsync($"Ping: {client.Latency}ms");
break;
case "portal":
case "portals":
await Portals.PortalManagement(msg, args);
break;
case "whitelist":
await Whitelist.CommandHandler(msg, args);
break;
//Below are not listed in the commands block.
case "dealias":
await msg.Channel.SendMessageAsync(Sanitize.Dealias(args));
break;
case "utility":
await Utilities.UtilitiesHandlerAsync(msg, args);
break;
default:
break;
}
}
private async Task MainAsync()
{
client.MessageReceived += Client_MessageRecieved;
client.Log += Logging.Log;
client.Ready += Users.Client_Ready;
client.MessageReceived += Portals.MessageRecieved;
client.UserJoined += Whitelist.UserJoined;
client.MessageReceived += Chatterbot.ChatterHandler;
await client.LoginAsync(TokenType.Bot, File.ReadAllText(PATH_TOKEN));
await Data.Program_SetStatus();
await client.StartAsync();
await Task.Delay(-1); //Sit here while the async listens
}
}
}