This repository has been archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
kirbi.js
72 lines (67 loc) · 1.91 KB
/
kirbi.js
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
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
console.log(chalk.green(`Starting Kirbi...`));
console.log(chalk.green(`Node version: ${process.version}`));
// Helpers
exports.require = filePath => {
delete require.cache[path.join(path.dirname(require.main.filename), filePath)];
return require(path.join(path.dirname(require.main.filename), filePath))(this);
};
exports.getFileContents = filePath => {
try {
return fs.readFileSync(path.join(path.dirname(require.main.filename), filePath), 'utf-8');
} catch (err) {
console.log(chalk.red(err));
return '';
}
};
exports.getFileArray = srcPath => {
try {
srcPath = path.join(path.dirname(require.main.filename), srcPath);
return fs.readdirSync(srcPath).filter(file => fs.statSync(path.join(srcPath, file)).isFile());
} catch (err) {
console.log(chalk.red(err));
return [];
}
};
exports.getJsonObject = filePath => {
return JSON.parse(exports.getFileContents(filePath));
};
exports.resolveMention = usertxt => {
let userid = usertxt;
if (usertxt.startsWith('<@!')) {
userid = usertxt.substr(3, usertxt.length - 4);
} else if (usertxt.startsWith('<@')) {
userid = usertxt.substr(2, usertxt.length - 3);
}
return userid;
};
exports.Auth = require('./lib/auth');
exports.Config = require('./lib/config');
exports.Permissions = require('./lib/permissions');
require('./lib/commands')(this);
// Initialize AI
if (exports.Config.elizaEnabled && !exports.Eliza) {
const Eliza = require('./extras/eliza');
exports.Eliza = new Eliza();
console.log('Eliza enabled.');
exports.Eliza.memSize = 500;
}
// Bot login
exports.login = () => {
if (exports.Config.discord.enabled) {
try {
require('kirbi-discord').discordLogin(this);
} catch (err) {
console.log(chalk.red(err));
}
}
if (exports.Config.slack.enabled) {
try {
require('kirbi-slack').slackLogin(this);
} catch (err) {
console.log(chalk.red(err));
}
}
};