mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 07:41:38 +01:00
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:
@@ -9,7 +9,7 @@ const ITEMNAME = 'blaster';
|
||||
|
||||
export default new Item(ITEMNAME, 'Blaster', 's',
|
||||
'Times a specific person out for 60 seconds',
|
||||
['blaster', 'blast'], ['moderator:manage:banned_users'],
|
||||
['blaster', 'blast'],
|
||||
async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any blasters!`, msg.messageId); return; };
|
||||
|
||||
@@ -10,7 +10,6 @@ const ITEMNAME = 'grenade';
|
||||
export default new Item(ITEMNAME, 'Grenade', 's',
|
||||
'Give a random chatter a 60s timeout',
|
||||
['grenade'],
|
||||
['moderator:manage:banned_users'],
|
||||
async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any grenades!`, msg.messageId); return; };
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user