mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 07:01:38 +01:00
major reworks, prefixless commands added
This commit is contained in:
@@ -3,7 +3,12 @@ import { addAdmin } from "lib/admins";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('addadmin', ['addadmin'], 'streamer', async msg => {
|
||||
export default new Command({
|
||||
name: 'addadmin',
|
||||
aliases: ['addadmin'],
|
||||
usertype: 'streamer',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -11,4 +16,5 @@ export default new Command('addadmin', ['addadmin'], 'streamer', async msg => {
|
||||
const data = await addAdmin(target.id);
|
||||
if (data === "OK") await sendMessage(`${target.displayName} is now an admin`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} is already an admin`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,12 @@ import { addInvuln } from "lib/invuln";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('addinvuln', ['addinvuln'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'addinvuln',
|
||||
aliases: ['addinvuln'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -11,4 +16,5 @@ export default new Command('addinvuln', ['addinvuln'], 'admin', async msg => {
|
||||
const data = await addInvuln(target.id);
|
||||
if (data === "OK") await sendMessage(`${target.displayName} is now an invuln`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} is already an invuln`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,11 @@ import { changeBalance } from "lib/changeBalance";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('admindonate', ['admindonate'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'admindonate',
|
||||
aliases: ['admindonate'],
|
||||
usertype: 'admin',
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -22,4 +26,5 @@ export default new Command('admindonate', ['admindonate'], 'admin', async msg =>
|
||||
await sendMessage(`${target.displayName} now has ${data.balance} qweribuck${data.balance === 1 ? '' : 's'}`, msg.messageId);
|
||||
};
|
||||
await target.clearLock();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,11 @@ import items, { changeItemCount } from "items";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('admingive', ['admingive'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'admingive',
|
||||
aliases: ['admingive'],
|
||||
usertype: 'admin',
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -26,4 +30,5 @@ export default new Command('admingive', ['admingive'], 'admin', async msg => {
|
||||
await sendMessage(`Failed to give ${target.displayName} ${amount} ${item.prettyName + (amount === 1 ? '' : item.plural)}`, msg.messageId);
|
||||
};
|
||||
await target.clearLock();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,11 @@ import { getTimeoutStats, getItemStats } from "lib/getStats";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('alltimestats', ['alltime', 'alltimestats'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'alltimestats',
|
||||
aliases: ['alltime', 'alltimestats'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
let target: User | null = user;
|
||||
if (args[0]) {
|
||||
@@ -25,4 +29,5 @@ export default new Command('alltimestats', ['alltime', 'alltimestats'], 'chatter
|
||||
Silver bullets fired: ${timeout.shot.silverbullet},
|
||||
Silver bullets taken: ${timeout.hit.silverbullet}.
|
||||
`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,9 +2,14 @@ import { Command, sendMessage } from "commands";
|
||||
import User from "user";
|
||||
import { redis } from "bun";
|
||||
|
||||
export default new Command('backshot', ['backshot'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'backshot',
|
||||
aliases: ['backshot'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const targets = await redis.keys(`user:*:haschatted`);
|
||||
const selection = targets[Math.floor(Math.random() * targets.length)]!;
|
||||
const target = await User.initUserId(selection.slice(5, -11));
|
||||
await sendMessage(`${user.displayName} backshotted ${target?.displayName}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { timeout } from "lib/timeout";
|
||||
import User from "user";
|
||||
import { playAlert } from "web/alerts/serverFunctions";
|
||||
|
||||
export default new Command('banclanker', ['banclanker', 'banbot'], 'moderator', async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage(`Specify a clanker to ban`, msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0]);
|
||||
if (!target) { await sendMessage(`Clanker ${args[0]} doesn't exist`, msg.messageId); return; };
|
||||
await Promise.all([
|
||||
timeout(target, `get fucked`),
|
||||
playAlert({
|
||||
name: 'userExecution',
|
||||
user: msg.chatterDisplayName,
|
||||
target: target.displayName
|
||||
})
|
||||
]);
|
||||
});
|
||||
@@ -3,7 +3,12 @@ import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { namedcheers } from "cheers";
|
||||
|
||||
export default new Command('disablecheer', ['disablecheer'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'disablecheer',
|
||||
aliases: ['disablecheer'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a cheer to disable', msg.messageId); return; };
|
||||
const selection = namedcheers.get(args[0].toLowerCase());
|
||||
@@ -11,4 +16,5 @@ export default new Command('disablecheer', ['disablecheer'], 'admin', async msg
|
||||
const result = await redis.sadd('disabledcheers', selection.name);
|
||||
if (result === 0) { await sendMessage(`The ${selection.name} cheer is already disabled`, msg.messageId); return; };
|
||||
await sendMessage(`Successfully disabled the ${selection.name} cheer`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { redis } from "bun";
|
||||
import commands, { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('disablecommand', ['disablecommand'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'disablecommand',
|
||||
aliases: ['disablecommand'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a command to disable', msg.messageId); return; };
|
||||
const selection = commands.get(args[0].toLowerCase());
|
||||
@@ -11,4 +16,5 @@ export default new Command('disablecommand', ['disablecommand'], 'admin', async
|
||||
const result = await redis.sadd('disabledcommands', selection.name);
|
||||
if (result === 0) { await sendMessage(`The ${selection.name} command is already disabled`, msg.messageId); return; };
|
||||
await sendMessage(`Successfully disabled the ${selection.name} command`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,7 +6,11 @@ import { changeBalance } from "lib/changeBalance";
|
||||
import User from "user";
|
||||
import logger from "lib/logger";
|
||||
|
||||
export default new Command('donate', ['donate'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'donate',
|
||||
aliases: ['donate'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -45,4 +49,5 @@ export default new Command('donate', ['donate'], 'chatter', async (msg, user) =>
|
||||
user.clearLock(),
|
||||
target.clearLock()
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,12 @@ import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { namedcheers } from "cheers";
|
||||
|
||||
export default new Command('enablecheer', ['enablecheer'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'enablecheer',
|
||||
aliases: ['enablecheer'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a cheer to enable', msg.messageId); return; };
|
||||
const selection = namedcheers.get(args[0].toLowerCase());
|
||||
@@ -11,4 +16,5 @@ export default new Command('enablecheer', ['enablecheer'], 'admin', async msg =>
|
||||
const result = await redis.srem('disabledcheers', selection.name);
|
||||
if (result === 0) { await sendMessage(`The ${selection.name} cheer isn't disabled`, msg.messageId); return; };
|
||||
await sendMessage(`Successfully enabled the ${selection.name} cheer`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { redis } from "bun";
|
||||
import commands, { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('enablecommand', ['enablecommand'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'enablecommand',
|
||||
aliases: ['enablecommand'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a command to enable', msg.messageId); return; };
|
||||
const selection = commands.get(args[0].toLowerCase());
|
||||
@@ -10,4 +15,5 @@ export default new Command('enablecommand', ['enablecommand'], 'admin', async ms
|
||||
const result = await redis.srem('disabledcommands', selection.name);
|
||||
if (result === 0) { await sendMessage(`The ${selection.name} command isn't disabled`, msg.messageId); return; };
|
||||
await sendMessage(`Successfully enabled the ${selection.name} command`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { Command, sendMessage } from "commands";
|
||||
import { getAdmins } from "lib/admins";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('getadmins', ['getadmins'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'getadmins',
|
||||
aliases: ['getadmins'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const admins = await getAdmins()
|
||||
const adminnames: string[] = [];
|
||||
for (const id of admins) {
|
||||
@@ -10,4 +15,5 @@ export default new Command('getadmins', ['getadmins'], 'chatter', async msg => {
|
||||
adminnames.push(admin?.displayName!);
|
||||
};
|
||||
await sendMessage(`Current admins: ${adminnames.join(', ')}`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,10 +3,15 @@ import { getUserRecord } from "db/dbUser";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('getbalance', ['getbalance', 'balance', 'qbucks', 'qweribucks', 'wallet', 'getwallet'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'getbalance',
|
||||
aliases: ['getbalance', 'balance', 'qbucks', 'qweribucks', 'wallet', 'getwallet'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
const target = args[0] ? await User.initUsername(args[0].toLowerCase()) : user;
|
||||
if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist!`, msg.messageId); return; };
|
||||
const data = await getUserRecord(target);
|
||||
await sendMessage(`${target.displayName} has ${data.balance} qbuck${data.balance === 1 ? '' : 's'}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,12 @@ import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { namedcheers } from "cheers";
|
||||
|
||||
export default new Command('getcheers', ['getcheers', 'getcheer'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'getcheers',
|
||||
aliases: ['getcheers', 'getcheer'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage(`A full list of cheers can be found here: https://github.com/qwerinope/qweribot#cheers`, msg.messageId); return; };
|
||||
const disabledcheers = await redis.smembers('disabledcheers');
|
||||
@@ -30,4 +35,5 @@ export default new Command('getcheers', ['getcheers', 'getcheer'], 'chatter', as
|
||||
await sendMessage(cheerstrings.length === 0 ? last : cheerstrings.join(', ') + " and " + last, msg.messageId);
|
||||
|
||||
} else await sendMessage('Please specify if you want the enabled or disabled cheers', msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { redis } from "bun";
|
||||
import { basecommands, Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('getcommands', ['getcommands', 'getc'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'getcommands',
|
||||
aliases: ['getcommands', 'getc'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage(`A full list of commands can be found here: https://github.com/qwerinope/qweribot#commands-1`, msg.messageId); return; };
|
||||
const disabledcommands = await redis.smembers('disabledcommands');
|
||||
@@ -20,4 +25,5 @@ export default new Command('getcommands', ['getcommands', 'getc'], 'chatter', as
|
||||
else await sendMessage(`Currently disabled commands: ${disabledcommands.join(', ')}`);
|
||||
}
|
||||
else await sendMessage('Please specify if you want the enabled or disabled commands', msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,11 @@ import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
import items from "items";
|
||||
|
||||
export default new Command('inventory', ['inv', 'inventory', 'pocket'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'inventory',
|
||||
aliases: ['inv', 'inventory', 'pocket'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
let target: User = user;
|
||||
if (args[0]) {
|
||||
@@ -23,4 +27,5 @@ export default new Command('inventory', ['inv', 'inventory', 'pocket'], 'chatter
|
||||
|
||||
if (messagedata.length === 0) { await sendMessage(`${target.displayName} has no items`, msg.messageId); return; };
|
||||
await sendMessage(`Inventory of ${target.displayName}: ${messagedata.join(', ')}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { Command, sendMessage } from "commands";
|
||||
import { getInvulns } from "lib/invuln";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('getinvulns', ['getinvulns'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'getinvulns',
|
||||
aliases: ['getinvulns'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const invulns = await getInvulns()
|
||||
const invulnnames: string[] = [];
|
||||
for (const id of invulns) {
|
||||
@@ -10,4 +15,5 @@ export default new Command('getinvulns', ['getinvulns'], 'chatter', async msg =>
|
||||
invulnnames.push(invuln?.displayName!);
|
||||
};
|
||||
await sendMessage(`Current invulnerable chatters: ${invulnnames.join(', ')}`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,7 +7,11 @@ import { timeout } from "lib/timeout";
|
||||
|
||||
const COOLDOWN = 10 * 60 * 1000; // 10 mins (ms)
|
||||
|
||||
export default new Command('getloot', ['getloot', 'dig', 'loot'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'getloot',
|
||||
aliases: ['getloot', 'dig', 'loot'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
if (!await redis.exists('streamIsLive')) { await sendMessage(`No loot while stream is offline`, msg.messageId); return; };
|
||||
if (await user.itemLock()) { await sendMessage(`Cannot get loot (itemlock)`, msg.messageId); return; };
|
||||
const userData = await getUserRecord(user);
|
||||
@@ -74,4 +78,5 @@ export default new Command('getloot', ['getloot', 'dig', 'loot'], 'chatter', asy
|
||||
sendMessage(message, msg.messageId),
|
||||
user.clearLock()
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,11 @@ import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
import { timeoutDuration } from "lib/timeout";
|
||||
|
||||
export default new Command('gettimeout', ['gett', 'gettimeout'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'gettimeout',
|
||||
aliases: ['gett', 'gettimeout'],
|
||||
usertype: 'chatter',
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -13,4 +17,5 @@ export default new Command('gettimeout', ['gett', 'gettimeout'], 'chatter', asyn
|
||||
if (data === false) { await sendMessage(`Chatter ${target.displayName} isn't timed out`, msg.messageId); return; };
|
||||
if (data) { await sendMessage(`${target.displayName} is still timed out for ${buildTimeString(data * 1000, Date.now())}`, msg.messageId); return; };
|
||||
await sendMessage(`${target.displayName} is permanently banned`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,7 +6,11 @@ import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
import logger from "lib/logger";
|
||||
|
||||
export default new Command('give', ['give'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'give',
|
||||
aliases: ['give'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -46,4 +50,5 @@ export default new Command('give', ['give'], 'chatter', async (msg, user) => {
|
||||
};
|
||||
await user.clearLock();
|
||||
await target.clearLock();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,24 +3,40 @@ import User from "user";
|
||||
|
||||
export type userType = 'chatter' | 'admin' | 'streamer' | 'moderator';
|
||||
|
||||
export type specialExecuteArgs = {
|
||||
activation?: string;
|
||||
};
|
||||
|
||||
export type commandOptions = {
|
||||
name: string;
|
||||
aliases: string[];
|
||||
usertype: userType;
|
||||
execution: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => Promise<void>;
|
||||
disableable?: boolean;
|
||||
specialaliases?: string[];
|
||||
};
|
||||
|
||||
/** The Command class represents a command */
|
||||
export class Command {
|
||||
public readonly name: string;
|
||||
public readonly aliases: string[];
|
||||
public readonly usertype: userType;
|
||||
public readonly disableable: boolean;
|
||||
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>;
|
||||
constructor(name: string, aliases: string[], usertype: userType, execution: (message: EventSubChannelChatMessageEvent, sender: User) => Promise<void>, disableable?: boolean) {
|
||||
this.name = name.toLowerCase();
|
||||
this.aliases = aliases;
|
||||
this.usertype = usertype;
|
||||
this.execute = execution;
|
||||
this.disableable = disableable ?? true;
|
||||
public readonly specialaliases: string[];
|
||||
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => Promise<void>;
|
||||
constructor(options: commandOptions) {
|
||||
this.name = options.name.toLowerCase();
|
||||
this.aliases = options.aliases;
|
||||
this.usertype = options.usertype;
|
||||
this.execute = options.execution;
|
||||
this.disableable = options.disableable ?? true;
|
||||
this.specialaliases = options.specialaliases ?? [];
|
||||
};
|
||||
};
|
||||
|
||||
import { readdir } from 'node:fs/promises';
|
||||
const commands = new Map<string, Command>; // This map has all command/item aliases mapped to commands/items (many-to-one)
|
||||
const specialAliasCommands = new Map<string, Command>; // This map has all special command/item aliases mapped to commands/items (just like commands map)
|
||||
const basecommands = new Map<string, Command>; // This map has all command names mapped to commands (one-to-one) (no items)
|
||||
|
||||
const files = await readdir(import.meta.dir);
|
||||
@@ -32,15 +48,21 @@ for (const file of files) {
|
||||
for (const alias of command.aliases) {
|
||||
commands.set(alias, command); // Since it's not a primitive type the map is filled with references to the command, not the actual object
|
||||
};
|
||||
for (const alias of command.specialaliases) {
|
||||
specialAliasCommands.set(alias, command);
|
||||
};
|
||||
};
|
||||
|
||||
import items from "items";
|
||||
import items, { specialAliasItems } from "items";
|
||||
for (const [name, item] of Array.from(items)) {
|
||||
commands.set(name, item); // As Item is basically just Command but with more parameters, this should work fine
|
||||
};
|
||||
for (const [alias, item] of Array.from(specialAliasItems)) {
|
||||
specialAliasCommands.set(alias, item);
|
||||
};
|
||||
|
||||
export default commands;
|
||||
export { basecommands };
|
||||
export { specialAliasCommands, basecommands };
|
||||
|
||||
import { chatterApi, chatterId, streamerId } from "main";
|
||||
|
||||
|
||||
@@ -2,10 +2,15 @@ import { Command, sendMessage } from "commands";
|
||||
import items from "items";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('iteminfo', ['iteminfo', 'itemhelp', 'info'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'iteminfo',
|
||||
aliases: ['iteminfo', 'itemhelp', 'info'],
|
||||
usertype: 'chatter',
|
||||
execution: async msg => {
|
||||
const messagequery = parseCommandArgs(msg.messageText).join(' ');
|
||||
if (!messagequery) { await sendMessage('Please specify an item you would like to get info about', msg.messageId); return; };
|
||||
const selection = items.get(messagequery.toLowerCase());
|
||||
if (!selection) { await sendMessage(`'${messagequery}' is not an item`, msg.messageId); return; };
|
||||
await sendMessage(`Name: ${selection.prettyName}, Description: ${selection.description}, Aliases: ${selection.aliases.join(', ')}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@ import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('itemlock', ['itemlock'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'itemlock',
|
||||
aliases: ['itemlock'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: 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());
|
||||
@@ -10,4 +15,5 @@ export default new Command('itemlock', ['itemlock'], 'admin', async msg => {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,11 @@ import { getTimeoutStats, getItemStats } from "lib/getStats";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('monthlystats', ['stats', 'monthlystats'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'monthlystats',
|
||||
aliases: ['stats', 'monthlystats'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
let target: User | null = user;
|
||||
if (args[0]) {
|
||||
@@ -25,4 +29,5 @@ export default new Command('monthlystats', ['stats', 'monthlystats'], 'chatter',
|
||||
Silver bullets fired: ${timeout.shot.silverbullet},
|
||||
Silver bullets taken: ${timeout.hit.silverbullet}.
|
||||
`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,12 @@ import { removeAdmin } from "lib/admins";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('removeadmin', ['removeadmin'], 'streamer', async msg => {
|
||||
export default new Command({
|
||||
name: 'removeadmin',
|
||||
aliases: ['removeadmin'],
|
||||
usertype: 'streamer',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -13,4 +18,5 @@ export default new Command('removeadmin', ['removeadmin'], 'streamer', async msg
|
||||
const data = await removeAdmin(target.id);
|
||||
if (data === 1) await sendMessage(`${target.displayName} is no longer an admin`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} isn't an admin`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,12 @@ import { removeInvuln } from "lib/invuln";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
|
||||
export default new Command('removeinvuln', ['removeinvuln'], 'admin', async msg => {
|
||||
export default new Command({
|
||||
name: 'removeinvuln',
|
||||
aliases: ['removeinvuln'],
|
||||
usertype: 'admin',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
@@ -13,4 +18,5 @@ export default new Command('removeinvuln', ['removeinvuln'], 'admin', async msg
|
||||
const data = await removeInvuln(target.id);
|
||||
if (data === 1) await sendMessage(`${target.displayName} is no longer invulnerable`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} isn't invulnerable`, msg.messageId);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,11 @@ import { timeout } from "lib/timeout";
|
||||
|
||||
const barrelCount = 6;
|
||||
|
||||
export default new Command('roulette', ['roulette'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'roulette',
|
||||
aliases: ['roulette'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
if (!await redis.exists('rouletteCount')) await redis.set('rouletteCount', "0");
|
||||
const currentChamber = Number(await redis.get('rouletteCount'));
|
||||
const shot = Math.random() < 1 / (barrelCount - currentChamber);
|
||||
@@ -17,4 +21,5 @@ export default new Command('roulette', ['roulette'], 'chatter', async (msg, user
|
||||
sendMessage("wybuh BANG!! wybuh"),
|
||||
timeout(user, "You lost at russian roulette!", 5 * 60)
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import { timeout } from "lib/timeout";
|
||||
|
||||
export default new Command('seiso', ['seiso'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'seiso',
|
||||
aliases: ['seiso'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const rand = Math.floor(Math.random() * 101);
|
||||
if (rand > 75) await sendMessage(`${rand}% seiso YAAAA`, msg.messageId);
|
||||
else if (rand > 51) await sendMessage(`${rand}% seiso POGGERS`, msg.messageId);
|
||||
@@ -12,4 +16,5 @@ export default new Command('seiso', ['seiso'], 'chatter', async (msg, user) => {
|
||||
sendMessage(`${rand}% seiso RIPBOZO`),
|
||||
timeout(user, 'TOO YABAI!', 60)
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,12 @@ import { Command, sendMessage } from "commands";
|
||||
import { isAdmin } from "lib/admins";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('stacking', ['stacking'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'stacking',
|
||||
aliases: ['stacking'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0] || !await isAdmin(msg.chatterId)) { await sendMessage(`Timeout stacking is currently ${await redis.exists('timeoutStacking') ? "on" : "off"}`, msg.messageId); return; };
|
||||
// Only admins can reach this part of code
|
||||
@@ -19,4 +24,5 @@ export default new Command('stacking', ['stacking'], 'chatter', async msg => {
|
||||
await sendMessage('Timeout stacking is now off')
|
||||
break;
|
||||
};
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,10 +2,16 @@ import { Command, sendMessage } from "commands";
|
||||
import { handleCheer } from "events/message";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
|
||||
export default new Command('testcheer', ['testcheer'], 'streamer', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'testcheer',
|
||||
aliases: ['testcheer'],
|
||||
usertype: 'streamer',
|
||||
disableable: false,
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify the amount of fake bits you want to send', msg.messageId); return; };
|
||||
if (isNaN(Number(args[0]))) { await sendMessage(`${args[0]} is not a valid amout of bits`); return; };
|
||||
const bits = Number(args.shift()); // we shift it so the amount of bits isn't part of the handleCheer message, we already know that args[0] can be parsed as a number so this is fine.
|
||||
await handleCheer(msg, bits, user);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,7 +6,11 @@ import { timeout } from "lib/timeout";
|
||||
import { changeBalance } from "lib/changeBalance";
|
||||
import { createTimeoutRecord } from "db/dbTimeouts";
|
||||
|
||||
export default new Command('timeout', ['timeout'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'timeout',
|
||||
aliases: ['timeout'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.balance < 100) { await sendMessage(`You don't have enough qweribucks (need 100, have ${userObj.balance})`, msg.messageId); return; };
|
||||
const messagequery = parseCommandArgs(msg.messageText);
|
||||
@@ -38,4 +42,5 @@ export default new Command('timeout', ['timeout'], 'chatter', async (msg, user)
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,11 +2,17 @@ import { redis } from "bun";
|
||||
import { Command, sendMessage } from "commands";
|
||||
import items from "items";
|
||||
|
||||
export default new Command('use', ['use'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'use',
|
||||
aliases: ['use'],
|
||||
usertype: 'chatter',
|
||||
disableable: false,
|
||||
execution: async (msg, user) => {
|
||||
const messagequery = msg.messageText.trim().split(' ').slice(1);
|
||||
if (!messagequery[0]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; };
|
||||
const selection = items.get(messagequery[0].toLowerCase());
|
||||
if (!selection) { await sendMessage(`'${messagequery[0]}' is not an item`, msg.messageId); return; };
|
||||
if (await redis.sismember('disabledcommands', selection.name)) { await sendMessage(`The ${selection.prettyName} item is disabled`, msg.messageId); return; };
|
||||
await selection.execute(msg, user);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { redis } from "bun";
|
||||
import { Command, sendMessage } from "commands";
|
||||
|
||||
export default new Command('vulnchatters', ['vulnchatters', 'vulnc'], 'chatter', async msg => {
|
||||
export default new Command({
|
||||
name: 'vulnchatters',
|
||||
aliases: ['vulnchatters', 'vulnc'],
|
||||
usertype: 'chatter',
|
||||
execution: async msg => {
|
||||
const data = await redis.keys('user:*:vulnerable');
|
||||
const one = data.length === 1;
|
||||
await sendMessage(`There ${one ? 'is' : 'are'} ${data.length} vulnerable chatter${one ? '' : 's'}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,11 @@ import { Command, sendMessage } from "commands";
|
||||
import { timeout } from "lib/timeout";
|
||||
|
||||
// Remake of the !yabai command in ttv/kiara_tv
|
||||
export default new Command('yabai', ['yabai', 'goon'], 'chatter', async (msg, user) => {
|
||||
export default new Command({
|
||||
name: 'yabai',
|
||||
aliases: ['yabai', 'goon'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const rand = Math.floor(Math.random() * 101);
|
||||
if (rand < 25) sendMessage(`${rand}% yabai! GIGACHAD`, msg.messageId);
|
||||
else if (rand < 50) sendMessage(`${rand}% yabai POGGERS`, msg.messageId);
|
||||
@@ -12,4 +16,5 @@ export default new Command('yabai', ['yabai', 'goon'], 'chatter', async (msg, us
|
||||
sendMessage(`${msg.chatterDisplayName} is ${rand}% yabai CAUGHT`),
|
||||
timeout(user, "TOO YABAI!", 60)
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base"
|
||||
import { streamerId, eventSub, commandPrefix, streamerUsers } from "main";
|
||||
import User from "user";
|
||||
import commands, { sendMessage } from "commands";
|
||||
import commands, { Command, sendMessage, specialAliasCommands } from "commands";
|
||||
import { redis } from "bun";
|
||||
import { isAdmin } from "lib/admins";
|
||||
import cheers from "cheers";
|
||||
@@ -11,6 +11,7 @@ import { isInvuln, setTemporaryInvuln } from "lib/invuln";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import { createCheerRecord } from "db/dbCheers";
|
||||
import handleAnivMessage from "lib/handleAnivMessage";
|
||||
import { spec } from "node:test/reporters";
|
||||
|
||||
eventSub.onChannelChatMessage(streamerId, streamerId, parseChatMessage);
|
||||
|
||||
@@ -46,13 +47,12 @@ async function handleChatMessage(msg: EventSubChannelChatMessageEvent, user: Use
|
||||
handleAnivMessage(msg, user);
|
||||
|
||||
// Parse commands:
|
||||
if (msg.messageText.startsWith(commandPrefix)) {
|
||||
const commandSelection = msg.messageText.slice(commandPrefix.length).split(' ')[0]!;
|
||||
const selected = commands.get(commandSelection.toLowerCase());
|
||||
const selected = selectCommand(msg.messageText);
|
||||
if (!selected) return;
|
||||
if (await redis.sismember('disabledcommands', selected.name)) return;
|
||||
const { cmd: selection, activation } = selected;
|
||||
if (await redis.sismember('disabledcommands', selection.name)) return;
|
||||
|
||||
switch (selected.usertype) {
|
||||
switch (selection.usertype) {
|
||||
case "admin":
|
||||
if (!await isAdmin(user.id)) return;
|
||||
break;
|
||||
@@ -64,13 +64,31 @@ async function handleChatMessage(msg: EventSubChannelChatMessageEvent, user: Use
|
||||
break;
|
||||
};
|
||||
|
||||
try { await selected.execute(msg, user); }
|
||||
try {
|
||||
await selection.execute(msg, user, {
|
||||
activation
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
logger.err(err as string);
|
||||
await sendMessage('ERROR: Something went wrong', msg.messageId);
|
||||
await user.clearLock();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type selectedCommand = {
|
||||
cmd: Command;
|
||||
activation: string;
|
||||
};
|
||||
|
||||
function selectCommand(message: string): selectedCommand | false {
|
||||
const specialcmdselector = message.trim().toLowerCase().split(' ')[0]!;
|
||||
const specialcmd = specialAliasCommands.get(specialcmdselector);
|
||||
if (specialcmd) return { cmd: specialcmd, activation: specialcmdselector };
|
||||
const commandSelector = message.slice(commandPrefix.length).trim().toLowerCase().split(' ')[0]!;
|
||||
const normalcmd = commands.get(commandSelector);
|
||||
if (normalcmd) return { cmd: normalcmd, activation: commandPrefix + commandSelector };
|
||||
return false;
|
||||
};
|
||||
|
||||
export async function handleCheer(msg: EventSubChannelChatMessageEvent, bits: number, user: User) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { commandPrefix } from "main";
|
||||
|
||||
/** Helper function to extract arguments from commands */
|
||||
export default function parseCommandArgs(input: string) {
|
||||
const nice = input.toLowerCase().slice(commandPrefix.length).trim();
|
||||
const sliceLength = nice.startsWith('use') ? 2 : 1;
|
||||
export default function parseCommandArgs(input: string, specialAlias?: string) {
|
||||
let nice = '';
|
||||
let sliceLength = 0;
|
||||
if (specialAlias) {
|
||||
nice = input.toLowerCase().slice(specialAlias.length).trim();
|
||||
} else {
|
||||
nice = input.toLowerCase().slice(commandPrefix.length).trim();
|
||||
sliceLength = nice.startsWith('use') ? 2 : 1;
|
||||
}
|
||||
return nice.split(' ').slice(sliceLength);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user