mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-18 23:01:38 +01:00
65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
import { changeItemCount, Item } from "items";
|
|
import { sendMessage } from "commands";
|
|
import { createTimeoutRecord } from "db/dbTimeouts";
|
|
import { createUsedItemRecord } from "db/dbUsedItems";
|
|
import { getUserRecord } from "db/dbUser";
|
|
import parseCommandArgs from "lib/parseCommandArgs";
|
|
import { timeout } from "lib/timeout";
|
|
import { playAlert } from "web/alerts/serverFunctions";
|
|
import User from "user";
|
|
|
|
const ITEMNAME = 'silverbullet';
|
|
|
|
export default new Item({
|
|
name: ITEMNAME,
|
|
prettyName: 'Silver bullet',
|
|
plural: 's',
|
|
description: 'Times a specific person out for 30 minutes',
|
|
aliases: ['execute', 'silverbullet'],
|
|
specialaliases: ['blastin'],
|
|
price: 666,
|
|
execution: async (msg, user, specialargs) => {
|
|
const messagequery = parseCommandArgs(msg.messageText, specialargs?.activation);
|
|
if (!messagequery[0]) { await sendMessage('Please specify a target'); return; };
|
|
const target = await User.initUsername(messagequery[0].toLowerCase());
|
|
if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; };
|
|
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();
|
|
|
|
const userObj = await getUserRecord(user);
|
|
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any silver bullets!`, msg.messageId); await user.clearLock(); return; };
|
|
|
|
const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60 * 30);
|
|
if (result.status) await Promise.all([
|
|
sendMessage(`${target.displayName} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`),
|
|
changeItemCount(user, userObj, ITEMNAME),
|
|
createTimeoutRecord(user, target, ITEMNAME),
|
|
createUsedItemRecord(user, ITEMNAME),
|
|
playAlert({
|
|
name: 'userExecution',
|
|
user: user.displayName,
|
|
target: target.displayName
|
|
})
|
|
]);
|
|
else {
|
|
switch (result.reason) {
|
|
case "banned":
|
|
await sendMessage(`${target.displayName} is already timed out/banned`, msg.messageId);
|
|
break;
|
|
case "illegal":
|
|
await Promise.all([
|
|
sendMessage(`${user.displayName} Nou Nou Nou`),
|
|
timeout(user, 'nah', 60)
|
|
]);
|
|
break;
|
|
case "unknown":
|
|
await sendMessage('Something went wrong...', msg.messageId);
|
|
break;
|
|
};
|
|
};
|
|
await user.clearLock();
|
|
}
|
|
});
|