Last active
March 25, 2018 08:32
-
-
Save sr229/7ba75240bdff6f5da3b5233ac4d92121 to your computer and use it in GitHub Desktop.
A Discord bot written in ES6 JavaScript format.
This file contains hidden or 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"; | |
import {Discord} from "discord.js"; | |
import {fs} from "fs"; | |
import {util} from "util"; | |
import {http} from "http"; | |
//config | |
const config = require("./botConfig.json"); | |
const prefix = (config.prefix); | |
const clementine = new Discord.Client({ | |
autoReconnect : true | |
}); | |
clementine.on("ready", function(){ | |
console.log ("ready!"); | |
}); | |
class Commands { | |
constructor(){ | |
this.ping = { | |
name: "ping", | |
desc: "a ping-pong example!", | |
longDesc: "ping me desu desu", | |
main: function(clementine,msg){ | |
var start = Date.now(); | |
clementine.sendMessage(msg.channel, 'Pong!').then(m => { | |
var end = Date.now(); | |
var diff = end - start; | |
clementine.updateMessage(m,'Pong! `'+ diff + 'ms`'); | |
}); | |
} | |
} | |
} | |
} | |
//command handler | |
clementine.on("message", 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.readFile('./adminList.json', (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.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}\`. | |
\`\`\` | |
${err} | |
\`\`\``); | |
} | |
}); | |
} else { | |
fs.readFile('./blackList.json', (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}\`. | |
\`\`\` | |
${err} | |
\`\`\``); | |
} | |
}); | |
} | |
} | |
} | |
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) | |
} |
This file contains hidden or 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
{ | |
"token": "Bot <replace this with token>", | |
"osuApiKey": "", | |
"prefix": "?", | |
"useEmail": false, | |
"email": "email", | |
"password": "password", | |
"botName": "default-name", | |
"botDesc": "default-description", | |
"ownerID": "", | |
"log": false, | |
"logchannel": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment