mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 13:56:57 +01:00
major reworks, prefixless commands added
This commit is contained in:
@@ -10,10 +10,13 @@ import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
const ITEMNAME = 'blaster';
|
||||
|
||||
export default new Item(ITEMNAME, 'Blaster', 's',
|
||||
'Times a specific person out for 60 seconds',
|
||||
['blaster', 'blast'],
|
||||
async (msg, user) => {
|
||||
export default new Item({
|
||||
name: ITEMNAME,
|
||||
prettyName: 'Blaster',
|
||||
plural: 's',
|
||||
description: 'Times a specific person out for 60 seconds',
|
||||
aliases: ['blaster', 'blast'],
|
||||
execution: async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any blasters!`, msg.messageId); return; };
|
||||
const messagequery = parseCommandArgs(msg.messageText);
|
||||
@@ -54,4 +57,4 @@ export default new Item(ITEMNAME, 'Blaster', 's',
|
||||
};
|
||||
await user.clearLock();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,10 +10,13 @@ import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
const ITEMNAME = 'grenade';
|
||||
|
||||
export default new Item(ITEMNAME, 'Grenade', 's',
|
||||
'Give a random chatter a 60s timeout',
|
||||
['grenade'],
|
||||
async (msg, user) => {
|
||||
export default new Item({
|
||||
name: ITEMNAME,
|
||||
prettyName: 'Grenade',
|
||||
plural: 's',
|
||||
description: 'Give a random chatter a 60s timeout',
|
||||
aliases: ['grenade'],
|
||||
execution: async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any grenades!`, msg.messageId); return; };
|
||||
const targets = await redis.keys(`user:*:vulnerable`);
|
||||
@@ -40,4 +43,4 @@ export default new Item(ITEMNAME, 'Grenade', 's',
|
||||
]);
|
||||
await user.clearLock();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base";
|
||||
import User from "user";
|
||||
import { type userType } from "commands";
|
||||
import { type userType, type specialExecuteArgs } from "commands";
|
||||
|
||||
type itemOptions = {
|
||||
name: string;
|
||||
aliases: string[];
|
||||
prettyName: string;
|
||||
plural: string;
|
||||
description: string;
|
||||
execution: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => Promise<void>;
|
||||
specialaliases?: string[];
|
||||
};
|
||||
|
||||
export class Item {
|
||||
public readonly name: string;
|
||||
@@ -8,25 +18,22 @@ export class Item {
|
||||
public readonly plural: string;
|
||||
public readonly description: string;
|
||||
public readonly aliases: string[];
|
||||
public readonly specialaliases: string[];
|
||||
public readonly usertype: userType;
|
||||
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>;
|
||||
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => 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 execution - code that gets executed when item gets used */
|
||||
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;
|
||||
|
||||
/** Creates an item object */
|
||||
constructor(options: itemOptions) {
|
||||
this.name = options.name.toLowerCase();
|
||||
this.prettyName = options.prettyName;
|
||||
this.plural = options.plural;
|
||||
this.description = options.description;
|
||||
this.aliases = options.aliases;
|
||||
this.usertype = 'chatter'; // Items are usable by everyone
|
||||
this.execute = execution;
|
||||
this.execute = options.execution;
|
||||
this.disableable = true;
|
||||
this.specialaliases = options.specialaliases ?? [];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -34,6 +41,7 @@ import { readdir } from 'node:fs/promises';
|
||||
import type { userRecord } from "db/connection";
|
||||
import { updateUserRecord } from "db/dbUser";
|
||||
const items = new Map<string, Item>;
|
||||
const specialAliasItems = new Map<string, Item>;
|
||||
const emptyInventory: inventory = {};
|
||||
const itemarray: string[] = [];
|
||||
|
||||
@@ -47,10 +55,13 @@ for (const file of files) {
|
||||
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
|
||||
};
|
||||
for (const alias of item.specialaliases) {
|
||||
specialAliasItems.set(alias, item);
|
||||
};
|
||||
};
|
||||
|
||||
export default items;
|
||||
export { emptyInventory, itemarray };
|
||||
export { emptyInventory, itemarray, specialAliasItems };
|
||||
export type inventory = {
|
||||
[key: string]: number;
|
||||
};
|
||||
|
||||
@@ -10,10 +10,14 @@ import User from "user";
|
||||
|
||||
const ITEMNAME = 'silverbullet';
|
||||
|
||||
export default new Item(ITEMNAME, 'Silver bullet', 's',
|
||||
'Times a specific person out for 24 hours',
|
||||
['execute', 'silverbullet'],
|
||||
async (msg, user) => {
|
||||
export default new Item({
|
||||
name: ITEMNAME,
|
||||
prettyName: 'Silver bullet',
|
||||
plural: 's',
|
||||
description: 'Times a specific person out for 24 hours',
|
||||
aliases: ['execute', 'silverbullet'],
|
||||
specialaliases: ['blastin'],
|
||||
execution: async (msg, user, specialargs) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.inventory[ITEMNAME]! < 1) { await sendMessage(`You don't have any silver bullets!`, msg.messageId); return; };
|
||||
const messagequery = parseCommandArgs(msg.messageText);
|
||||
@@ -54,4 +58,4 @@ export default new Item(ITEMNAME, 'Silver bullet', 's',
|
||||
};
|
||||
await user.clearLock();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,10 +10,13 @@ import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
const ITEMNAME = 'tnt';
|
||||
|
||||
export default new Item(ITEMNAME, 'TNT', 's',
|
||||
'Give 5-10 random chatters 60 second timeouts',
|
||||
['tnt'],
|
||||
async (msg, user) => {
|
||||
export default new Item({
|
||||
name: ITEMNAME,
|
||||
prettyName: 'TNT',
|
||||
plural: 's',
|
||||
description: 'Give 5-10 random chatters 60 second timeouts',
|
||||
aliases: ['tnt'],
|
||||
execution: 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('user:*:vulnerable').then(a => a.map(b => b.slice(5, -11)));
|
||||
@@ -46,7 +49,7 @@ export default new Item(ITEMNAME, 'TNT', 's',
|
||||
await user.clearLock();
|
||||
await sendMessage(`RIPBOZO ${user.displayName} exploded ${targets.length} chatter${targets.length === 1 ? '' : 's'} with their TNT RIPBOZO`);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
export function getTNTTargets<T>(arr: T[]): T[] {
|
||||
if (arr.length <= 5) {
|
||||
|
||||
Reference in New Issue
Block a user