mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 09:46:57 +01:00
proper formatting and linting YAY, change cheer constructor to take object
This commit is contained in:
@@ -1,48 +1,60 @@
|
||||
import { redis } from "lib/redis";
|
||||
import { sendMessage } from "lib/commandUtils";
|
||||
import { timeout } from "lib/timeout";
|
||||
import { changeItemCount, Item } from "items";
|
||||
import User from "user";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import { createTimeoutRecord } from "db/dbTimeouts";
|
||||
import { createUsedItemRecord } from "db/dbUsedItems";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import { changeItemCount, Item } from "items";
|
||||
import { sendMessage } from "lib/commandUtils";
|
||||
import { redis } from "lib/redis";
|
||||
import { timeout } from "lib/timeout";
|
||||
import User from "user";
|
||||
import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
const ITEMNAME = 'grenade';
|
||||
const ITEMNAME = "grenade";
|
||||
|
||||
export default new Item({
|
||||
name: ITEMNAME,
|
||||
prettyName: 'Grenade',
|
||||
plural: 's',
|
||||
description: 'Give a random chatter a 60s timeout',
|
||||
aliases: ['grenade'],
|
||||
price: 99,
|
||||
execution: async (msg, user) => {
|
||||
const targets = await redis.keys(`user:*:vulnerable`);
|
||||
if (targets.length === 0) { await sendMessage('No vulnerable chatters to blow up', msg.messageId); return; };
|
||||
const selection = targets[Math.floor(Math.random() * targets.length)]!;
|
||||
const target = await User.initUserId(selection.slice(5, -11));
|
||||
name: ITEMNAME,
|
||||
prettyName: "Grenade",
|
||||
plural: "s",
|
||||
description: "Give a random chatter a 60s timeout",
|
||||
aliases: ["grenade"],
|
||||
price: 99,
|
||||
execution: async (msg, user) => {
|
||||
const targets = await redis.keys(`user:*:vulnerable`);
|
||||
if (targets.length === 0) {
|
||||
await sendMessage("No vulnerable chatters to blow up", msg.messageId);
|
||||
return;
|
||||
}
|
||||
const selection = targets[Math.floor(Math.random() * targets.length)]!;
|
||||
const target = await User.initUserId(selection.slice(5, -11));
|
||||
|
||||
await getUserRecord(target!); // make sure the user record exist in the database
|
||||
await getUserRecord(target!); // make sure the user record exist in the database
|
||||
|
||||
if (await user.itemLock()) { await sendMessage('Cannot use an item (itemlock)', msg.messageId); return; };
|
||||
await user.setLock();
|
||||
if (await user.itemLock()) {
|
||||
await sendMessage("Cannot use an item (itemlock)", msg.messageId);
|
||||
return;
|
||||
}
|
||||
await user.setLock();
|
||||
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any grenades!`, msg.messageId); await user.clearLock(); return; };
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) {
|
||||
await sendMessage(`You don't have any grenades!`, msg.messageId);
|
||||
await user.clearLock();
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
timeout(target!, `You got hit by ${user.displayName}'s grenade!`, 60),
|
||||
sendMessage(`wybuh ${target?.displayName} got hit by ${user.displayName}'s grenade wybuh`),
|
||||
changeItemCount(user, userObj, ITEMNAME),
|
||||
createTimeoutRecord(user, target!, ITEMNAME),
|
||||
createUsedItemRecord(user, ITEMNAME),
|
||||
playAlert({
|
||||
name: 'grenadeExplosion',
|
||||
user: user.displayName,
|
||||
target: target?.displayName!
|
||||
})
|
||||
]);
|
||||
await user.clearLock();
|
||||
}
|
||||
await Promise.all([
|
||||
timeout(target!, `You got hit by ${user.displayName}'s grenade!`, 60),
|
||||
sendMessage(
|
||||
`wybuh ${target?.displayName} got hit by ${user.displayName}'s grenade wybuh`,
|
||||
),
|
||||
changeItemCount(user, userObj, ITEMNAME),
|
||||
createTimeoutRecord(user, target!, ITEMNAME),
|
||||
createUsedItemRecord(user, ITEMNAME),
|
||||
playAlert({
|
||||
name: "grenadeExplosion",
|
||||
user: user.displayName,
|
||||
target: target?.displayName!,
|
||||
}),
|
||||
]);
|
||||
await user.clearLock();
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user