2 development.commands
qwerinope edited this page 2026-02-27 18:10:05 +01:00

Commands, Items, Point Redeems and Cheers

Commands

The constructor for commands takes an object with several attributes, these are all self explanatory.

The name of commands has to be lowercase.

Aliases and special aliases cannot contain spaces and must all be lowercase.

The execution attribute is the method that gets called when the command is run. By now the program has checked if the user has the required permissions and if the command isn't disabled.

The execution method should by itself validate everything else, and return from the function when encountering a problem.

A common pattern will be:

if (condition) { await sendMessage("message", msg.messageId); return; };

This replies with specific info to the chatter and ends the execution of the command.

The method gives 3 optional arguments: msg, user and specialargs

msg contains all data from the triggering message. parseCommandArgs(msg.messageText) should be used for extracting arguments from commands.

user has a User object from the user.

specialargs currently only contains activation which is the string that activated the command. Useful for parsing specialAliases.

Commands are currently loaded at runtime by looking through the commands directory for any .ts files (excluding index.ts, as that's the one that does the scanning and doesn't contain a command).

All commands found will have their default export imported (which has to be a Command).

These will then get mapped into a couple of maps that get exported:

NAME FUNCTION
default commands Stores all commands with the keys being individual aliases. This map contains many of the same commands, which is fine, as JS/TS stores references to the same object instead of the same object. This also contains all items.
specialAliasCommands Stores all commands with the keys being individual special aliases. This map is nearly empty, as very few commands/items have special aliases. This also contains items.
basecommands Stores all commands with the key being the name. Every command is stored once. This map contains no items.

Items

Items work the same as commands, as they inherit most of the construction and activation logic from commands. They get loaded the same as commands, except from the items directory instead of commands. Items can always be disabled and need no permissions.

The items directory exports some constants as well:

NAME TYPE FUNCTION
items type<string> A static type of all item names.
default itemAliasMap Map<string, Item> Stores all items with the keys being individual aliases, just like commands.
specialAliasMap Map<string, Item> Stores all items with the keys being special alises. Currently only has blastin for silverbullets.
emptyInventory Object<items, number: 0> Self explanatory, an empty inventory with every item set to 0.
itemObjectArray Array<Item> An array of all items.
itemarray Array<items> An array of all item names.

Point Redeems

Point Redeems are events that happen whenever a user uses channel points. Pointredeems are similar to commands as they also have a field with execution, that takes a function that gets executed upon activation, and that they automatically import everything from the pointRedeems directory. Pointredeems differ by the fact that we need to communicate with twitch. We need to set the pointredeem cost, colour, title, prompt, input etc.

Most possible flags are currently not an option to set with the PointRedeem class, but they're not nessecary.

Pointredeems that have been created on twitch by an application, have an annoying as fuck quirk, where they can only be modified or deleted by the same application. There's currently a crappy fix to only create pointredeems on twitch if the environment is production. This makes testing a pain in the ass. Pointredeems can also only be marked as fulfilled or canceled by the application that made the redeem, which makes even less sense.

When the bot is started, it will check the environment. If started with the production database, it will create all pointredeems on twitch, then delete all pointredeems that are not defined in the program. If it's started with the development database, it will not create them at all.

Pointredeems export the following constants:

NAME TYPE FUNCTION
namedredeems Map<string, Pointredeem> A map of all defined redeems with the keys being the names.
sfxRedeems Map<string, Pointredeem> A map of all defined sound redeems with the keys being the names.
idMap Map<string, string> A map of the names of redeems to the ids that twitch assigned.
activeRedeems Map<string, Pointredeem> A map of twitch assigned ids to the redeem object.

Cheers

Cheers are the final command-like in the project. These get triggered when a message with a specific amount of bits is sent via chat message. Cheers can be disabled and the execution method will not be called if the cheer is disabled.

These are the values exported:

NAME TYPE FUNCTION
cheers type<string> A type that has all names of all cheers.
default cheers Map<number, Cheer> All cheers mapped to the specific amount used to activate.
namedcheers Map<string, Cheer> All cheers mapped to the specified internal name.