init function

This commit is contained in:
Emily 2020-08-19 18:21:23 +10:00
parent 68b467ac71
commit 6c61ec59a6
2 changed files with 29 additions and 23 deletions

View file

@ -44,12 +44,14 @@ const init = async () => {
// Initialize client
const client = new Custom();
// Initialize Redis database
await client.db.init();
// Load all commands/events
await client.commandHandler.loadAll();
await client.eventHandler.loadAll();
// Connect to Redis database
await client.db.init();
client.logger.info("Connected to Redis.")
if (client.dev === true) {
client.logger.warn("Development mode is on. Some features (such as Sentry) are disabled.");
client.login(client.config.devtoken);

View file

@ -3,14 +3,19 @@ const generators = require('redis-async-gen')
class Redis {
constructor(client) {
this.client = client;
}
init () {
// Create redis client
this.global = redis.createClient(this.client.config.redis)
this.server = this.global.duplicate({ db: 1 })
this.member = this.global.duplicate({ db: 2 })
this.user = this.global.duplicate({ db: 3 })
}
// Deletes specified guild entry
this.deleteGuild = async function (id) {
async deleteGuild (id) {
this.server.del(id)
var { keysMatching } = await generators.using(this.member)
// eslint-disable-next-line no-unused-vars
@ -20,7 +25,7 @@ class Redis {
}
// Deletes specified user and their member entries in guilds
this.deleteUser = async function (id) {
async deleteUser (id) {
this.user.del(id)
var { keysMatching } = await generators.using(this.member)
// eslint-disable-next-line no-unused-vars
@ -30,10 +35,9 @@ class Redis {
}
// Deletes member of user in specified guild
this.deleteMember = async function (guildId, id) {
async deleteMember (guildId, id) {
this.member.del(guildId + '-' + id)
}
}
}
module.exports = Redis