From 4c8e9125e562ce2ca9a3eec56838d2e00d4ada7d Mon Sep 17 00:00:00 2001 From: Isaac Date: Tue, 16 Feb 2021 23:35:31 +0000 Subject: [PATCH] Make things work --- package.json | 4 +-- pnpm-lock.yaml | 17 +++++------- src/index.js | 20 ++------------ src/listeners/messageReactionAdd.js | 3 -- src/listeners/ready.js | 4 +-- src/modules/listeners.js | 3 +- src/modules/plugins.js | 43 ++++++++--------------------- user/example.config.js | 22 +++++++++------ 8 files changed, 39 insertions(+), 77 deletions(-) diff --git a/package.json b/package.json index aa358e6..212319d 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "funding": "https://github.com/eartharoid/DiscordTickets/?sponsor=1", "dependencies": { "@eartharoid/i18n": "^0.0.1", + "command-exists": "^1.2.9", "discord.js": "^12.5.1", "dotenv": "^8.2.0", "keyv": "^4.0.3", @@ -36,8 +37,7 @@ "leekslazylogger": "^2.0.7", "node-fetch": "^2.6.1", "sequelize": "^6.5.0", - "terminal-link": "^2.1.1", - "yarpm": "^1.1.1" + "terminal-link": "^2.1.1" }, "devDependencies": { "eslint": "^7.20.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f43a122..6ca3165 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,6 @@ dependencies: '@eartharoid/i18n': 0.0.1 + command-exists: 1.2.9 discord.js: 12.5.1 dotenv: 8.2.0 keyv: 4.0.3 @@ -8,7 +9,6 @@ dependencies: node-fetch: 2.6.1 sequelize: 6.5.0_fb66e8c649bde1be622cc06164c9e22d terminal-link: 2.1.1 - yarpm: 1.1.1 devDependencies: eslint: 7.20.0 mariadb: 2.5.2 @@ -611,6 +611,7 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 + dev: true engines: node: '>= 8' resolution: @@ -1902,6 +1903,7 @@ packages: resolution: integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18= /path-key/3.1.1: + dev: true engines: node: '>=8' resolution: @@ -2336,11 +2338,13 @@ packages: /shebang-command/2.0.0: dependencies: shebang-regex: 3.0.0 + dev: true engines: node: '>=8' resolution: integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== /shebang-regex/3.0.0: + dev: true engines: node: '>=8' resolution: @@ -2773,6 +2777,7 @@ packages: /which/2.0.2: dependencies: isexe: 2.0.0 + dev: true engines: node: '>= 8' hasBin: true @@ -2882,16 +2887,9 @@ packages: /yallist/4.0.0: resolution: integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== - /yarpm/1.1.1: - dependencies: - command-exists: 1.2.9 - cross-spawn: 7.0.3 - dev: false - hasBin: true - resolution: - integrity: sha512-A3gVdtyld+gYcVmKScvJqS2oT/i9xdsb/SqDsY9c0+BeYdYBUJrRfr4pD7UP+5uXEneJ0BL0rC/6rd1fnlYEcg== specifiers: '@eartharoid/i18n': ^0.0.1 + command-exists: ^1.2.9 discord.js: ^12.5.1 dotenv: ^8.2.0 eslint: ^7.20.0 @@ -2908,4 +2906,3 @@ specifiers: sqlite3: ^5.0.2 tedious: ^11.0.3 terminal-link: ^2.1.1 - yarpm: ^1.1.1 diff --git a/src/index.js b/src/index.js index d59d47f..e56ebda 100644 --- a/src/index.js +++ b/src/index.js @@ -60,21 +60,6 @@ const log = new Logger({ } }); - -log.report = error => { - let report = [ - '<< Issue report >>', - 'Please include this information if you ask for help about the following error!', - `Support server: ${terminalLink('go.eartharoid.me/discord', 'https://go.eartharoid.me/discord')}`, - `Node.JS version: ${process.versions.node}`, - `Bot version: ${version}`, - `Platform: ${process.platform}` - ]; - log.warn(report.join('\n')); - if (error) log.error(error); -}; - -const terminalLink = require('terminal-link'); const I18n = require('@eartharoid/i18n'); const { CommandManager } = require('./modules/commands'); @@ -109,7 +94,7 @@ class Bot extends Client { this.plugins = await require('./modules/plugins')(this); this.log.info('Connecting to Discord API'); - + this.login(); })(); } @@ -119,7 +104,8 @@ class Bot extends Client { new Bot(); process.on('unhandledRejection', error => { - log.report(); + log.notice('PLEASE INCLUDE THIS INFORMATION:'); + log.warn(`Discord Tickets v${version}, Node ${process.versions.node} (${process.platform})`); log.warn('An error was not caught'); if (error instanceof Error) log.warn(`Uncaught ${error.name}: ${error}`); log.error(error); diff --git a/src/listeners/messageReactionAdd.js b/src/listeners/messageReactionAdd.js index 25d9e47..cdc2444 100644 --- a/src/listeners/messageReactionAdd.js +++ b/src/listeners/messageReactionAdd.js @@ -1,8 +1,5 @@ module.exports = { event: 'messageReactionAdd', execute: (client, r, u) => { - client.log.info('messageReactionAdd'); - console.log(r); - console.log(u); } }; \ No newline at end of file diff --git a/src/listeners/ready.js b/src/listeners/ready.js index 79458fb..5fc0d3e 100644 --- a/src/listeners/ready.js +++ b/src/listeners/ready.js @@ -1,6 +1,6 @@ module.exports = { event: 'ready', - execute: client => { - client.log.success(`Connected to Discord as ${client.user.tag}`); + execute: (client) => { + client.log.success(`Connected to Discord as "${client.user.tag}"`); } }; \ No newline at end of file diff --git a/src/modules/listeners.js b/src/modules/listeners.js index f53474f..d68fdb8 100644 --- a/src/modules/listeners.js +++ b/src/modules/listeners.js @@ -7,7 +7,6 @@ module.exports = client => { for (const file of files) { const listener = require(`../listeners/${file}`); - // client.on(listener.event, ...args => listener.execute(client, ...args)); - client.on(listener.event, args => listener.execute(client, args)); + client.on(listener.event, (...args) => listener.execute(client, ...args)); } }; \ No newline at end of file diff --git a/src/modules/plugins.js b/src/modules/plugins.js index fa16356..d16164e 100644 --- a/src/modules/plugins.js +++ b/src/modules/plugins.js @@ -1,35 +1,14 @@ -const yarpm = require('yarpm'); -const fs = require('fs'); -const { join } = require('path'); -const { path } = require('../utils/fs'); - module.exports = async client => { - const plugins = {}; - const dirs = fs.readdirSync(path('./user/plugins')); - - for (const dir of dirs) { - let package_path = path(`./user/plugins/${dir}/package.json`); - if (!fs.existsSync(package_path)) continue; - - let package = require(`../../user/plugins/${dir}/package.json`); - let main = require(join(`../../user/plugins/${dir}/`, package.main)); - - plugins[package.name] = package; - client.log.plugins(`Loading ${package.name} v${package.version} by ${package.author}`); - - if (package.dependencies && Object.keys(package.dependencies).length >= 1) { - client.log.plugins(`Installing dependencies for ${package.name}`); - let deps = Object.keys(package.dependencies) - .map(d => `${d}@${package.dependencies[d]}`) - .join(' '); - - await yarpm(['install', '--no-save', deps], { - stdout: process.stdout - }); - await main(client); - } else { - await main(client); + client.config.plugins.forEach(plugin => { + try { + let package = require(`${plugin}/package.json`); + client.log.plugins(`Loading ${package.name} v${package.version} by ${package.author?.name || 'unknown'}`); + require(plugin)(client); + } catch (e) { + client.log.warn(`An error occurred whilst loading ${plugin}, have you installed it?`); + client.log.error(e); + return process.exit(); } - - } + }); + }; \ No newline at end of file diff --git a/user/example.config.js b/user/example.config.js index 635b097..d23db19 100644 --- a/user/example.config.js +++ b/user/example.config.js @@ -23,6 +23,19 @@ */ module.exports = { + debug: false, + defaults: { + colour: '#009999', + locale: 'en-GB' + }, + logs: { + enabled: true, + keep_for: 30 + }, + plugins: [ + // 'dsctickets.plugin-name' + 'discordtickets-portal' + ], portal: { enabled: false, host: 'https://tickets.example.com' @@ -41,14 +54,5 @@ module.exports = { type: 'WATCHING' }, ], - defaults: { - colour: '#009999', - locale: 'en-GB' - }, - logs: { - enabled: true, - keep_for: 30 - }, - debug: false, update_notice: true, }; \ No newline at end of file