Created
September 16, 2016 04:58
-
-
Save sr229/9de71a89a4484d59f595ed85db54f5c9 to your computer and use it in GitHub Desktop.
out file from bot-es6.js by babel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Project Clementine | |
* this is an experimental ES6 implementation | |
* some features don't work | |
* use at your own risk. | |
* -Capuccino | |
*/ | |
"use strict"; | |
var _discord = require("discord.js"); | |
var _fs = require("fs"); | |
var _util = require("util"); | |
var _http = require("http"); | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
//config | |
var config = require("./botConfig.json"); | |
var prefix = config.prefix; | |
var clementine = new _discord.Discord.Client({ | |
autoReconnect: true | |
}); | |
clementine.on("ready", function () { | |
console.log("ready!"); | |
}); | |
var Commands = function Commands() { | |
_classCallCheck(this, Commands); | |
this.ping = { | |
name: "ping", | |
desc: "a ping-pong example!", | |
longDesc: "ping me desu desu", | |
main: function main(clementine, msg) { | |
var start = Date.now(); | |
clementine.sendMessage(msg.channel, 'Pong!').then(function (m) { | |
var end = Date.now(); | |
var diff = end - start; | |
clementine.updateMessage(m, 'Pong! `' + diff + 'ms`'); | |
}); | |
} | |
}; | |
}; | |
//command handler | |
clementine.on("message", function (msg) { | |
if (msg.content.startsWith(config.prefix)) { | |
var noPrefix = msg.content.substring(config.prefix.length, msg.content.length); | |
var noPrefixSplit = noPrefix.split(" "); | |
var cmd = noPrefixSplit[0]; | |
var preArgs = msg.content.substring(prefix.length + noPrefixSplit[0], msg.content.length); | |
var args = preArgs.split(" "); | |
var preSuffix = msg.content.substring(prefix.length + noPrefixSplit[0], msg.content.length); | |
var suffix = preSuffix.split(" "); | |
suffix.split(); | |
args.shift(); | |
if (commands[cmd] !== undefined) { | |
if (commands[cmd].adminOnly) { | |
_fs.fs.readFile('./adminList.json', function (err, listData) { | |
if (!err) { | |
var adminList = JSON.parse(listData); | |
if (adminList.indexOf(msg.author.id) > -1 || msg.author.id === config.ownerID) { | |
commands[cmd].main(bot, msg, args); | |
} else { | |
bot.sendMessage(msg, _util.util.format('I\'m sorry, but you need to be on the admin list in order to run this command.')); | |
} | |
} else if (err) { | |
bot.sendMessage(msg, "Experienced error while trying to execute command `" + cmd + "`.\n```\n" + err + "\n```"); | |
} | |
}); | |
} else { | |
_fs.fs.readFile('./blackList.json', function (err, blData) { | |
if (!err) { | |
var blackList = JSON.parse(blData); | |
if (blackList.indexOf(msg.author.id) === -1) { | |
commands[cmd].main(bot, msg, args); | |
} | |
} else if (err) { | |
clementine.sendMessage(msg, "Experienced error while trying to execute command `" + cmd + "`.\n```\n" + err + "\n```"); | |
} | |
}); | |
} | |
} | |
} | |
if (msg.content.startsWith("<@" + bot.user.id + "> prefix")) { | |
clementine.reply(msg.channel.id, "***My prefix is *** `" + prefix + "`!"); | |
} | |
}); | |
if (config.useEmail === false) { | |
clementine.loginWithToken(config.token); | |
} else if (config.useEmail === true) { | |
clementine.login(config.email, config.password); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment