-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdaily.js
62 lines (53 loc) · 1.95 KB
/
daily.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const mongo = require('@root/database/mongo');
const userSchema = require('@schemas/userSchema');
const { Command } = require('discord.js-commando');
let claimedCache = [];
const clearCache = () => {
claimedCache = [];
setTimeout(clearCache, 20 * 60 * 1000);
};
module.exports = class DailyCommand extends Command {
constructor(client) {
super(client, {
name: 'daily',
group: 'fun',
memberName: 'daily',
description: 'get some fantastic daily rewards, coins, xp and what not?',
examples: ['daily'],
});
}
async run(message) {
const { guild, member } = message;
const { id } = member;
const obj = {
userId: id,
};
await mongo().then(async (mongoose) =>{
try{
const results = await userSchema.findOne(obj);
if(results){
const then = new Date(results.dailyclaimtimestamp).getTime();
const now = new Date().getTime();
const diffTime = Math.abs(now - then);
const diffDays = diffTime / (1000 * 60 * 60 * 24);
if (diffDays <= 1) {
claimedCache.push(id);
message.reply(`you have already claimed your **daily** rewards!`);
return;
}
}
var upd = {
userId : id,
dailyclaimtimestamp : new Date().getTime(),
}
await userSchema.findOneAndUpdate(obj,upd, { new: true, upsert: true });
// const coins = Math.floor(Math.random() * 500) + 500;
// await updateCoins(message.author.id, coins);
// const XP = Math.floor(Math.random() * 20) + 25;
// await updateXP(message.author.id, XP, message);
message.reply(`Daily Claimed`);
} finally{
}
})
}
};