-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.js
More file actions
45 lines (38 loc) · 1.33 KB
/
chat.js
File metadata and controls
45 lines (38 loc) · 1.33 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
/**
* Chat
*
* This handles the bots parser, as well as assigning the bots commands
*
* @license MIT license
*/
'use strict';
const fs = require('fs');
const path = require('path');
const commands = exports.commands = require('./chat-commands').commands;
for (let file of fs.readdirSync(path.resolve(__dirname, 'chat-plugins'))) {
if (file.substr(-3) !== '.js') continue;
Object.assign(commands, require('./chat-plugins/' + file).commands);
}
exports.parse = function (message, target, room, user) {
const cmd = message.substr(1, message.length).split(' ')[0].trim();
const cmdId = Tools.toId(cmd);
const trigger = Config.cmdchar;
if (message.startsWith(Config.cmdchar) && commands[cmdId]) {
if (Config.logcmds) console.log(`CMD USED: ${message} | user: ${user.username}#${user.discriminator}`);
try { // try calling the command
if (typeof commands[cmdId] === 'string') return commands[commands[cmdId]](target, room, user, cmd, trigger); // alias
commands[cmdId](target, room, user, cmd, trigger); // runs the command
} catch (e) {
Chat.send(room, e.stack); // send user crash message
}
}
};
exports.send = function (room, message) {
room.send('```' + message + '```');
};
exports.basicSend = function (room, message) {
room.send(message);
}
exports.isAdmin = function (user) {
return Config.admins.includes(user.id);
};