mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
move lootbox cooldown to redis because of timezone garbage
This commit is contained in:
@@ -7,8 +7,9 @@ import { timeout } from "lib/timeout";
|
||||
import { isInvuln, removeInvuln } from "lib/invuln";
|
||||
import { streamerUsers } from "main";
|
||||
import { createGetLootRecord } from "db/dbGetLoot";
|
||||
import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
const COOLDOWN = 10 * 60 * 1000; // 10 mins (ms)
|
||||
const COOLDOWN = 10 * 60; // 10 mins (s)
|
||||
|
||||
export default new Command({
|
||||
name: 'getloot',
|
||||
@@ -20,20 +21,19 @@ export default new Command({
|
||||
if (await user.itemLock()) { await sendMessage(`Cannot get loot (itemlock)`, msg.messageId); return; };
|
||||
await user.setLock();
|
||||
const userData = await getUserRecord(user);
|
||||
const lastlootbox = userData.lastlootbox.getTime();
|
||||
const now = Date.now();
|
||||
if ((lastlootbox + COOLDOWN) > now) {
|
||||
const timeData = await redis.expiretime(`user:${user.id}:lootboxcooldown`) * 1000;
|
||||
if ((timeData) > Date.now()) {
|
||||
await user.clearLock();
|
||||
if (await user.greedy()) {
|
||||
await Promise.all([
|
||||
sendMessage(`${user.displayName} STOP BEING GREEDY!!! UltraMad UltraMad UltraMad`),
|
||||
timeout(user, `Wait ${buildTimeString(now - COOLDOWN, lastlootbox)}`, 60)
|
||||
timeout(user, `Wait ${buildTimeString(timeData, Date.now())} for another lootbox`, 60)
|
||||
]);
|
||||
return;
|
||||
} else {
|
||||
await Promise.all([
|
||||
user.setGreed(),
|
||||
sendMessage(`Wait ${buildTimeString(now - COOLDOWN, lastlootbox)} for another lootbox.`, msg.messageId)
|
||||
sendMessage(`Wait ${buildTimeString(timeData, Date.now())} for another lootbox.`, msg.messageId)
|
||||
]);
|
||||
return;
|
||||
};
|
||||
@@ -41,8 +41,23 @@ export default new Command({
|
||||
|
||||
await user.clearGreed();
|
||||
|
||||
userData.lastlootbox = new Date(now);
|
||||
await redis.set(`user:${user.id}:lootboxcooldown`, '1');
|
||||
await redis.expire(`user:${user.id}:lootboxcooldown`, COOLDOWN);
|
||||
|
||||
if (!await redis.exists(`user:${user.id}:subbed`) && Math.random() < 0.1) {
|
||||
await Promise.all([
|
||||
user.clearLock(),
|
||||
updateUserRecord(user, userData),
|
||||
timeout(user, "THE LOOTBOX WAS TRAPPED!!!", 60),
|
||||
sendMessage(`wybuh wybuh ${user.displayName.toUpperCase()} FOUND A TRAPPED LOOTBOX!!! wybuh wybuh`),
|
||||
playAlert({
|
||||
name: 'grenadeExplosion',
|
||||
user: 'trapped lootbox',
|
||||
target: user.displayName
|
||||
})
|
||||
]);
|
||||
return;
|
||||
};
|
||||
const gainedqbucks = Math.floor(Math.random() * 100) + 50; // range from 50 to 150
|
||||
userData.balance += gainedqbucks;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user