Make things work

This commit is contained in:
Isaac
2021-02-16 23:35:31 +00:00
parent 5fdfb121c7
commit 4c8e9125e5
8 changed files with 39 additions and 77 deletions

View File

@@ -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);

View File

@@ -1,8 +1,5 @@
module.exports = {
event: 'messageReactionAdd',
execute: (client, r, u) => {
client.log.info('messageReactionAdd');
console.log(r);
console.log(u);
}
};

View File

@@ -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}"`);
}
};

View File

@@ -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));
}
};

View File

@@ -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();
}
}
});
};