@tusile/bot 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -90,10 +90,14 @@ await i.acknowledge(); // a press that needs no visible change
90
90
  A private answer is not channel history: nobody else ever sees it, it is not searchable or
91
91
  exportable, and it is gone within a day.
92
92
 
93
- If a handler takes longer than eight seconds, the SDK defers on its behalf rather than let
94
- the window run out. If a handler throws, or returns without answering, the person is told
95
- something went wrong instead of being left watching a spinner, and the error reaches
96
- `bot.on('error')`.
93
+ If a command or form handler takes longer than eight seconds, the SDK defers on its behalf
94
+ rather than let the window run out. A button handler is left alone: a press is answered by
95
+ rewriting the message it sits on, and that is only available before the interaction has
96
+ been answered at all, so deferring for you would trade a late answer for one that cannot be
97
+ given. A slow press should defer and `followUp`.
98
+
99
+ If a handler throws, or returns without answering, the person is told something went wrong
100
+ instead of being left watching a spinner, and the error reaches `bot.on('error')`.
97
101
 
98
102
  ## Embeds and controls
99
103
 
@@ -115,7 +119,7 @@ await i.reply({
115
119
  components: [
116
120
  { type: 'button', style: 'primary', label: 'Press me', custom_id: 'vote:yes' },
117
121
  { type: 'button', style: 'danger', label: 'No', custom_id: 'vote:no' },
118
- { type: 'button', style: 'link', label: 'Docs', url: 'https://tusile.com/bots.html' },
122
+ { type: 'button', style: 'link', label: 'Docs', url: 'https://tusile.com/bots' },
119
123
  ],
120
124
  }],
121
125
  });
@@ -129,8 +133,9 @@ whatever state you need in it: `page:3`, `vote:close:99`. An exactly registered
129
133
  a prefix, and the longest matching prefix wins, so a general handler cannot swallow presses
130
134
  meant for a specific one.
131
135
 
132
- Button styles are `primary`, `secondary`, `success`, `danger` and `link` (which takes a
133
- `url` instead of a `custom_id`). A row can hold five buttons, or one select.
136
+ Button styles are `primary`, `secondary`, `danger` and `link` (which takes a `url` instead
137
+ of a `custom_id`). Anything else draws as a plain button rather than not at all. A row can
138
+ hold five buttons, or one select.
134
139
 
135
140
  ## Forms
136
141
 
@@ -229,6 +234,6 @@ commands, a custom status line, gateway resume after a drop (it reconnects and r
229
234
  instead), and outbound webhooks.
230
235
 
231
236
  Full reference, including every field of an embed, a component and a command option:
232
- **https://tusile.com/bots.html**
237
+ **https://tusile.com/bots**
233
238
 
234
239
  MIT licensed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tusile/bot",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Write a Tusile bot: slash commands, buttons, forms and voice, over an outbound WebSocket.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -27,7 +27,7 @@
27
27
  "chat",
28
28
  "slash-commands"
29
29
  ],
30
- "homepage": "https://tusile.com/bots.html",
30
+ "homepage": "https://tusile.com/bots",
31
31
  "license": "MIT",
32
32
  "author": "Tusile"
33
33
  }
package/src/dispatch.js CHANGED
@@ -120,9 +120,14 @@ export class Dispatcher {
120
120
  *
121
121
  * Cancelled the moment the handler returns, and it checks again before sending: an
122
122
  * unasked-for defer arriving after a normal answer would be refused every time.
123
+ *
124
+ * Not for a press. A press is answered by rewriting the message it sits on, and that is
125
+ * only available before the interaction has been answered at all; after a bare defer the
126
+ * server has no message to edit and refuses. Deferring on the handler's behalf would
127
+ * trade a late answer for one that cannot be given, and leave the buttons live.
123
128
  */
124
129
  #deferAfterAWhile(interaction) {
125
- if (!(this.#autoDeferMs > 0)) return { cancel() {} };
130
+ if (!(this.#autoDeferMs > 0) || interaction.isComponent) return { cancel() {} };
126
131
  const timer = setTimeout(() => {
127
132
  if (interaction.answered) return;
128
133
  interaction.defer().catch((err) => this.#onError(err, interaction));