big refactor
This commit is contained in:
@@ -3,13 +3,10 @@ module.exports = {
|
||||
set: placeOnCooldown
|
||||
};
|
||||
|
||||
const memcache = require('memcache'),
|
||||
md5 = require('md5'),
|
||||
keyPrefix = 'cd';
|
||||
|
||||
const cache = new memcache.Client();
|
||||
cache.on('error', console.error);
|
||||
cache.connect();
|
||||
const NodeCache = require('node-cache');
|
||||
const cache = new NodeCache({checkperiod: 1});
|
||||
const md5 = require('md5');
|
||||
const keyPrefix = 'cd';
|
||||
|
||||
// Given a cooldownTime in seconds and a command, returns false if the command is not on cooldown
|
||||
// returns the time in seconds until the command will be ready again otherwise
|
||||
@@ -40,9 +37,9 @@ function isOnCooldown(command, cooldownTime, callback)
|
||||
function placeOnCooldown(command, cooldownTime)
|
||||
{
|
||||
let key = keyPrefix + md5(command);
|
||||
return cache.set(key, Date.now(), handleCacheSet, cooldownTime);
|
||||
return cache.set(key, Date.now(), cooldownTime, handleCacheSet);
|
||||
}
|
||||
|
||||
function handleCacheSet(error, result) {}
|
||||
|
||||
process.on('exit', (code) => {cache.close()});
|
||||
process.on('exit', (code) => {cache.close()});
|
||||
|
||||
Reference in New Issue
Block a user