Tagscript

Plugins

Packages that add parsers and transformers for a particular host application.

A plugin is a package of parsers and transformers built for one place TagScript gets embedded. Nothing about a plugin is special to the interpreter. It exports classes, you register the ones you want, and they behave exactly like the built-in ones.

Official plugins

PluginAdds
@tagscript/plugin-discordDiscord tags for embeds, cooldowns, permissions, attachments and timestamps, plus transformers for members, roles, channels and guilds.

Writing one

There is no plugin API to learn. A plugin is a package that exports parsers and transformers, and the host app decides which to register.

Two conventions are worth following, both of which the Discord plugin uses.

Record actions rather than performing them. If your tag needs the host app to do something, write it to ctx.response.actions and return an empty string. That keeps the host in control and keeps your parser testable without mocking whatever it would otherwise call.

Declaration-merge IActions so your fields are typed.

import 'tagscript';

declare module 'tagscript' {
	export interface IActions {
		sendSms?: { body: string; to: string };
	}
}

Importing your package is then enough for response.actions.sendSms to be typed in the host app, with no setup on their side.

IKeyValues merges the same way, for data the host passes into run for your parsers to read.

The plugin-discord source is about 600 lines and is a reasonable thing to copy from.

Last updated on

On this page

Edit on Github