Last active
May 2, 2018 07:51
-
-
Save appellation/5ba5b3acd262c65e6dd235044c2e71e5 to your computer and use it in GitHub Desktop.
basic redis points system
This file contains 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
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 | |
}); | |
} | |
}; |
This file contains 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
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); | |
} | |
}); |
This file contains 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
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