support for ankhbot commands, static commands, cooldowns, implemented fun/ham facts

This commit is contained in:
Chris Ham
2018-01-22 18:32:09 -08:00
parent be5d8bc2ec
commit a2a9974108
10 changed files with 249 additions and 15 deletions

53
lib/static-commands.js Executable file
View File

@@ -0,0 +1,53 @@
module.exports = {
exists: exists,
get: get
};
const fs = require('fs'),
path = require('path');
const commandsFilePath = path.join(__dirname, '..', 'conf', 'text_commands');
// Read in basic text commands / definitions and watch for changes
let commands = parseCommands(commandsFilePath);
fs.watchFile(commandsFilePath, (curr, prev) => {
if (curr.mtime !== prev.mtime) {
commands = parseCommands(commandsFilePath);
}
});
// Read/parse text commands from the "database"
function parseCommands(filePath)
{
let commands = {};
let data = fs.readFileSync(filePath, 'utf-8');
let commandLines = data.toString().split('\n');
let commandParts;
let aliases;
commandLines.forEach(function(line) {
if (line.length > 0 && line.indexOf('|') !== -1) {
commandParts = line.split('|');
// check for aliases
aliases = commandParts[0].split(',');
aliases.forEach(function(cmd) {
commands[cmd] = commandParts[1];
//console.log(`!${cmd},`);
});
}
});
return commands;
}
function exists(command)
{
return commands.hasOwnProperty(command);
}
function get(command)
{
if (exists(command)) {
return commands[command];
} else {
return undefined;
}
}