disabled items can no longer be used with !use, admingive is now disableable, removed command specific intents, simplified command permission system

This commit is contained in:
2025-06-29 15:26:03 +02:00
parent 773a694714
commit 898e0b7b70
23 changed files with 72 additions and 85 deletions

View File

@@ -1,5 +1,6 @@
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base";
import { User } from "../user";
import { type userType } from "../commands";
export class Item {
public readonly name: string;
@@ -7,24 +8,25 @@ export class Item {
public readonly plural: string;
public readonly description: string;
public readonly aliases: string[];
public readonly requiredIntents: string[];
public readonly usertype: userType;
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>;
public readonly disableable: boolean;
/** 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>) {
constructor(name: string, prettyName: string, plural: string, description: string, aliases: 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.usertype = 'chatter'; // Items are usable by everyone
this.execute = execution;
this.disableable = true;
};
};
@@ -32,7 +34,6 @@ import { readdir } from 'node:fs/promises';
import type { userRecord } from "../db/connection";
import { updateUserRecord } from "../db/dbUser";
const items = new Map<string, Item>;
const itemintents: string[] = [];
const emptyInventory: inventory = {};
const itemarray: string[] = [];
@@ -43,14 +44,13 @@ for (const file of files) {
const item: Item = await import(import.meta.dir + '/' + file.slice(0, -3)).then(a => a.default);
emptyInventory[item.name] = 0;
itemarray.push(item.name);
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, emptyInventory, itemarray };
export { emptyInventory, itemarray };
export type inventory = {
[key: string]: number;
};