redis stuff
This commit is contained in:
parent
0d8878ed37
commit
68b467ac71
2 changed files with 77 additions and 21 deletions
59
bot/index.js
59
bot/index.js
|
@ -13,17 +13,19 @@ class Custom extends Client {
|
||||||
constructor (options) {
|
constructor (options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
this.path = __dirname;
|
|
||||||
this.config = require("../config.json");
|
this.config = require("../config.json");
|
||||||
|
this.dev = true;
|
||||||
|
if (this.config.devmode === false) {
|
||||||
|
this.dev = false;
|
||||||
|
//sentry.init({ dsn: this.config.keys.sentry });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.path = __dirname;
|
||||||
this.logger = require("./util/logger");
|
this.logger = require("./util/logger");
|
||||||
this.util = new (require("./util/util"))(this);
|
this.util = new (require("./util/util"))(this);
|
||||||
this.messageUtil = new (require("./util/messageUtil"))(this);
|
this.messageUtil = new (require("./util/messageUtil"))(this);
|
||||||
this.dev = false;
|
this.db = new (require("./util/redis"))(this)
|
||||||
|
|
||||||
if (this.config.devmode === true) {
|
|
||||||
this.dev = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create collections to store loaded commands and aliases in
|
// Create collections to store loaded commands and aliases in
|
||||||
this.commands = new Collection();
|
this.commands = new Collection();
|
||||||
this.aliases = new Collection();
|
this.aliases = new Collection();
|
||||||
|
@ -37,20 +39,35 @@ class Custom extends Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize client
|
// Initialization function, so we can use async/await
|
||||||
const client = new Custom();
|
const init = async () => {
|
||||||
/* Enable this later
|
// Initialize client
|
||||||
if (client.dev !== true) {
|
const client = new Custom();
|
||||||
sentry.init({ dsn: client.config.keys.sentry });
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
client.commandHandler.loadAll();
|
// Initialize Redis database
|
||||||
client.eventHandler.loadAll();
|
await client.db.init();
|
||||||
|
|
||||||
if (client.dev === true) {
|
await client.commandHandler.loadAll();
|
||||||
client.logger.warn("Development mode is on. Some features (such as Sentry) are disabled.");
|
await client.eventHandler.loadAll();
|
||||||
client.login(client.config.devtoken);
|
|
||||||
} else {
|
if (client.dev === true) {
|
||||||
client.login(client.config.token);
|
client.logger.warn("Development mode is on. Some features (such as Sentry) are disabled.");
|
||||||
|
client.login(client.config.devtoken);
|
||||||
|
} else {
|
||||||
|
client.login(client.config.token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
// Catch exceptions/rejections and give more details on the stack trace
|
||||||
|
process.on("uncaughtException", (err) => {
|
||||||
|
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, "g"), "./")
|
||||||
|
console.error("Uncaught Exception: ", errorMsg)
|
||||||
|
process.exit(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("unhandledRejection", err => {
|
||||||
|
console.error("Uncaught Promise Error: ", err)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
39
bot/util/redis.js
Normal file
39
bot/util/redis.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
const redis = require('redis')
|
||||||
|
const generators = require('redis-async-gen')
|
||||||
|
|
||||||
|
class Redis {
|
||||||
|
constructor(client) {
|
||||||
|
// 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) {
|
||||||
|
this.server.del(id)
|
||||||
|
var { keysMatching } = await generators.using(this.member)
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
for await (const key of keysMatching(id + '-*')) {
|
||||||
|
this.member.del(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deletes specified user and their member entries in guilds
|
||||||
|
this.deleteUser = async function (id) {
|
||||||
|
this.user.del(id)
|
||||||
|
var { keysMatching } = await generators.using(this.member)
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
for await (const key of keysMatching('*-' + id)) {
|
||||||
|
this.member.del(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deletes member of user in specified guild
|
||||||
|
this.deleteMember = async function (guildId, id) {
|
||||||
|
this.member.del(guildId + '-' + id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Redis
|
Loading…
Reference in a new issue