Skip to content

Instantly share code, notes, and snippets.

@appellation
Last active May 2, 2018 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appellation/5ba5b3acd262c65e6dd235044c2e71e5 to your computer and use it in GitHub Desktop.
Save appellation/5ba5b3acd262c65e6dd235044c2e71e5 to your computer and use it in GitHub Desktop.
basic redis points system
const { Client } = require('discord.js');
const Redis = require('ioredis');
module.exports = new class extends Client {
constructor() {
super({
// discord.js options
});
this.redis = new Redis({
// redis options
});
}
};
const { Structures } = require('discord.js');
const Points = require('./Points');
module.exports = Structures.extend('GuildMember', GuildMember => class extends GuildMember {
constructor(...args) {
super(...args);
this.points = new Points(this);
}
});
module.exports = class Points {
constructor(member) {
this.member = member;
this.key = `guilds.${this.member.id}.members.${this.id}`;
}
get _redis() {
return this.member.client.redis;
}
get() {
return this._redis.get(this.key);
}
incr(amt = 1) {
return this._redis.incrby(this.key, amt);
}
// etc.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment