added itemlock command, added TNT item, minor bugfixes

This commit is contained in:
2025-07-02 18:10:28 +02:00
parent ac3f81857f
commit a698cb25d5
11 changed files with 82 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ COMMAND|FUNCTION|USER|ALIASES|DISABLEABLE
`disablecommand {command/item}`|Disable a specific command/item|admins|`disablecommand`|:x: `disablecommand {command/item}`|Disable a specific command/item|admins|`disablecommand`|:x:
`enablecommand {command/item}`|Re-enable a specific command/item|admins|`enablecommand`|:x: `enablecommand {command/item}`|Re-enable a specific command/item|admins|`enablecommand`|:x:
`getadmins`|Get a list of every admin in the channel|anyone|`getadmins`|:x: `getadmins`|Get a list of every admin in the channel|anyone|`getadmins`|:x:
`itemlock {target}`|Toggle the itemlock on the specified target|admins|:x:
`addadmin {target}`|Adds an admin|streamer/botchatter|`addadmin`|:x: `addadmin {target}`|Adds an admin|streamer/botchatter|`addadmin`|:x:
`removeadmin {target}`|Removes an admin|streamer/botchatter|`removeadmin`|:x: `removeadmin {target}`|Removes an admin|streamer/botchatter|`removeadmin`|:x:

View File

