sync changes

This commit is contained in:
Emily 2020-10-20 19:30:46 +11:00
parent ee5de0ccaa
commit 4769669d12
6 changed files with 123 additions and 64 deletions

View file

@ -0,0 +1,12 @@
class Ready {
constructor () {
this.wsEvent;
}
async run (client) {
client.editStatus('online', { name: `Goddess of Discord! | v${client.version}`});
client.logger.event(`Woomy v${client.version} initialized and ready to accept commands!`);
}
}
module.exports = new Ready();

View file

@ -2,14 +2,16 @@
const Eris = require('eris-additions')(require('eris'));
const EventHandler = require('./util/handlers/eventHandler');
const messageHandler = require('./util/handlers/messageHandler');
// const messageHandler = require('./util/handlers/messageHandler');
const Helpers = require('./util/helpers');
const Database = require('./util/database');
const Logger = require('./util/logger');
const read = require('fs-readdir-recursive');
const sentry = require('@sentry/node');
const config = require('../botconfig.yml');
const pkg = require('../package.json');
const fs = require('fs');
const read = require('fs-readdir-recursive');
const yaml = require('js-yaml');
const config = yaml.safeLoad(fs.readFileSync('../botconfig.yml', 'utf8'));
const version = require('../package.json').version;
class WoomyClient extends Eris.Client {
constructor (token, options) {
@ -17,13 +19,15 @@ class WoomyClient extends Eris.Client {
this.config = config;
this.path = __dirname;
this.version = pkg.version;
this.version = version;
this.commandFiles = read('./commands').filter(file => file.endsWith('.js'));
this.eventFiles = read('./event_modules').filter(file => file.endsWith('.js'));
this.logger = Logger;
//this.helpers = new Helpers(this);
this.db = new Database(this);
this.helpers = new Helpers(this);
this.eventHandler = new EventHandler(this);
// this.messageHandler = new messageHandler(this);
this.commands = new Eris.Collection();
this.aliases = new Eris.Collection();
@ -47,61 +51,79 @@ class WoomyClient extends Eris.Client {
this.aliases.set(alias, props.help.name);
});
} catch (error) {
this.logger.error('COMMAND_LOADER', error);
this.logger.error('COMMAND_LOADER_ERROR', error);
}
}
this.logger.success('COMMAND_LOADER', `Successfully loaded ${this.commands.size}/${this.commandFiles.length} commands.`);
this.logger.success('COMMAND_LOADER_SUCCESS', `Loaded ${this.commands.size}/${this.commandFiles.length} commands.`);
}
loadEventModules () {
const nameRegexp = /[^/]*$/;
const catRegexp = /.+?(?=\/)/;
for (const file of this.eventFiles) {
try {
const event = require(this.path + '/event_modules/' + file)(this);
const event = require(this.path + '/event_modules/' + file);
event.wsEvent = catRegexp.exec(file);
this.eventModules.set(nameRegexp.exec(file), event);
} catch (error) {
this.logger.error('EVENT_LOADER', error);
this.logger.error('EVENT_LOADER_ERROR', error);
}
}
this.logger.success('EVENT_LOADER', `Successfully loaded ${this.eventModules.size}/${this.eventFiles.length} event modules.`);
this.logger.success('EVENT_LOADER_SUCCESS', `Loaded ${this.eventModules.size}/${this.eventFiles.length} event modules.`);
}
mainEventListener (wsEvent, message, other) {
mainEventListener (wsEvent, param_1, param_2) {
try {
this.eventHandler.handle(wsEvent, param_1, param_2);
} catch (error) {
this.logger.error('MODULE_LISTENER_ERROR', error);
}
}
runReadyEvents () {
runReadyModules () {
this.mainEventListener('ready');
}
runErrorEvents (error) {
this.mainEventListener('error', null, error);
runErrorModules (error) {
this.mainEventListener('error', error);
}
runGuildCreateEvents (guild) {
this.mainEventListener('guildCreate', null, guild);
runMessageCreateModules (message) {
this.mainEventListener('messageCreate', message);
}
runGuildDeleteEvents (guild) {
this.mainEventListener('guildDelete', null, guild);
runGuildCreateModules (guild) {
this.mainEventListener('guildCreate', guild);
}
runGuildMemberAddEvents () {
runGuildDeleteModules (guild) {
this.mainEventListener('guildDelete', guild);
}
runGuildMemberAddModules (guild, member) {
this.mainEventListener('guildMemberAdd', guild, member);
}
runGuildMemberRemoveModules (guild, member) {
this.mainEventListener('guildMemberRemove', guild, member);
}
runVoiceStateUpdateModules (oldState, newState) {
this.mainEventListener('voiceStateUpdate', oldState, newState);
}
createEventListeners () {
this.on('ready', );
this.on('error')
this.on('messageCreate', this.mainEventLIstener('message', message));
this.on('guildCreate', );
this.on('guildDelete', );
this.on('guildMemberAdd', );
this.on('guildMemberRemove', );
this.on('voiceStateUpdate', );
this.on('ready', this.runReadyModules);
this.on('error', this.runErrorModules);
this.on('messageCreate', this.runMessageCreateModules);
this.on('guildCreate', this.runGuildCreateModules);
this.on('guildDelete', this.runGuildDeleteModules);
this.on('guildMemberAdd', this.runGuildMemberAddModules);
this.on('guildMemberRemove', this.runGuildMemberRemoveModules);
this.on('voiceStateUpdate', this.runVoiceStateUpdateModules);
}
}
@ -131,11 +153,13 @@ async function init () {
try {
// sentry.init({ dsn: client.config.keys.sentry });
} catch (err) {
client.logger.error('SENTRY', `Sentry failed to start: ${err}`);
client.logger.error('SENTRY_INIT_ERROR', `Sentry failed to initialize: ${err}`);
}
} else {
client.logger.warning('DEVMODE', 'Running in development mode, some features have been disabled.');
client.logger.warning('DEVELOPMENT_MODE', 'Running in development mode, some features have been disabled.');
}
client.connect();
}
init ();

View file

@ -1,46 +1,67 @@
/* eslint-disable indent */
class EventHandler {
constructor (client) {
this.client = client;
}
ready () {
const readyModules = this.client.eventModules.filter(module => module.wsEvent = 'ready');
readyModules.forEach(module => module.execute(this.client));
}
handle (wsEvent, param_1, param_2) {
switch (wsEvent) {
case 'ready': {
const readyModules = this.client.eventModules.filter(module => module.wsEvent === 'ready');
readyModules.forEach(module => module.run(this.client));
break;
}
error () {
const errorModules = this.client.eventModules.filter(module => module.wsEvent = 'error');
errorModules.forEach(module => module.execute(this.client));
}
// param_1 - error message
case 'error': {
const errorModules = this.client.eventModules.filter(module => module.wsEvent === 'error');
errorModules.forEach(module => module.run(this.client, param_1));
break;
}
messageCreate () {
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent = 'messageCreate');
mCreateModules.forEach(module => module.execute(this.client));
}
// param_1 - message object
case 'messageCreate': {
const mCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'messageCreate');
mCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
guildCreate () {
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent = 'guildCreate');
gCreateModules.forEach(module => module.execute(this.client));
}
// param_1 - guild object
case 'guildCreate': {
const gCreateModules = this.client.eventModules.filter(module => module.wsEvent === 'guildCreate');
gCreateModules.forEach(module => module.run(this.client, param_1));
break;
}
guildDelete () {
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent = 'guildDelete');
gDeleteModules.forEach(module => module.execute(this.client));
}
// param_1 - guild object
case 'guildDelete': {
const gDeleteModules = this.client.eventModules.filter(module => module.wsEvent === 'guildDelete');
gDeleteModules.forEach(module => module.run(this.client, param_1));
break;
}
guildMemberAdd () {
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent = 'guildMemberAdd');
gMemberAddModules.forEach(module => module.execute(this.client));
}
// param_1 - guild object | param_2 - member object
case 'guildMemberAdd': {
const gMemberAddModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberAdd');
gMemberAddModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
guildMemberRemove () {
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent = 'guildMemberRemove');
gMemberRemoveModules.forEach(module => module.execute(this.client));
}
// param_1 - guild object | param_2 - member object
case 'guildMemberRemove': {
const gMemberRemoveModules = this.client.eventModules.filter(module => module.wsEvent === 'guildMemberRemove');
gMemberRemoveModules.forEach(module => module.run(this.client, param_1, param_2));
break;
}
voiceStateUpdate () {
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent = 'voiceStateUpdate');
vStateUpdateModules.forEach(module => module.execute(this.client));
// param_1 - old voice state | param_2 - new voice state
case 'voiceStateUpdate': {
const vStateUpdateModules = this.client.eventModules.filter(module => module.wsEvent === 'voiceStateUpdate');
vStateUpdateModules.forEach(module => module.run(this.client));
break;
}
}
}
}

View file

@ -1,4 +1,3 @@
const { MessageEmbed } = require('discord.js');
const { inspect, promisify } = require('util');
class Helpers {
@ -6,6 +5,7 @@ class Helpers {
this.client = client;
}
/* Rewrite for Eris
userError (channel, cmd, error) {
const embed = new MessageEmbed()
.setColor('#EF5350')
@ -16,6 +16,7 @@ class Helpers {
channel.send(embed);
}
*/
async getLastMessage (channel) {
const messages = await channel.messages.fetch({ limit: 2 });

View file

@ -77,7 +77,7 @@ class Logger {
* @returns {void}
*/
static event (body) {
console.log(chalk.bold.yellow(`[ ${this._getCurrentTime()} ] [ EVENT ] `) + body);
console.log(chalk.bold.blue(`[ ${this._getCurrentTime()} ] [ EVENT ] `) + body);
}
/**

View file

@ -10,6 +10,7 @@
"eris-additions": "^1.4.1",
"eslint": "^7.11.0",
"fs-readdir-recursive": "^1.1.0",
"js-yaml": "^3.14.0",
"pg": "^8.4.1",
"pg-format": "^1.0.4"
},