Error handling and Guild and Message Manager classes to come with a command manager and module hot reloader
This commit is contained in:
@@ -4,7 +4,7 @@ import {RateLimits} from './ratelimits'
|
||||
|
||||
export class Events extends RateLimits { // extends rate limits
|
||||
constructor() {
|
||||
super()
|
||||
super();
|
||||
}
|
||||
|
||||
async init(client) {
|
||||
@@ -22,6 +22,13 @@ export class Events extends RateLimits { // extends rate limits
|
||||
);
|
||||
});
|
||||
|
||||
this.client.on('error', async (err) => {
|
||||
this.handle(err,
|
||||
[this.handleError],
|
||||
this.client
|
||||
);
|
||||
});
|
||||
|
||||
this.client.on('message', async (message) => {
|
||||
this.handle(message,
|
||||
[super.request, this.handleMessage],
|
||||
@@ -30,6 +37,9 @@ export class Events extends RateLimits { // extends rate limits
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async handle(obj = [null], callbacks = [undefined], client) {
|
||||
let doNext = false;
|
||||
if (callbacks.length == 0) {
|
||||
@@ -56,9 +66,14 @@ export class Events extends RateLimits { // extends rate limits
|
||||
next();
|
||||
}
|
||||
|
||||
async handleMessage(obj, client, next) {
|
||||
if (client.user.id == obj.author.id) return;
|
||||
if (obj.limiting) obj.channel.send(`${obj.author} You are being rate limited`);
|
||||
async handleError(err, client, next) {
|
||||
Logger.error(`An error occured with the Discord API: ${err}`);
|
||||
next();
|
||||
}
|
||||
|
||||
async handleMessage(message, client, next) {
|
||||
if (client.user.id == message.author.id) return;
|
||||
if (message.limiting) message.channel.send(`${message.author} You are being rate limited`);
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
9
src/guildmanager.js
Normal file
9
src/guildmanager.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import {Logger} from './logger';
|
||||
|
||||
export class GuildManager {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
5
src/messagemanager.js
Normal file
5
src/messagemanager.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import {Logger} from './logger';
|
||||
|
||||
export class MessageManager {
|
||||
|
||||
}
|
||||
@@ -11,10 +11,10 @@ export class RateLimits {
|
||||
|
||||
async request(obj, client, next) {
|
||||
let id = obj.author.id;
|
||||
if (id == client.user.id) { return; }
|
||||
if (id == client.user.id) return;
|
||||
|
||||
if (!buckets[id]) {
|
||||
Logger.debug(`New rate limiting bucket`);
|
||||
Logger.debug(`New rate limiting bucket for ${id}`);
|
||||
|
||||
buckets[id] = {id: id, tokens: [], lastUsed: new Date().getTime()};
|
||||
for (let i = 0; i < requestsPerSecond; i++) {
|
||||
@@ -27,7 +27,6 @@ export class RateLimits {
|
||||
|
||||
buckets[id].lastUsed = new Date().getTime();
|
||||
|
||||
Logger.debug(buckets[id].tokens.length);
|
||||
if (buckets[id].tokens.length <= 0) {
|
||||
Logger.middleware(`${id} is being rate limited`);
|
||||
obj.limiting = true;
|
||||
|
||||
Reference in New Issue
Block a user