Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathinitCommands.js
More file actions
476 lines (399 loc) · 20.6 KB
/
Copy pathinitCommands.js
File metadata and controls
476 lines (399 loc) · 20.6 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
* Copyright (C) 2016-2026 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* global Packages */
(function() {
let useBotName = $.getSetIniDbBoolean('settings', 'initCommands.useBotName', true);
let sentReady = false;
/*
* @event command
*/
$.bind('command', function(event) {
let sender = event.getSender(),
command = event.getCommand(),
argsString = event.getArguments(),
args = event.getArgs(),
action = args[0],
subAction = args[1];
if ($.equalsIgnoreCase(command, 'pbcore')) {
if (action === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.usage', command));
return;
}
/*
* @commandpath pbcore usebotname - Toggles using the bot name for initCommands commands.
*/
if ($.equalsIgnoreCase(action, 'usebotname')) {
useBotName = !useBotName;
$.setIniDbBoolean('settings', 'initCommands.useBotName', useBotName);
if (useBotName) {
$.registerChatAlias($.botName.toLowerCase(), 'pbcore', './core/initCommands.js');
} else {
$.unregisterChatAlias($.botName.toLowerCase());
}
$.say($.whisperPrefix(sender) + $.lang.get('init.toggle.botname', $.botName.toLowerCase(), (useBotName ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
}
/*
* @commandpath pbcore disconnect - Removes the bot from your channel.
*/
if ($.equalsIgnoreCase(action, 'disconnect')) {
$.say($.whisperPrefix(sender) + $.lang.get('init.disconnect'));
setTimeout(function() {
Packages.java.lang.System.exit(0);
}, 1000);
}
/*
* @commandpath pbcore reconnect - Reconnects the bot to TMI and EventSub.
*/
if ($.equalsIgnoreCase(action, 'reconnect')) {
$.say($.whisperPrefix(sender) + $.lang.get('init.reconnect'));
setTimeout(function() {
Packages.tv.phantombot.PhantomBot.instance().reconnect();
}, 1000);
}
/*
* @commandpath pbcore moderate - Forces the bot to detect its moderator status.
*/
if ($.equalsIgnoreCase(action, 'moderate')) {
Packages.tv.phantombot.PhantomBot.instance().getSession().getModerationStatus();
}
/*
* @commandpath pbcore forceonline - Forces the bot to mark the channel as online.
*/
if ($.equalsIgnoreCase(action, 'forceonline')) {
$.say($.whisperPrefix(sender) + $.lang.get('init.forceonline'));
Packages.tv.phantombot.event.EventBus.instance().postAsync(new Packages.tv.phantombot.event.twitch.online.TwitchOnlineEvent());
}
/*
* @commandpath pbcore forceoffline - Forces the bot to mark the channel as offline.
*/
if ($.equalsIgnoreCase(action, 'forceoffline')) {
$.say($.whisperPrefix(sender) + $.lang.get('init.forceoffline'));
Packages.tv.phantombot.event.EventBus.instance().postAsync(new Packages.tv.phantombot.event.twitch.offline.TwitchOfflineEvent());
}
/*
* @commandpath pbcore setconnectmessage [message] - Sets a message that will be said once the bot joins the channel.
*/
if ($.equalsIgnoreCase(action, 'setconnectmessage')) {
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg.usage', bot));
return;
}
let message = args.slice(1).join(' ');
$.setIniDbString('settings', 'connectedMsg', message);
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg', message));
}
/*
* @commandpath pbcore removeconnectmessage - Removes the message said when the bot joins the channel.
*/
if ($.equalsIgnoreCase(action, 'removeconnectmessage')) {
$.inidb.del('settings', 'connectedMsg');
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg.removed'));
}
/*
* @commandpath pbcore togglepricecommods - Toggles if moderators and higher pay for commands.
*/
if ($.equalsIgnoreCase(action, 'togglepricecommods')) {
let toggle = !$.getIniDbBoolean('settings', 'pricecomMods', false);
$.setIniDbBoolean('settings', 'pricecomMods', toggle);
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.on.pay') : $.lang.get('init.mod.toggle.off.pay')));
}
/*
* @commandpath pbcore togglepermcommessage - Toggles if the no permission message is said in the chat.
*/
if ($.equalsIgnoreCase(action, 'togglepermcommessage')) {
let toggle = !$.getIniDbBoolean('settings', 'permComMsgEnabled', false);
$.setIniDbBoolean('settings', 'permComMsgEnabled', toggle);
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.perm.msg.on') : $.lang.get('init.mod.toggle.perm.msg.off')));
}
/*
* @commandpath pbcore togglepricecommessage - Toggles if the cost message is said in the chat.
*/
if ($.equalsIgnoreCase(action, 'togglepricecommessage')) {
let toggle = !$.getIniDbBoolean('settings', 'priceComMsgEnabled', false);
$.setIniDbBoolean('settings', 'priceComMsgEnabled', toggle);
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.price.msg.on') : $.lang.get('init.mod.toggle.price.msg.off')));
}
/*
* @commandpath pbcore togglecooldownmessage - Toggles if the cooldown message is said in the chat.
*/
if ($.equalsIgnoreCase(action, 'togglecooldownmessage')) {
let toggle = !$.getIniDbBoolean('settings', 'coolDownMsgEnabled', false);
$.setIniDbBoolean('settings', 'coolDownMsgEnabled', toggle);
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.toggle.cooldown.msg.on') : $.lang.get('init.toggle.cooldown.msg.off')));
}
/*
* @commandpath pbcore togglecustomcommandat - Toggles if custom commands without command tags can be targeted by mods using !mycommand @user
*/
if ($.equalsIgnoreCase(action, 'togglecustomcommandat')) {
let toggle = !$.getIniDbBoolean('settings', 'customCommandAtEnabled', true);
$.setIniDbBoolean('settings', 'customCommandAtEnabled', toggle);
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.toggle.customCommandAt.on') : $.lang.get('init.toggle.customCommandAt.off')));
}
}
if ($.equalsIgnoreCase(command, 'module')) {
if (action === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage'));
return;
}
/*
* @commandpath module reload [path/all (option)] - Force reloads all active modules or force reloads a single module.
*/
if ($.equalsIgnoreCase(action, 'reload')) {
if (subAction === undefined || $.equalsIgnoreCase(subAction, 'all')) {
$.bot.loadScriptRecursive('', false, true);
$.say($.whisperPrefix(sender) + $.lang.get('init.module.reload.all'));
return;
}
if ($.getIniDbString('modules', subAction, undefined) !== undefined){
let module = $.bot.getModule(subAction);
if (module !== undefined) {
$.bot.loadScript(module.scriptName, true, false);
$.say($.whisperPrefix(sender) + $.lang.get('init.module.reload', subAction));
} else {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.404'));
}
return;
}
$.say($.whisperPrefix(sender) + $.lang.get('init.module.reload.usage'));
return;
}
/*
* @commandpath module delete [path] - Removes a module from the modules list. This does not remove the module itself.
*/
if ($.equalsIgnoreCase(action, 'delete')) {
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.usage'));
return;
} else if ($.getIniDbString('modules', subAction, undefined) === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.404', subAction));
return;
}
$.inidb.del('modules', subAction);
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.success', subAction));
}
/*
* @commandpath module list - Gives a list of all the modules with their current status.
*/
if ($.equalsIgnoreCase(action, 'list')) {
let keys = Object.keys($.bot.modules),
modules = $.bot.modules,
temp = [],
i;
for (i in keys) {
if (modules[keys[i]].scriptName.indexOf('./core') !== -1 || modules[keys[i]].scriptName.indexOf('./lang') !== -1) {
continue;
}
temp.push(modules[keys[i]].scriptName + (modules[keys[i]].isEnabled ? ' (' + $.lang.get('common.enabled') + ')' : ' (' + $.lang.get('common.disabled') + ')'));
}
let totalPages = $.paginateArray(temp, 'init.module.list', ', ', true, sender, (isNaN(parseInt(subAction)) ? 1 : parseInt(subAction)));
if (totalPages > 0) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.list.total', totalPages));
}
}
/*
* @commandpath module status [module path] - Retrieve the current status (enabled/disabled) of the given module
*/
if ($.equalsIgnoreCase(action, 'status')) {
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.status'));
return;
}
let module = $.bot.getModule(subAction);
if (module !== undefined) {
if (module.isEnabled) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.check.enabled', module.getModuleName()));
} else {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.check.disabled', module.getModuleName()));
}
} else {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
}
}
/*
* @commandpath module enable [module path] - Enable a module using the path and name of the module
*/
if ($.equalsIgnoreCase(action, 'enable')) {
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.enable'));
return;
}
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
return;
}
let module = $.bot.getModule(subAction);
if (module !== undefined) {
$.setIniDbBoolean('modules', module.scriptName, true);
$.bot.loadScript(module.scriptName);
$.bot.modules[module.scriptName].isEnabled = true;
let hookIndex = $.bot.getHookIndex($.bot.modules[module.scriptName].scriptName, 'initReady');
try {
if (hookIndex !== -1) {
$.bot.getHook(module.scriptName, 'initReady').handler();
}
$.say($.whisperPrefix(sender) + $.lang.get('init.module.enabled', module.getModuleName()));
} catch (ex) {
$.log.error('Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex);
$.consoleLn("Sending stack trace to error log...");
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
}
} else {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
}
}
/*
* @commandpath module disable [module path] - Disable a module using the path and name of the module
*/
if ($.equalsIgnoreCase(action, 'disable')) {
if (subAction === undefined) {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.disable'));
return;
}
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
return;
}
let module = $.bot.getModule(subAction);
if (module !== undefined) {
$.setIniDbBoolean('modules', module.scriptName, false);
$.bot.modules[module.scriptName].isEnabled = false;
$.say($.whisperPrefix(sender) + $.lang.get('init.module.disabled', module.getModuleName()));
if ($.equalsIgnoreCase(module.scriptName, './systems/pointSystem.js')) {
let modules = ['./games/adventureSystem.js', './games/roll.js', './games/slotMachine.js', './systems/ticketraffleSystem.js', './systems/raffleSystem.js', './games/gambling.js'],
i;
for (i in modules) {
module = $.bot.getModule(modules[i]);
$.bot.modules[modules[i]].isEnabled = false;
$.setIniDbBoolean('modules', module.scriptName, false);
}
$.say($.whisperPrefix(sender) + $.lang.get('init.module.auto-disabled'));
}
} else {
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
}
}
/*
* Panel command.
*/
if ($.equalsIgnoreCase(action, 'enablesilent')) {
if (subAction === undefined) {
return;
}
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
return;
}
let module = $.bot.getModule(subAction);
if (module !== undefined) {
$.setIniDbBoolean('modules', module.scriptName, true);
$.bot.loadScript(module.scriptName);
$.bot.modules[module.scriptName].isEnabled = true;
let hookIndex = $.bot.getHookIndex(module.scriptName, 'initReady');
try {
if (hookIndex !== -1) {
$.bot.getHook(module.scriptName, 'initReady').handler();
}
} catch (ex) {
$.log.error('Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex);
$.consoleLn("Sending stack trace to error log...");
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
}
}
}
/*
* Panel command.
*/
if ($.equalsIgnoreCase(action, 'disablesilent')) {
if (subAction === undefined) {
return;
}
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
return;
}
let module = $.bot.getModule(subAction);
if (module !== undefined) {
$.setIniDbBoolean('modules', module.scriptName, false);
$.bot.modules[module.scriptName].isEnabled = false;
if ($.equalsIgnoreCase(module.scriptName, './systems/pointSystem.js')) {
let modules = ['./games/adventureSystem.js', './games/roll.js', './games/slotMachine.js', './systems/ticketraffleSystem.js', './systems/raffleSystem.js', './games/gambling.js'],
i;
for (i in modules) {
module = $.bot.getModule(modules[i]);
$.bot.modules[module.scriptName].isEnabled = false;
$.setIniDbBoolean('modules', module.scriptName, false);
}
}
}
}
}
/*
* Panel command.
*/
if ($.equalsIgnoreCase(command, 'reconnect')) {
if ($.isBot(sender)) {
Packages.tv.phantombot.PhantomBot.instance().reconnect();
}
}
/*
* Panel command.
*/
if ($.equalsIgnoreCase(command, 'disconnect')) {
if ($.isBot(sender)) {
Packages.java.lang.System.exit(0);
}
}
/*
* @commandpath echo [message] - Send a message as the bot.
*/
if ($.equalsIgnoreCase(command, 'chat') || $.equalsIgnoreCase(command, 'echo')) {
if ($.strlen(argsString) > 0) {
$.say(argsString);
}
}
});
/*
* @event initReady
*/
$.bind('initReady', function() {
$.registerChatCommand('./core/initCommands.js', 'chat', $.PERMISSION.Admin);
$.registerChatCommand('./core/initCommands.js', 'module', $.PERMISSION.Admin);
$.registerChatCommand('./core/initCommands.js', 'echo', $.PERMISSION.Admin);
$.registerChatCommand('./core/initCommands.js', 'reconnect', $.PERMISSION.Admin);
$.registerChatCommand('./core/initCommands.js', 'disconnect', $.PERMISSION.Admin);
$.registerChatCommand('./core/initCommands.js', 'pbcore', $.PERMISSION.Mod);
$.registerChatSubcommand('pbcore', 'disconnect', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'reconnect', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'moderate', $.PERMISSION.Mod);
$.registerChatSubcommand('pbcore', 'forceonline', $.PERMISSION.Mod);
$.registerChatSubcommand('pbcore', 'forceoffline', $.PERMISSION.Mod);
$.registerChatSubcommand('pbcore', 'setconnectmessage', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'removeconnectmessage', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'togglepricecommods', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'togglepermcommessage', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'togglepricecommessage', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'togglecooldownmessage', $.PERMISSION.Admin);
$.registerChatSubcommand('pbcore', 'togglecustomcommandat', $.PERMISSION.Admin);
if (useBotName) {
$.registerChatAlias($.botName.toLowerCase(), 'pbcore', './core/initCommands.js');
}
// Say the connected message.
if (!sentReady) {
let connectedMsg = $.optIniDbString('settings', 'connectedMsg');
if (connectedMsg.isPresent()) {
$.say(connectedMsg.get());
sentReady = true;
}
}
});
})();
You can’t perform that action at this time.
