Permalink
Browse files

Start on ES7 update.

  • Loading branch information...
roncli committed Nov 20, 2018
1 parent 476be75 commit da465361695fc41ba3910e8f69a6dd86d69e2d44
Showing with 46 additions and 13 deletions.
  1. +3 −1 .eslintrc
  2. +18 −0 commands.js
  3. +1 −0 index.js
  4. +12 −5 log.js
  5. +1 −1 package.json
  6. +11 −6 tmi.js
@@ -5,8 +5,9 @@
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6
"ecmaVersion": 7
},
"parser": "babel-eslint",
"extends": "eslint:all",
"rules": {
"array-element-newline": "off",
@@ -79,6 +80,7 @@
"prefer-promise-reject-errors": [
"error", {"allowEmptyReject": true}
],
"require-unicode-regexp": "off",
"sort-keys": "off",
"sort-vars": "off",
"space-before-function-paren": "off",
@@ -50,6 +50,24 @@ class Commands {
}
}
// # # ## # #
// # # # # #
// ### ### # # ## ### # ### ## ## # #
// # # # # #### # # # # # # # ## # ##
// # ## # # # # # # # # # # # ## # # #
// # # ### # # ### # # ## # # ## ## # #
/**
* Throws an error if the user is not an admin.
* @param {Commands} commands The commands object.
* @param {string|User} user The user to check.
* @returns {void}
*/
static adminCheck(commands, user) {
if (!(commands.service.name === "Discord" && Discord.isPodcaster(user) || commands.service.name === "Tmi" && Tmi.isMod(user))) {
throw new Error("Admin permission required to perform this command.");
}
}
// # # ### #
// # # #
// ### ### # # ## ### # # ### ## # # ## ### ##
@@ -16,6 +16,7 @@ const Db = require("./database"),
(function startup() {
Log.log("Starting up...");
// Set the window title.
if (process.platform === "win32") {
process.title = "SixBotGG";
} else {
17 log.js
@@ -29,7 +29,7 @@ class Log {
// ###
/**
* Logs a message.
* @param {*} obj The object to log.
* @param {object} obj The object to log.
* @returns {void}
*/
static log(obj) {
@@ -50,7 +50,7 @@ class Log {
// ###
/**
* Logs a warning.
* @param {*} obj The object to log.
* @param {object} obj The object to log.
* @returns {void}
*/
static warning(obj) {
@@ -72,7 +72,7 @@ class Log {
/**
* Logs an exception.
* @param {string} message The message describing the error.
* @param {*} obj The object to log.
* @param {object} obj The object to log.
* @returns {void}
*/
static exception(message, obj) {
@@ -109,7 +109,7 @@ class Log {
const message = {
embed: {
color: log.type === "log" ? 0x80FF80 : log.type === "warning" ? 0xFFFF00 : log.type === "exception" ? 0xFF0000 : 0x16F6F8,
footer: {icon_url: Discord.icon}, // eslint-disable-line camelcase
footer: {"icon_url": Discord.icon, text: "SixBotGG"},
fields: [],
timestamp: log.date
}
@@ -120,9 +120,16 @@ class Log {
}
if (log.obj) {
const msg = util.inspect(log.obj);
if (msg.length > 1024) {
Discord.queue(msg, log.type === "exception" ? errorChannel : logChannel);
return;
}
message.embed.fields.push({
name: "Message",
value: util.inspect(log.obj)
value: msg
});
}
@@ -18,7 +18,7 @@
"url": "https://github.com/roncli/SixBotGG.git"
},
"dependencies": {
"discord.js": "11.3.2",
"discord.js": "11.4.2",
"node-database": "roncli/node-database#v1.0.2",
"tmi.js": "1.2.1",
"twitch-api": "0.5.0"
17 tmi.js
@@ -44,11 +44,14 @@ class Tmi {
static startup() {
Tmi.commands = new Commands(Tmi);
tmi.on("connected", () => {
tmi.on("connected", async () => {
Log.log("Connected to tmi.");
tmi.raw("CAP REQ :twitch.tv/membership").catch((err) => {
try {
await tmi.raw("CAP REQ :twitch.tv/membership");
} catch (err) {
Log.exception("Raw command failed.", err);
});
}
});
tmi.on("disconnected", (ev) => {
@@ -155,10 +158,12 @@ class Tmi {
* @param {string} message The message to be sent.
* @returns {Promise} A promise that resolves when the message is sent.
*/
static queue(message) {
return tmi.say("sixgaminggg", message).catch((err) => {
static async queue(message) {
try {
await tmi.say("sixgaminggg", message);
} catch (err) {
Log.exception("Say command failed.", err);
});
}
}
// # #

0 comments on commit da46536

Please sign in to comment.