Commands
A command is a method marked with [Command]. Its parameters are the command’s options, which the
person fills in after the /. Put as many commands as you like in one class and add it with one
call:
using Woosh.Wisp;
public enum Wrap { Plain, [Choice("Gold paper")] Gold }
public sealed class Gifts(Bank bank){ [Command("gift", "Give someone coins")] public async Task Gift( CommandRun run, [Option("Who gets them")] MemberId to, [Option("How many")] int amount, Wrap wrap = Wrap.Plain) { if (!bank.Move(run.User.Id, to, amount)) { await run.AnswerPrivatelyAsync("You don't have that many coins."); return; } var color = wrap == Wrap.Gold ? "#eab308" : "#22c55e"; var giver = Mark.User(run.User.Id); var given = $"{giver} gave {Mark.User(to)} {amount} coins."; var card = new Card(color).Text(given); await run.AnswerAsync($"{run.User} gave {amount} coins.", card); }
[Command("balance", "How many coins you have")] public Task Balance(CommandRun run) => run.AnswerPrivatelyAsync($"You have {bank[run.User.Id]:N0} coins.");}wisp.AddCommands(new Gifts(bank));A command is a name, a description, its options by name, and the function that answers it. The
options are what the person fills in after the /. Declare as many commands as you like together,
in a function of your own:
import { card, mark, text, type Wisp } from "@woosh-no/wisp";
export function gifts(wisp: Wisp, bank: Bank) { wisp.command("gift", "Give someone coins", { to: { kind: "member", description: "Who gets them", required: true }, amount: { kind: "number", description: "How many", required: true }, wrap: { kind: "choice", choices: [{ value: "plain", label: "Plain" }, { value: "gold", label: "Gold paper" }] }, }, async (run) => { const { to, amount, wrap = "plain" } = run.options; if (!bank.move(run.user.id, to, amount)) { await run.answerPrivately("You don't have that many coins."); return; } const color = wrap === "gold" ? "#eab308" : "#22c55e"; const given = `${mark.user(run.user.id)} gave ${mark.user(to)} ${amount} coins.`; await run.answer(`${run.user} gave ${amount} coins.`, card({ color, blocks: [text(given)] })); });
wisp.command("balance", "How many coins you have", (run) => run.answerPrivately(`You have ${bank.coins(run.user.id).toLocaleString("en")} coins.`));}gifts(wisp, bank);Options
Section titled “Options”Each parameter’s type says what the person gives:
| Parameter | What the person gives |
|---|---|
string |
words |
int, long, short, byte |
a whole number |
double, float, decimal |
a number |
MemberId |
a member of the server, picked from a list |
ChannelId, RoleId |
a channel or a role of the server, picked from a list |
| an enum | one of its values (up to 25), picked from a list |
CommandRun |
nothing: the run itself, who ran it and where |
CancellationToken |
nothing: it ends with the run’s 15 seconds |
- An option is required unless its parameter is nullable (
int?,MemberId?) or has a default (int bet = 10). Left out, it takes that default. - Its name is the parameter’s, in lowercase with dashes (
betAmountisbet-amount), and so are an enum’s values.[Option("What it is for")]describes it, andName = "..."renames it.[Choice("Gold paper")]on an enum value changes the words the picker shows. - A number that does not fit its parameter, such as 2.5 for an
int, never reaches your code: the person is told privately and your method does not run.
Mistakes are build errors, where you made them and in plain words. Nothing is looked up when your wisp runs: the library writes the code that adds your commands as your project builds.
Dice.cs(6,58): error WISP003: 'loud' is a Boolean: an option is a string, a number type,MemberId, ChannelId, RoleId or an enum. Woosh has no yes-or-no option: an enum with Yes and Nois a choice.Each option’s kind says what the person gives, and its type in run.options:
kind |
What the person gives | In run.options |
|---|---|---|
text |
words, up to 1,000 characters | a string |
number |
a number | a number |
member, channel, role |
a member, a channel or a role of the server, picked from a list | its id |
choice |
one of its choices (up to 25), picked from a list |
the choice’s value |
- An option is left out unless it is
required: true. Adescriptionsays what it is for, and a choice’slabelis the words the picker shows. - Its name is its key: 1 to 32 of
atoz,0to9,_and-. run.optionsis typed from what you declare:run.options.amountis anumber, and an option that is not required may beundefined.run.signalends with the run’s 15 seconds.
Mistakes are caught where you made them. An option of a kind Woosh does not have is a type error
in your editor, and anything that breaks one of Woosh’s rules throws a WispRuleError in plain
words as you declare it, before your wisp connects:
WispRuleError: An option's kind is text, number, member, channel, role or choice: 'boolean' isnot one. Woosh has no yes-or-no option: a choice of Yes and No is one.A wisp has up to 50 commands, each with up to 10 options.
Answering
Section titled “Answering”A run is answered once, within 15 seconds. The person’s app shows your wisp working on it from the moment they run it, so there is nothing to acknowledge first.
| Answer | Shows |
|---|---|
run.AnswerAsync(text, card?), run.AnswerAsync(card) |
a line in the channel, with “ana used /gift” above it. Returns the line’s id |
run.AnswerPrivatelyAsync(text, card?), run.AnswerPrivatelyAsync(card) |
a private answer: only the person sees it, and Woosh keeps it nowhere |
run.AskAsync(form) |
a form for the person to fill in and send |
run.User is who ran it, run.Channel and run.Server are where. Writing run.User into words
writes the person’s name.
| Answer | Shows |
|---|---|
run.answer(text, card?), run.answer(card) |
a line in the channel, with “ana used /gift” above it. Returns the line’s id |
run.answerPrivately(text, card?), run.answerPrivately(card) |
a private answer: only the person sees it, and Woosh keeps it nowhere |
run.ask(form) |
a form for the person to fill in and send |
run.user is who ran it, run.channel and run.server are where. Writing run.user into words
writes the person’s name.
A line’s words are plain text, and @name in them mentions a member.
Slow work answers first. Answer at once, then edit your own line when the work is done:
var line = await run.AnswerAsync("Drawing a winner...");var winner = await DrawWinnerAsync();await wisp.EditAsync(line, $"The winner is @{winner.Name}!");const line = await run.answer("Drawing a winner...");const winner = await drawWinner();await wisp.edit(line, `The winner is @${winner.name}!`);A run that is not answered within 15 seconds tells the person your wisp did not answer.
Who sees a command
Section titled “Who sees a command”A command is offered in the channels where the server’s admin let your wisp work, and only once your wisp has the Commands item in that server (How a server lets it in). The list people see is the one your wisp sent when it last started.
Commands built from data
Section titled “Commands built from data”When your commands come from data, such as one game per row of a table, build them in a loop:
foreach (var game in games) wisp.Command(game.Name, game.Description) .Number("bet", "Coins to bet", required: true) .Handle(run => game.PlayAsync(run, run.Options.Integer("bet")!.Value));Options: Text, Number, Member, Channel, Role and Choice. Read them with
run.Options.Text("name"), .Number, .Integer, .Member, .Channel, .Role and .Choice.
for (const game of games) { wisp.command(game.name, game.description, { bet: { kind: "number", description: "Coins to bet", required: true }, }, (run) => game.play(run, run.options.bet));}A list that breaks a rule throws as you build it. Woosh takes a new list at most every 15 seconds, so build it once, before your wisp starts.
Writing your own library? The frames underneath are in Commands, raw.