@@ -13,7 +13,7 @@ export default new Command('admindonate', ['admindonate'], 'admin', async msg =>
if (!args[1]) { await sendMessage('Please specify the amount qweribucks you want to give', msg.messageId); return; }; if (!args[1]) { await sendMessage('Please specify the amount qweribucks you want to give', msg.messageId); return; };
const amount = Number(args[1]); const amount = Number(args[1]);
if (isNaN(amount)) { await sendMessage(`${args[1]} is not a valid amount`); return; }; if (isNaN(amount)) { await sendMessage(`${args[1]} is not a valid amount`); return; };
if (await target.itemLock()) { await sendMessage('Cannot give qweribucks: item transaction in progress', msg.messageId); return; }; if (await target.itemLock()) { await sendMessage('Cannot give qweribucks: item lock is set', msg.messageId); return; };
await target.setLock(); await target.setLock();
const data = await changeBalance(target, userRecord, amount); const data = await changeBalance(target, userRecord, amount);
if (!data) { if (!data) {

View File

@@ -16,7 +16,7 @@ export default new Command('admingive', ['admingive'], 'admin', async msg => {
if (!args[2]) { await sendMessage('Please specify the amount of the item you want to give', msg.messageId); return; }; if (!args[2]) { await sendMessage('Please specify the amount of the item you want to give', msg.messageId); return; };
const amount = Number(args[2]); const amount = Number(args[2]);
if (isNaN(amount)) { await sendMessage(`${args[2]} is not a valid amount`); return; }; if (isNaN(amount)) { await sendMessage(`${args[2]} is not a valid amount`); return; };
if (await target.itemLock()) { await sendMessage('Cannot give item: item transaction in progress', msg.messageId); return; }; if (await target.itemLock()) { await sendMessage('Cannot give item: item lock is set', msg.messageId); return; };
await target.setLock(); await target.setLock();
const data = await changeItemCount(target, userRecord, item.name, amount); const data = await changeItemCount(target, userRecord, item.name, amount);
if (data) { if (data) {

View File

@@ -10,6 +10,7 @@ export default new Command('donate', ['donate'], 'chatter', async (msg, user) =>
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; }; if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
const target = await User.initUsername(args[0].toLowerCase()); const target = await User.initUsername(args[0].toLowerCase());
if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; }; if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; };
if (target.username === user.username) { await sendMessage("You can't give yourself qweribucks", msg.messageId); return; };
const targetRecord = await getUserRecord(target); const targetRecord = await getUserRecord(target);
if (!args[1]) { await sendMessage('Please specify the amount of the item you want to give', msg.messageId); return; }; if (!args[1]) { await sendMessage('Please specify the amount of the item you want to give', msg.messageId); return; };
const amount = Number(args[1]); const amount = Number(args[1]);
@@ -18,7 +19,7 @@ export default new Command('donate', ['donate'], 'chatter', async (msg, user) =>
const userRecord = await getUserRecord(user); const userRecord = await getUserRecord(user);
if (userRecord.balance < amount) { await sendMessage(`You can't give qweribucks you don't have!`, msg.messageId); return; }; if (userRecord.balance < amount) { await sendMessage(`You can't give qweribucks you don't have!`, msg.messageId); return; };
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give qweribucks. Please try again!', msg.messageId); return; }; if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give qweribucks', msg.messageId); return; };
await Promise.all([ await Promise.all([
user.setLock(), user.setLock(),

View File

@@ -10,6 +10,7 @@ export default new Command('give', ['give'], 'chatter', async (msg, user) => {
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; }; if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
const target = await User.initUsername(args[0].toLowerCase()); const target = await User.initUsername(args[0].toLowerCase());
if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; }; if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; };
if (target.username === user.username) { await sendMessage("You can't give yourself items", msg.messageId); return; };
const targetRecord = await getUserRecord(target); const targetRecord = await getUserRecord(target);
if (!args[1]) { await sendMessage('Please specify an item to give', msg.messageId); return; }; if (!args[1]) { await sendMessage('Please specify an item to give', msg.messageId); return; };
const item = items.get(args[1].toLowerCase()); const item = items.get(args[1].toLowerCase());
@@ -21,7 +22,7 @@ export default new Command('give', ['give'], 'chatter', async (msg, user) => {
const userRecord = await getUserRecord(user); const userRecord = await getUserRecord(user);
if (userRecord.inventory[item.name]! < amount) { await sendMessage(`You can't give items you don't have!`, msg.messageId); return; }; if (userRecord.inventory[item.name]! < amount) { await sendMessage(`You can't give items you don't have!`, msg.messageId); return; };
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give item. Please try again!', msg.messageId); return; }; if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give item', msg.messageId); return; };
await Promise.all([ await Promise.all([
user.setLock(), user.setLock(),

13
bot/commands/itemlock.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Command, sendMessage } from ".";
import parseCommandArgs from "../lib/parseCommandArgs";
import { User } from "../user";
export default new Command('itemlock', ['itemlock'], 'admin', async msg => {
const args = parseCommandArgs(msg.messageText);
if (!args[0]) { await sendMessage('Please specify a chatter to toggle the lock for', msg.messageId); return; };
const target = await User.initUsername(args[0].toLowerCase());
if (!target) { await sendMessage('Targeted user does not exist', msg.messageId); return; };
const status = await target.itemLock();
status ? await target.clearLock() : await target.setLock();
await sendMessage(`Successfully ${status ? 'cleared' : 'set'} the item lock on ${target.displayName}`, msg.messageId);
}, false);

View File

@@ -10,7 +10,7 @@ export async function getUserRecord(user: User): Promise<userRecord> {
if (Object.keys(data.inventory).sort().toString() !== itemarray.sort().toString()) { // If the items in the user inventory are missing an item. if (Object.keys(data.inventory).sort().toString() !== itemarray.sort().toString()) { // If the items in the user inventory are missing an item.
itemarray.forEach(key => { itemarray.forEach(key => {
if (!(key in data.inventory)) Object.defineProperty(data.inventory, key, { value: 0 }); if (!(key in data.inventory)) data.inventory[key] = 0;
}); });
}; };

View File

@@ -1,6 +1,6 @@
import { chatterId, streamerId, eventSub, commandPrefix, singleUserMode, streamerUsers } from ".."; import { chatterId, streamerId, eventSub, commandPrefix, singleUserMode, streamerUsers } from "..";
import { User } from "../user"; import { User } from "../user";
import commands from "../commands"; import commands, { sendMessage } from "../commands";
import { redis } from "bun"; import { redis } from "bun";
import { isAdmin } from "../lib/admins"; import { isAdmin } from "../lib/admins";
@@ -42,6 +42,10 @@ eventSub.onChannelChatMessage(streamerId, streamerId, async msg => {
}; };
try { await selected.execute(msg, user!); } try { await selected.execute(msg, user!); }
catch (err) { console.error(err); }; catch (err) {
console.error(err);
await sendMessage('ERROR: Something went wrong', msg.messageId);
await user?.clearLock();
};
}; };
}); });

View File

@@ -21,7 +21,7 @@ export default new Item(ITEMNAME, 'Blaster', 's',
if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; }; if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; };
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('Can\'t use two items at once pepeW', msg.messageId); return; }; if (await user.itemLock()) { await sendMessage('Cannot use an item right now', msg.messageId); return; };
await user.setLock(); await user.setLock();
const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60); const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60);
if (result.status) await Promise.all([ if (result.status) await Promise.all([

View File

@@ -22,7 +22,7 @@ export default new Item(ITEMNAME, 'Grenade', 's',
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('Can\'t use two items at once pepeW', msg.messageId); return; }; if (await user.itemLock()) { await sendMessage('Cannot use an item right now', msg.messageId); return; };
await user.setLock(); await user.setLock();
await Promise.all([ await Promise.all([
timeout(target!, `You got hit by ${user.displayName}'s grenade!`, 60), timeout(target!, `You got hit by ${user.displayName}'s grenade!`, 60),

53
bot/items/tnt.ts Normal file
View File

@@ -0,0 +1,53 @@
import { redis } from "bun";
import { sendMessage } from "../commands";
import { timeout } from "../lib/timeout";
import { changeItemCount, Item } from ".";
import { User } from "../user";
import { getUserRecord } from "../db/dbUser";
import { createTimeoutRecord } from "../db/dbTimeouts";
import { createUsedItemRecord } from "../db/dbUsedItems";
const ITEMNAME = 'tnt';
export default new Item(ITEMNAME, 'TNT', 's',
'Give 5-10 random chatters 60 second timeouts',
['tnt'],
async (msg, user) => {
const userObj = await getUserRecord(user);
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any TNTs!`, msg.messageId); return; };
const vulntargets = await redis.keys('vulnchatters:*');
if (vulntargets.length === 0) { await sendMessage('No vulnerable chatters to blow up', msg.messageId); return; };
const targets = getTNTTargets(vulntargets);
if (await user.itemLock()) { await sendMessage('Cannot use an item right now', msg.messageId); return; };
await user.setLock();
await Promise.all(targets.map(async targetid => {
const target = await User.initUserId(targetid.split(':')[1]!);
await getUserRecord(target!); // make sure the user record exist in the database
await Promise.all([
timeout(target!, `You got hit by ${user.displayName}'s TNT!`, 60),
redis.del(targetid),
sendMessage(`wybuh ${target?.displayName} got hit by ${user.displayName}'s TNT wybuh`),
createTimeoutRecord(user, target!, ITEMNAME),
]);
}));
await Promise.all([
createUsedItemRecord(user, ITEMNAME),
changeItemCount(user, userObj, ITEMNAME)
]);
await user.clearLock();
await sendMessage(`RIPBOZO ${user.displayName} exploded ${targets.length} chatter${targets.length === 1 ? '' : 's'} with their TNT RIPBOZO`);
}
);
function getTNTTargets<T>(arr: T[]): T[] {
if (arr.length <= 5) {
return arr;
};
const count = Math.floor(Math.random() * 6) + 5; // Random number between 5 and 10
const shuffled = [...arr].sort(() => 0.5 - Math.random()); // Shuffle array
return shuffled.slice(0, Math.min(count, arr.length)); // Return up to `count` entries
};