diff --git a/bot.js b/bot.js index 31cfeeb..de8e9ba 100644 --- a/bot.js +++ b/bot.js @@ -197,15 +197,24 @@ class Bot { // shuts down the bot after destroying the client cmd.createGlobalCommand(prefix + 'shutdown', (msg) => { - msg.reply('Shutting down...').finally(() => { + msg.reply('Shutting down...').catch((err) => { + logger.error(err.message); + logger.debug(err.stack); + }).finally(() => { logger.debug('Destroying client...'); - this.client.destroy().finally(() => { + this.client.destroy().catch((err) => { + logger.error(err.message); + logger.debug(err.stack); + }).finally(() => { logger.debug('Exiting server...'); + this.webServer.stop().then(() => { logger.debug(`Exiting Process...`); process.exit(0); - }).catch(() => { + }).catch((err) => { + logger.error(err.message); + logger.debug(err.stack); process.exit(0); }); }); @@ -251,15 +260,14 @@ class Bot { resolve("It's not save here! Try again via PM."); } else if (argv.username && argv.scope) { logger.debug(`Creating user entry ${argv.username}, scope: ${argv.scope}`); + this.webServer.createUser(argv.username, argv.password, argv.scope, false).then((token) => { resolve(`Created entry username: ${argv.username}, scope: ${argv.scope}, token: ${token} `); - }).catch((err) => { - reject(err.message); - }); + }).catch((err) => reject(err.message)); } }); }, ['username', 'password', 'scope'], 'Generates a token for a username and returns it.', 'owner'); @@ -271,15 +279,17 @@ class Bot { rotatePresence() { let pr = this.presences.shift(); this.presences.push(pr); + this.client.user.setPresence({ game: {name: `${gamepresence} | ${pr}`, type: "PLAYING"}, status: 'online' - }).then(() => logger.debug(`Presence rotation to ${pr}`)); + }).then(() => logger.debug(`Presence rotation to ${pr}`)) + .catch((err) => logger.warn(err.message)); } /** - * Registeres callbacks for client events + * Registeres callbacks for client events message and ready */ registerCallbacks() { this.client.on('error', (err) => { diff --git a/package.json b/package.json index cef4be4..0e479da 100644 --- a/package.json +++ b/package.json @@ -51,27 +51,49 @@ "jquery": true, "es6": true }, - "extends": ["eslint:recommended", "plugin:promise/recommended"], + "extends": [ + "eslint:recommended", + "plugin:promise/recommended" + ], "rules": { "semi": "error", "semi-style": [ "error", "last" ], - "no-async-promise-executer": "warn", "no-await-in-loop": "warn", "curly": [ "warn", "multi", "consistent" ], - "block-spacing": ["warn", "always"], - "array-bracket-newline": ["warn", "consistent"], - "camelcase": ["error", {"properties": "always"}], - "comma-spacing": ["error", {"after": true}], - "brace-style": ["error", "1tbs"], + "block-spacing": [ + "warn", + "always" + ], + "array-bracket-newline": [ + "warn", + "consistent" + ], + "camelcase": [ + "error", + { + "properties": "always" + } + ], + "comma-spacing": [ + "error", + { + "after": true + } + ], + "brace-style": [ + "error", + "1tbs" + ], "promise/no-promise-in-callback": "off", - "promise/always-return": "off" + "promise/always-return": "off", + "promise/catch-or-return": "off" }, "plugins": [ "eslint-plugin-graphql", diff --git a/web/http/scripts/query.js b/web/http/scripts/query.js index 91d1b4d..0097eb5 100644 --- a/web/http/scripts/query.js +++ b/web/http/scripts/query.js @@ -68,7 +68,7 @@ function queryGuilds() { } }`; postQuery(query).then((res) => { - for (let guild of res.data.client.guilds) { + for (let guild of res.data.client.guilds) if ($(`option[value=${guild.id}]`).length === 0) { let option = document.createElement('option'); option.setAttribute('value', guild.id); @@ -77,7 +77,7 @@ function queryGuilds() { let guildSelect = document.querySelector('#guild-select'); guildSelect.appendChild(option); } - } + }); } @@ -220,11 +220,11 @@ function queryStatus() { document.querySelector('#client-guildCount').innerText = d.client.guildCount; document.querySelector('#client-vcCount').innerText = d.client.voiceConnectionCount; - if (d.client.status !== 0) { + if (d.client.status !== 0) document.querySelector('#status-indicator').setAttribute('status', 'offline'); - } else { + else document.querySelector('#status-indicator').setAttribute('status', d.client.user.presence.status); - } + document.querySelector('#user-game').innerText = d.client.user.presence.game; setTimeout(() => { @@ -247,7 +247,7 @@ function queryLogs(count) { }`; postQuery(query).then((res) => { let d = res.data; - for (let logEntry of d.logs) { + for (let logEntry of d.logs) if (!latestLogs.find((x) => x.id === logEntry.id)) { let entryElem = document.createElement('div'); entryElem.setAttribute('class', 'logEntry text-left'); @@ -272,15 +272,15 @@ function queryLogs(count) { let logContainer = document.querySelector('#log-container'); logContainer.insertBefore(entryElem, logContainer.firstChild); } - } + latestLogs = d.logs; }); } function startUpdating() { - if (!localStorage.apiToken || localStorage.apiToken.length < 0) { + if (!localStorage.apiToken || localStorage.apiToken.length < 0) localStorage.apiToken = prompt('Please provide an api token: '); - } + queryStatic(); setInterval(queryStatic, 3600000); queryStatus();