This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_daily.js
68 lines (65 loc) · 2.25 KB
/
cmd_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
63
64
65
66
67
68
var fs = require('fs')
function convertMS(ms) {
var d, h, m, s;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24; //
h += d * 24; //shut up stackoverflow is not skid
return h + ' hours ' + m + ' minutes and ' + s + ' seconds';
}
module.exports = function(msg, bot, args) {
var daily = 1337;
var randomNumber = 0;
global.coins = JSON.parse(fs.readFileSync("./coins.json", "utf8"))
if (!global.coins[msg.author.id]) {
daily = Math.floor(Math.random() * 123) + 55
global.coins[msg.author.id] = {
cookies: 0,
lastdaily: 9999,
lasthourly: 9999
}
console.log("db thing owo")
fs.writeFile("./coins.json", JSON.stringify(global.coins), (err) => {
if (err) {
console.log(err)
}
})
} else {
randomNumber = Math.floor(Math.random() * 123) + 55
daily = global.coins[msg.author.id].cookies + randomNumber
}
if (new Date() - new Date(global.coins[msg.author.id].lastdaily) > 86400000) {
global.coins[msg.author.id] = {
cookies: daily,
lastdaily: new Date(),
lasthourly: global.coins[msg.author.id].lasthourly
}
fs.writeFile("./coins.json", JSON.stringify(global.coins), (err) => {
if (err) {
console.log(err)
}
})
var totalcookies = daily - global.coins[msg.author.id].cookies
const dailyembed = {
"embed": {
"title": "You earned " + randomNumber + " cookies! :cookie:",
"description": "Yay! :cookie:",
"color": 10211145,
"timestamp": new Date(),
"footer": {
"text": "~daily"
}
}
};
msg.channel.createMessage(dailyembed)
} else {
var datething = new Date(global.coins[msg.author.id].lastdaily);
var seconddatething = new Date();
var fuckjimbo = 86400000 - (seconddatething.getTime() - datething.getTime());
msg.channel.createMessage("Wait! Your turn is in " + convertMS(fuckjimbo)) //SHOULD BE HOURS
}
}