BlueGit

blue-star danique-bot

Files

danique-bot / commands.js

commands.js

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
commands.js 10.1 KiB Download Raw
1var http = require('http');
2var fs = require('fs');
3
4if (!Object.entries) {
5 Object.entries = function( obj ){
6 var ownProps = Object.keys( obj ),
7 i = ownProps.length,
8 resArray = new Array(i); // preallocate the Array!
9 while (i--)
10 resArray[i] = [ownProps[i], obj[ownProps[i]]];
11
12 return resArray;
13 };
14 }
15
16exports.admins =
17[
18 "124136556578603009",
19 "193093226096361472"
20]
21
22exports.cmds =
23[
24
25 /*
26 DEFAULT COMMANDS - Don't change unless you're really sure!
27 */
28 {
29 cmd: "help",
30 params: "category",
31 category: "main",
32 execute: function(bot, info, args)
33 {
34 var cmds = ["Commands:"];
35
36 var categories = ["Categories:"];
37
38 var category = args.join(" ").toLowerCase();
39
40 if(args.length == 0)
41 {
42 for(var i = 0; i < bot.commands.length; i++)
43 {
44 var found = false;
45
46 for(var c = 0; c < categories.length; c++)
47 {
48 if(categories[c] == "- " + bot.commands[i].category || bot.commands[i].hidden == true || bot.commands[i].category == "wip")
49 {
50 found = true;
51 }
52 }
53
54 if(!found)
55 {
56 categories.push("- " + bot.commands[i].category);
57 }
58 }
59
60 bot.sendMessage({
61 to: info.channelID,
62 message: "Help Categories: ```" + categories.join("\n") /*+ (wip.length > 1? "\n\n" + wip.join("\n") : "")*/ + "```",
63 typing: false
64 });
65 }
66 else
67 {
68 for(var i = 0; i < bot.commands.length; i++)
69 {
70 if(!bot.commands[i].hidden && bot.commands[i].category == category)
71 {
72 var lines = "";
73
74 for(var a = 0; a < 15 - bot.commands[i].cmd.length; a++)
75 lines += "-";
76
77 if(!bot.commands[i].wip)
78 cmds.push (">" + bot.commands[i].cmd + " " + lines + " parameters: " + bot.commands[i].params);
79 else
80 wip.push (">" + bot.commands[i].cmd + " " + lines + " parameters: " + bot.commands[i].params);
81 }
82 }
83
84 bot.sendMessage({
85 to: info.channelID,
86 message: "Commands: ```" + cmds.join("\n") /*+ (wip.length > 1? "\n\n" + wip.join("\n") : "")*/ + "```",
87 typing: false
88 });
89 }
90 }
91 },
92 {
93 cmd: "debughelp",
94 params: "none",
95 hidden: true,
96 category: "admin",
97 execute: function(bot, info, args)
98 {
99 var cmds = ["Commands:"];
100 var hidden = ["Admin-only commands:"];
101
102 for(var i = 0; i < bot.commands.length; i++)
103 {
104 var lines = "";
105
106 for(var a = 0; a < 15 - bot.commands[i].cmd.length; a++)
107 lines += "-";
108
109 if(!bot.commands[i].hidden)
110 cmds.push (">" + bot.commands[i].cmd + " " + lines + " parameters: " + bot.commands[i].params);
111 else
112 hidden.push (">" + bot.commands[i].cmd + " " + lines + " parameters: " + bot.commands[i].params);
113 }
114
115 bot.sendMessage({
116 to: info.channelID,
117 message: "Admins: <@" + exports.admins.join("> <@") + "> ```" + /*cmds.join("\n") + "\n\n" + */ hidden.join("\n") + "```",
118 typing: false
119 });
120 }
121 },
122 {
123 cmd: "serverid",
124 params: "none",
125 hidden: true,
126 category: "admin",
127 execute: function(bot, info, args)
128 {
129 bot.sendMessage({
130 to: info.channelID,
131 message: "Server ID: `" + bot.data[info.serverId].serverId + "`",
132 typing: false
133 });
134 }
135 },
136 {
137 cmd: "invitelink",
138 params: "none",
139 category: "main",
140 execute: function(bot, info, args)
141 {
142 bot.sendMessage({
143 to: info.channelID,
144 message: "https://discordapp.com/oauth2/authorize?&client_id=915336925638967366&scope=bot&permissions=511040",
145 typing: false
146 });
147 }
148 },
149 {
150 cmd: "ping",
151 params: "none",
152 category: "main",
153 execute: function(bot, info, args)
154 {
155 bot.sendMessage({
156 to: info.channelID,
157 message: "<@!" + info.userID + ">" + ' Pong!',
158 typing: false
159 });
160 }
161 },
162 {
163 cmd:"update",
164 params: "none",
165 hidden:true,
166 category: "admin",
167 execute:function(bot, info, args)
168 {
169 var exec = require('child_process').exec;
170
171 bot.data.update = info.channelID;
172
173 bot.sendMessage({
174 to: info.channelID,
175 message: "Fetching changes...",
176 typing: false
177 }, function()
178 {
179 exec('git fetch --all', function(err, stdout, stderr)
180 {
181 exec('git log --oneline master..origin/master', function(err, stdout, stderr)
182 {
183 bot.sendMessage({
184 to: info.channelID,
185 message: (stdout == ""? "No changes, " : "Changes: ```" + stdout + "``` Updating and ") + "reloading!",
186 typing: false
187 }, function()
188 {
189 bot.suicide();
190 });
191 });
192 });
193 });
194 }
195 },
196 {
197 cmd: "memdump",
198 params: "none",
199 hidden: true,
200 category: "admin",
201 execute:function(bot, info, args)
202 {
203 bot.sendMessage({
204 to: info.channelID,
205 message: "```" + JSON.stringify(bot.data[info.serverId]) + "```",
206 typing: false
207 });
208 }
209 },
210 {
211 cmd: "globalmemdump",
212 params: "none",
213 hidden: true,
214 category: "admin",
215 execute:function(bot, info, args)
216 {
217 bot.sendMessage({
218 to: info.channelID,
219 message: "```" + JSON.stringify(bot.data) + "```",
220 typing: false
221 });
222 }
223 },
224 {
225 cmd: "clearlocalmem",
226 params: "none",
227 hidden: true,
228 category: "admin",
229 execute:function(bot, info, args)
230 {
231 bot.sendMessage({
232 to: info.channelID,
233 message: "Clearing memory!",
234 typing: false
235 });
236
237 bot.data[info.serverId] = {};
238 }
239 },
240 {
241 cmd: "clearglobalmem",
242 params: "none (untested)",
243 hidden: true,
244 category: "admin",
245 execute:function(bot, info, args)
246 {
247 bot.sendMessage({
248 to: info.channelID,
249 message: "Clearing global memory!",
250 typing: false
251 });
252
253 bot.data = {};
254 }
255 },
256 {
257 cmd: "stream",
258 params: "'streaming' string",
259 category: "meta",
260 execute:function(bot, info, args)
261 {
262 bot.setPresence({game:
263 {
264 name:args.join(" "),
265 type: 1
266 }
267 });
268
269 bot.sendMessage({
270 to: info.channelID,
271 message: "_Now streaming " + args.join(" ") + "_",
272 typing:false
273 })
274 }
275 },
276 {
277 cmd: "listento",
278 params: "'listening to' string",
279 category: "meta",
280 execute:function(bot, info, args)
281 {
282 bot.setPresence({game:
283 {
284 name:args.join(" "),
285 type: 2
286 }
287 });
288
289 bot.sendMessage({
290 to: info.channelID,
291 message: "_Now listening to " + args.join(" ") + "_",
292 typing:false
293 })
294 }
295 },
296 {
297 cmd: "watch",
298 params: "'watching' string",
299 category: "meta",
300 execute:function(bot, info, args)
301 {
302 bot.setPresence({game:
303 {
304 name:args.join(" "),
305 type: 3
306 }
307 });
308
309 bot.sendMessage({
310 to: info.channelID,
311 message: "_Now watching " + args.join(" ") + "_",
312 typing:false
313 })
314 }
315 },
316 {
317 cmd: "givefile",
318 params: "nothing",
319 category: "admin",
320 hidden: true,
321 execute:function(bot, info, args)
322 {
323 var url = args.join(" ");
324
325 bot.uploadFile({
326 to: info.channelID,
327 file: url
328 }, function(error, response)
329 {
330 console.log(error);
331 })
332 }
333 },
334 {
335 cmd: "version",
336 params: "none",
337 category: "main",
338 execute: function(bot, info, args)
339 {
340 var exec = require('child_process').exec
341 exec('git log --oneline -n 1 HEAD', function(err, stdout, stderr)
342 {
343 console.log(stdout)
344 bot.sendMessage({
345 to: info.channelID,
346 message: "Current version: ```" + stdout + "```",
347 typing:false
348 })
349 })
350 }
351 }
352]
353
354function rand(min, max)
355{
356 return min + (Math.floor(Math.random() *(max - min)));
357}
358
359function shuffle(a) {
360 var j, x, i;
361 for (i = a.length - 1; i > 0; i--) {
362 j = Math.floor(Math.random() * (i + 1));
363 x = a[i];
364 a[i] = a[j];
365 a[j] = x;
366 }
367 return a;
368}