mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 07:21:38 +01:00
minor bugfixes for singleusermode, added seiso command and basic item implementation
items need to check the inventory of the user themselves also !iteminfo and !use commands should be super easy to make i do wonder if there's a nicer way to create the Item objects
This commit is contained in:
22
bot/items/grenade.ts
Normal file
22
bot/items/grenade.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { redis } from "bun";
|
||||
import { sendMessage } from "../commands";
|
||||
import { timeout } from "../lib/timeout";
|
||||
import { Item } from ".";
|
||||
import { User } from "../user";
|
||||
|
||||
export default new Item('grenade', 'Grenade', 's',
|
||||
'Give a random chatter a 60s timeout',
|
||||
['grenade'],
|
||||
['moderator:manage:banned_users'],
|
||||
async (msg, user) => {
|
||||
const targets = await redis.keys('vulnchatters:*');
|
||||
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.split(':')[1]!);
|
||||
await Promise.all([
|
||||
timeout(target!, `You got hit by ${user.displayName}'s grenade!`, 60),
|
||||
redis.del(selection),
|
||||
sendMessage(`wybuh ${target?.displayName} got hit by ${user.displayName}'s grenade wybuh`)
|
||||
]);
|
||||
}
|
||||
);
|
||||
47
bot/items/index.ts
Normal file
47
bot/items/index.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base";
|
||||
import { User } from "../user";
|
||||
|
||||
export class Item {
|
||||
public readonly name: string;
|
||||
public readonly prettyName: string;
|
||||
public readonly plural: string;
|
||||
public readonly description: string;
|
||||
public readonly aliases: string[];
|
||||
public readonly requiredIntents: string[];
|
||||
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>;
|
||||
/** Creates an item object
|
||||
* @param name - internal name of item
|
||||
* @param prettyName - name of item for presenting to chat
|
||||
* @param plural - plural appendage; example: lootbox(es)
|
||||
* @param description - description of what item does
|
||||
* @param aliases - alternative ways to activate item
|
||||
* @param requiredIntents - required twitch API scopes to use item
|
||||
* @param execution - code that gets executed when item gets used */
|
||||
constructor(name: string, prettyName: string, plural: string, description: string, aliases: string[], requiredIntents: string[], execution: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>) {
|
||||
this.name = name;
|
||||
this.prettyName = prettyName;
|
||||
this.plural = plural;
|
||||
this.description = description;
|
||||
this.aliases = aliases;
|
||||
this.requiredIntents = requiredIntents;
|
||||
this.execute = execution;
|
||||
};
|
||||
};
|
||||
|
||||
import { readdir } from 'node:fs/promises';
|
||||
const items = new Map<string, Item>;
|
||||
const itemintents: string[] = [];
|
||||
|
||||
const files = await readdir(import.meta.dir);
|
||||
for (const file of files) {
|
||||
if (!file.endsWith('.ts')) continue;
|
||||
if (file === import.meta.file) continue;
|
||||
const item: Item = await import(import.meta.dir + '/' + file.slice(0, -3)).then(a => a.default);
|
||||
itemintents.push(...item.requiredIntents);
|
||||
for (const alias of item.aliases) {
|
||||
items.set(alias, item); // Since it's not a primitive type the map is filled with references to the item, not the actual object
|
||||
};
|
||||
};
|
||||
|
||||
export default items;
|
||||
export { itemintents };
|
||||
Reference in New Issue
Block a user