mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 12:21:38 +01:00
major reworks, prefixless commands added
This commit is contained in:
@@ -7,71 +7,76 @@ import { timeout } from "lib/timeout";
|
||||
|
||||
const COOLDOWN = 10 * 60 * 1000; // 10 mins (ms)
|
||||
|
||||
export default new Command('getloot', ['getloot', 'dig', 'loot'], 'chatter', async (msg, user) => {
|
||||
if (!await redis.exists('streamIsLive')) { await sendMessage(`No loot while stream is offline`, msg.messageId); return; };
|
||||
if (await user.itemLock()) { await sendMessage(`Cannot get loot (itemlock)`, msg.messageId); return; };
|
||||
const userData = await getUserRecord(user);
|
||||
const lastlootbox = Date.parse(userData.lastlootbox);
|
||||
const now = Date.now();
|
||||
if ((lastlootbox + COOLDOWN) > now) {
|
||||
if (await user.greedy()) {
|
||||
await Promise.all([
|
||||
sendMessage(`${user.displayName} STOP BEING GREEDY!!! UltraMad UltraMad UltraMad`),
|
||||
timeout(user, `Wait ${buildTimeString(now - COOLDOWN, lastlootbox)}`, 60)
|
||||
]);
|
||||
return;
|
||||
} else {
|
||||
await Promise.all([
|
||||
user.setGreed(),
|
||||
sendMessage(`Wait ${buildTimeString(now - COOLDOWN, lastlootbox)} for another lootbox.`, msg.messageId)
|
||||
]);
|
||||
return;
|
||||
export default new Command({
|
||||
name: 'getloot',
|
||||
aliases: ['getloot', 'dig', 'loot'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
if (!await redis.exists('streamIsLive')) { await sendMessage(`No loot while stream is offline`, msg.messageId); return; };
|
||||
if (await user.itemLock()) { await sendMessage(`Cannot get loot (itemlock)`, msg.messageId); return; };
|
||||
const userData = await getUserRecord(user);
|
||||
const lastlootbox = Date.parse(userData.lastlootbox);
|
||||
const now = Date.now();
|
||||
if ((lastlootbox + COOLDOWN) > now) {
|
||||
if (await user.greedy()) {
|
||||
await Promise.all([
|
||||
sendMessage(`${user.displayName} STOP BEING GREEDY!!! UltraMad UltraMad UltraMad`),
|
||||
timeout(user, `Wait ${buildTimeString(now - COOLDOWN, lastlootbox)}`, 60)
|
||||
]);
|
||||
return;
|
||||
} else {
|
||||
await Promise.all([
|
||||
user.setGreed(),
|
||||
sendMessage(`Wait ${buildTimeString(now - COOLDOWN, lastlootbox)} for another lootbox.`, msg.messageId)
|
||||
]);
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
await user.clearGreed();
|
||||
await user.setLock();
|
||||
await user.clearGreed();
|
||||
await user.setLock();
|
||||
|
||||
userData.lastlootbox = new Date(now).toISOString();
|
||||
userData.lastlootbox = new Date(now).toISOString();
|
||||
|
||||
const gainedqbucks = Math.floor(Math.random() * 100) + 50; // range from 50 to 150
|
||||
userData.balance += gainedqbucks;
|
||||
const gainedqbucks = Math.floor(Math.random() * 100) + 50; // range from 50 to 150
|
||||
userData.balance += gainedqbucks;
|
||||
|
||||
const itemDiff = {
|
||||
grenade: 0,
|
||||
blaster: 0,
|
||||
tnt: 0,
|
||||
silverbullet: 0
|
||||
};
|
||||
const itemDiff = {
|
||||
grenade: 0,
|
||||
blaster: 0,
|
||||
tnt: 0,
|
||||
silverbullet: 0
|
||||
};
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade += 1;
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster += 1;
|
||||
if (Math.floor(Math.random() * 25) === 0) itemDiff.tnt += 1;
|
||||
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet += 1;
|
||||
};
|
||||
for (let i = 0; i < 5; i++) {
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade += 1;
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster += 1;
|
||||
if (Math.floor(Math.random() * 25) === 0) itemDiff.tnt += 1;
|
||||
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet += 1;
|
||||
};
|
||||
|
||||
for (const [item, amount] of Object.entries(itemDiff)) {
|
||||
if (userData.inventory[item]) userData.inventory[item] += amount;
|
||||
else userData.inventory[item] = amount;
|
||||
};
|
||||
for (const [item, amount] of Object.entries(itemDiff)) {
|
||||
if (userData.inventory[item]) userData.inventory[item] += amount;
|
||||
else userData.inventory[item] = amount;
|
||||
};
|
||||
|
||||
const itemstrings: string[] = [`${gainedqbucks} qbucks`];
|
||||
const itemstrings: string[] = [`${gainedqbucks} qbucks`];
|
||||
|
||||
for (const [item, amount] of Object.entries(itemDiff)) {
|
||||
if (amount === 0) continue;
|
||||
const selection = items.get(item);
|
||||
if (!selection) continue;
|
||||
itemstrings.push(`${amount} ${selection.prettyName + (amount === 1 ? '' : selection.plural)}`);
|
||||
};
|
||||
for (const [item, amount] of Object.entries(itemDiff)) {
|
||||
if (amount === 0) continue;
|
||||
const selection = items.get(item);
|
||||
if (!selection) continue;
|
||||
itemstrings.push(`${amount} ${selection.prettyName + (amount === 1 ? '' : selection.plural)}`);
|
||||
};
|
||||
|
||||
const last = itemstrings.pop();
|
||||
const itemstring = itemstrings.length === 0 ? last : itemstrings.join(', ') + " and " + last;
|
||||
const message = `You got ${itemstring}`;
|
||||
const last = itemstrings.pop();
|
||||
const itemstring = itemstrings.length === 0 ? last : itemstrings.join(', ') + " and " + last;
|
||||
const message = `You got ${itemstring}`;
|
||||
|
||||
await Promise.all([
|
||||
updateUserRecord(user, userData),
|
||||
sendMessage(message, msg.messageId),
|
||||
user.clearLock()
|
||||
]);
|
||||
await Promise.all([
|
||||
updateUserRecord(user, userData),
|
||||
sendMessage(message, msg.messageId),
|
||||
user.clearLock()
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user