-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlottery.js
71 lines (52 loc) · 2.17 KB
/
lottery.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
69
70
71
/* eslint-disable no-unused-vars */
const Handler = require("./mongo/handler");
const caller = "lottery"
const handler = new Handler(caller)
const User = require('./mongo/users')
const emotes = {
"cookie": "<:Cookie:970644679353831424>",
"giveCookie": "<a:GiveCookieR:971740550845853696>"
}
module.exports = async (m) => {
//this module is called from index.js at the the function at ~83
const msgAuthorID = m.author.id
const userData = await handler.fetchData(msgAuthorID)
const mTime = Math.floor(m.createdTimestamp / 1000)
// console.log(await userData)
// console.log(`message at ${messageTimestamp} and last reward at ${lastRewarded}`)
let lastRewarded = await userData.lastReward || 0
let isBanned = await userData.isBanned || false
function prizeAmount() {
let p = Math.floor(Math.random() * 10) + 1;
console.log(`giving the mf ${p}`)
return p;
}
getsPrize() // no subroutines??? megamind face
async function getsPrize() {
const r1 = Math.floor(Math.random() * 100) + 1;
//generates a number between 1 & 100
console.log(r1)
//console.log(userIsBanned)
console.log("message", mTime, "lastRew", lastRewarded, "delta", `${mTime - lastRewarded}`)
if (r1 >= 99) {
if ((mTime - lastRewarded > 400) && (isBanned === false)) { //can only be rewarded every 20 seconds
//wins amounts of cookies that should be decided in the other function
const num = prizeAmount()
console.log(msgAuthorID)
m.reply(`YOU WON ${num} COOKIES ${emotes.cookie} !`)
handler.addBal(msgAuthorID, num).then(async () => { // give the money and make sure
try {
await User.findOneAndUpdate({
userID: msgAuthorID
}, {
// then update the last time they got rewarded
lastReward: mTime
})
} catch (error) {
console.log(error)
}
})
}
}
}
}