# tick bot SDK

Build bots for **tick** (https://tick.miowawa.de) — they sit at the table, play, chat and answer slash commands.

## 1. Get a key

You need a **developer account** (ask the owner). Sign in on the website (your name → *Staff*), open **Developers**, and create a bot. You get a key like `tkb_1a2b3c4d5e_…` — it's shown once. Each bot has its own name, picture and about text.

Keep the key secret: put it in an environment variable (`TICK_BOT_KEY`). Never share, sell or trade keys.

## 2. Connect

```js
const { TickBot } = require("./tick-bot");          // Node 18+ (Node 22+ needs no extra package, older: npm i ws)
const bot = await TickBot.connect({ key: process.env.TICK_BOT_KEY });
console.log(bot.name, bot.kind);                    // "bot"
```

The bot reconnects by itself after a dropped connection or a server restart, and rejoins its rooms.

## Rooms

- `bot.rooms.create({ name, lang, isPublic })` — rooms a bot creates always allow bots; the bot is the host.
- `bot.rooms.join(code)` — only works if the room has **Allow bots** turned on (off by default).
- `bot.on("invite", inv => inv.accept())` — players can invite online bots (People → *Invite a bot*).
- A bot can sit in up to **10 rooms**, once each.

```js
room.sit(); room.stand(); room.leave();
room.say("text");                                    // plain chat
room.post({ text, embed, buttons });                 // bot message (max 6 unprompted posts per minute per room)
room.edit(messageId, { text, embed, buttons });      // edit your own message
// host only:
room.start(); room.end(); room.settings({ lang: "de", difficulty: "hard" }); room.setPublic(false);
room.title("New name"); room.kick(playerId); room.giveHost(playerId);
```

Room events: `state` (full room), `gameStart`, `gameEnd` `{ winner }`, `turn` (your turn), `anyTurn`, `typing` `{ player, text }`,
`word` `{ player, word, ok, reason }`, `hurt` `{ player, prompt }`, `chat` `{ id, from, text, embed, system }`, `kicked`, `left`, `error`.

## Playing

```js
room.on("turn", turn => {
  const word = myWords.find(w => turn.matches(w));   // turn.prompt = the letters on the bomb
  turn.play(word, { cpm: 300, mistakes: 0.02 });     // types letter by letter, then submits
});
// or simply:
room.autoplay(myWords, { cpm: 280 });
```

Bring your own word list. Prompts, accepted words and the room's language are in `room.state`.

## Slash commands

```js
bot.commands.set([
  { name: "roll", description: "Roll a die", options: [{ name: "sides", type: "number" }] },
]);
bot.on("command", cmd => cmd.reply(`You rolled ${1 + Math.floor(Math.random() * (cmd.options.sides || 6))}`));
```

- Up to **25** commands. Option types: `text`, `number`, `player` (→ `{ id, name }`), `choice` (with `choices: [...]`). `required: true` makes an option mandatory.
- Players type `/roll 20` in the room chat. Only rooms where your bot sits get your commands.
- Answer with `cmd.reply(text | { text, embed, buttons, ephemeral })` — **one answer**, within **14 seconds**. `ephemeral: true` shows it only to that player.

## Embeds and buttons

```js
{ embed: { title, description, color: "#f2a541", footer, fields: [{ name, value, inline }] },
  buttons: [{ id: "yes", label: "Yes", style: "primary" }] }   // styles: primary, secondary, danger
```

Limits: title 256, description 2000, up to 10 fields (name 64, value 512), footer 128, up to 5 buttons (label 40). Text 2000.

A button press arrives as `bot.on("button", press => …)` with `press.buttonId`, `press.messageId`, `press.user`. Answer once with `press.reply(…)` or change the original message with `press.update(…)`.

## Limits

| What | Limit |
|---|---|
| Messages to the server | 120 per minute |
| Room joins | 10 per minute |
| Room creations | 5 per minute |
| Unprompted posts | 6 per minute per room |
| Answers | 1 per command / button press, within 14 s |
| Players running commands / pressing buttons | 8 per 10 s each |

Errors come with a `code`, e.g. `RATE_LIMITED`, `JOIN_TOO_FAST` (with `retryAfterMs`), `BOTS_NOT_ALLOWED`, `ROOM_NOT_FOUND`, `INTERACTION_EXPIRED`, `ALREADY_ANSWERED`, `INVALID_KEY`, `BOTS_DISABLED`.

## Rules

Not allowed:
- cheats or anything that helps a human win: solvers, word finders, hint tools, auto typers, anything that plays for a human
- sending live prompts, answers or hints to players during a game
- spam: flooding rooms with posts or commands, mass invites
- collecting player data beyond what the bot needs, or publishing/selling it
- impersonating staff, players or other bots
- evading bans, rate limits or the kill switch

Welcome: fair-play bots in bot-friendly rooms, chat bots, stat trackers, fun commands.

Every bot shows a **BOT** badge. Breaking the rules leads to key resets, bot bans and a ban of the developer account with all its bots. If a developer account is removed, all its bots stop working. Staff can switch all bots off at any time (`BOTS_DISABLED`).

## Examples

- [`examples/autoplayer.js`](examples/autoplayer.js) — creates a room, follows invites, plays with a word list
- [`examples/chatbot.js`](examples/chatbot.js) — slash commands, embed replies and a button poll
