Created
February 18, 2020 16:43
-
-
Save ha6000/4c02c90bdfc5fe4a63ddd33b149d4d71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Harry Kruger | |
* @copyright 2020 Harry Kruger | |
*/ | |
// todo: add auto config | |
const dotenv = require('dotenv'); | |
// the default client options | |
const clientOptionsDefaults = { | |
token: undefined, | |
logChannel: undefined | |
}; | |
// error for when a log channel is provided that isent found. | |
class missingLogChannelError extends Error { | |
constructor() { | |
super('Log Channel not found.'); | |
this.name = 'missingLogChannel'; | |
}; | |
}; | |
const colors = { | |
green: 0x84ed47 | |
} | |
module.exports = { | |
Handler: class Handler | |
{ | |
/** | |
* Cool class | |
* @param Discord The discord module | |
*/ | |
constructor(Discord) { | |
if (Discord == undefined) { | |
Discord = require('discord.js'); | |
}; | |
this.Discord = Discord; | |
// the embed for when the bot is ready | |
const logChannelReadyEmbed = new this.Discord.RichEmbed({ | |
title: 'Bot Ready', | |
color: colors.green | |
}) | |
class Client extends Discord.Client { | |
/** | |
* Nice class | |
* @param opts {ClientOptions} The options for the Client | |
*/ | |
constructor(opts) { | |
super(); | |
// sets unset values to defaults | |
this.opts = clientOptionsDefaults; | |
this.opts = Object.assign(this.opts, opts); | |
// checks if a token is provided | |
if (opts.token) { | |
this.on('ready', () => { | |
console.log(`${this.user.username} is ready`); | |
// checks if log channel is a option | |
if (opts.logChannel) { | |
// gets the log channel | |
const logChannel = this.channels.get(opts.logChannel.toString()); | |
// checks if its a valid log channel | |
if (logChannel) { | |
logChannelReadyEmbed.setDescription(`${this.user.username} is ready.`); | |
} else { | |
throw new missingLogChannelError(); | |
}; | |
} | |
}); | |
this.login(this.opts.token); | |
}; | |
}; | |
} | |
this.Discord.Client = Client; | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment