pikiclaw 0.2.35

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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Channel base — minimal abstract for all IM platforms.
3
+ *
4
+ * Only defines: lifecycle + outgoing primitives.
5
+ * Hooks (onCommand, onMessage, onCallback, ...) are platform-specific
6
+ * and belong in each subclass — different IMs expose different interaction models.
7
+ */
8
+ export const DEFAULT_CHANNEL_CAPABILITIES = Object.freeze({
9
+ editMessages: false,
10
+ typingIndicators: false,
11
+ commandMenu: false,
12
+ callbackActions: false,
13
+ messageReactions: false,
14
+ fileUpload: false,
15
+ fileDownload: false,
16
+ threads: false,
17
+ });
18
+ export class Channel {
19
+ bot = null;
20
+ capabilities = DEFAULT_CHANNEL_CAPABILITIES;
21
+ async setMenu(_commands) { }
22
+ async clearMenu() { }
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // Shared helpers
26
+ // ---------------------------------------------------------------------------
27
+ export function supportsChannelCapability(channel, capability) {
28
+ return channel?.capabilities?.[capability] ?? false;
29
+ }
30
+ export function splitText(text, max) {
31
+ if (text.length <= max)
32
+ return [text];
33
+ const chunks = [];
34
+ let rest = text;
35
+ while (rest.length > max) {
36
+ let cut = rest.lastIndexOf('\n', max);
37
+ if (cut < max * 0.3)
38
+ cut = max;
39
+ chunks.push(rest.slice(0, cut));
40
+ rest = rest.slice(cut);
41
+ }
42
+ if (rest)
43
+ chunks.push(rest);
44
+ return chunks;
45
+ }
46
+ export function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }