taverns.js 0.2.0

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,144 @@
1
+ "use strict";
2
+ /**
3
+ * taverns.js - Collection
4
+ *
5
+ * A utility class that extends Map with convenience methods,
6
+ * with convenience methods for working with cached data.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Collection = void 0;
10
+ class Collection extends Map {
11
+ /**
12
+ * Find the first value that satisfies the predicate.
13
+ */
14
+ find(fn) {
15
+ for (const [key, value] of this) {
16
+ if (fn(value, key, this))
17
+ return value;
18
+ }
19
+ return undefined;
20
+ }
21
+ /**
22
+ * Filter the collection and return a new Collection with matching entries.
23
+ */
24
+ filter(fn) {
25
+ const result = new Collection();
26
+ for (const [key, value] of this) {
27
+ if (fn(value, key, this))
28
+ result.set(key, value);
29
+ }
30
+ return result;
31
+ }
32
+ /**
33
+ * Map each value in the collection to a new value.
34
+ */
35
+ map(fn) {
36
+ const result = [];
37
+ for (const [key, value] of this) {
38
+ result.push(fn(value, key, this));
39
+ }
40
+ return result;
41
+ }
42
+ /**
43
+ * Check if any value satisfies the predicate.
44
+ */
45
+ some(fn) {
46
+ for (const [key, value] of this) {
47
+ if (fn(value, key, this))
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ /**
53
+ * Check if every value satisfies the predicate.
54
+ */
55
+ every(fn) {
56
+ for (const [key, value] of this) {
57
+ if (!fn(value, key, this))
58
+ return false;
59
+ }
60
+ return true;
61
+ }
62
+ /**
63
+ * Reduce the collection to a single value.
64
+ */
65
+ reduce(fn, initialValue) {
66
+ let accumulator = initialValue;
67
+ for (const [key, value] of this) {
68
+ accumulator = fn(accumulator, value, key, this);
69
+ }
70
+ return accumulator;
71
+ }
72
+ first(count) {
73
+ if (count === undefined) {
74
+ const iter = this.values();
75
+ return iter.next().value;
76
+ }
77
+ if (count < 0)
78
+ return this.last(count * -1);
79
+ count = Math.min(this.size, count);
80
+ const result = [];
81
+ const iter = this.values();
82
+ for (let i = 0; i < count; i++) {
83
+ const next = iter.next();
84
+ if (next.done)
85
+ break;
86
+ result.push(next.value);
87
+ }
88
+ return result;
89
+ }
90
+ last(count) {
91
+ const arr = [...this.values()];
92
+ if (count === undefined)
93
+ return arr[arr.length - 1];
94
+ if (count < 0)
95
+ return this.first(count * -1);
96
+ if (!count)
97
+ return [];
98
+ return arr.slice(-count);
99
+ }
100
+ random(count) {
101
+ const arr = [...this.values()];
102
+ if (count === undefined) {
103
+ return arr[Math.floor(Math.random() * arr.length)];
104
+ }
105
+ return Array.from({ length: Math.min(count, arr.length) }, () => {
106
+ const index = Math.floor(Math.random() * arr.length);
107
+ return arr.splice(index, 1)[0];
108
+ });
109
+ }
110
+ /**
111
+ * Return an array of all values in the collection.
112
+ */
113
+ toArray() {
114
+ return [...this.values()];
115
+ }
116
+ /**
117
+ * Return an array of all keys in the collection.
118
+ */
119
+ keyArray() {
120
+ return [...this.keys()];
121
+ }
122
+ /**
123
+ * Sort the collection by a comparator and return a new Collection.
124
+ */
125
+ sort(compareFn = () => 0) {
126
+ const entries = [...this.entries()].sort((a, b) => compareFn(a[1], b[1], a[0], b[0]));
127
+ const sorted = new Collection();
128
+ for (const [key, value] of entries) {
129
+ sorted.set(key, value);
130
+ }
131
+ return sorted;
132
+ }
133
+ /**
134
+ * Create a Collection from an array using a key extractor.
135
+ */
136
+ static from(items, keyFn) {
137
+ const collection = new Collection();
138
+ for (const item of items) {
139
+ collection.set(keyFn(item), item);
140
+ }
141
+ return collection;
142
+ }
143
+ }
144
+ exports.Collection = Collection;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * taverns.js - Constants
3
+ *
4
+ * API versions, URLs, enums, and event names used throughout the SDK.
5
+ */
6
+ export declare const API_VERSION = "v1";
7
+ export declare const DEFAULT_API_URL = "https://api.tav.gg/api/v1";
8
+ export declare const DEFAULT_WS_URL = "wss://ws.tav.gg";
9
+ export declare const BOT_TOKEN_PREFIX = "tavbot_";
10
+ export declare enum ChannelType {
11
+ TEXT = "TEXT",
12
+ ANNOUNCEMENT = "ANNOUNCEMENT",
13
+ THREAD = "THREAD",
14
+ VOICE = "VOICE",
15
+ MIRROR = "MIRROR",
16
+ FORUM = "FORUM"
17
+ }
18
+ export declare enum MessageStatus {
19
+ SENT = "SENT",
20
+ FILTERED = "FILTERED",
21
+ DELETED = "DELETED"
22
+ }
23
+ export declare enum BotStatus {
24
+ CREATED = "CREATED",
25
+ ACTIVE = "ACTIVE",
26
+ DISABLED = "DISABLED",
27
+ BANNED = "BANNED"
28
+ }
29
+ export declare enum MemberStatus {
30
+ ACTIVE = "ACTIVE",
31
+ PENDING = "PENDING",
32
+ BANNED = "BANNED"
33
+ }
34
+ export declare const GatewayIntents: {
35
+ readonly TAVERN_MESSAGES: bigint;
36
+ readonly MESSAGE_CONTENT: bigint;
37
+ readonly TAVERN_MEMBERS: bigint;
38
+ readonly TAVERN_MODERATION: bigint;
39
+ readonly TAVERN_CHANNELS: bigint;
40
+ readonly TAVERN_THREADS: bigint;
41
+ readonly TAVERN_FORUMS: bigint;
42
+ readonly TAVERN_ROLES: bigint;
43
+ readonly TAVERN_SETTINGS: bigint;
44
+ readonly TAVERN_EVENTS: bigint;
45
+ readonly TAVERN_VOICE: bigint;
46
+ readonly TAVERN_BROADCASTS: bigint;
47
+ readonly TAVERN_TYPING: bigint;
48
+ readonly TAVERN_REACTIONS: bigint;
49
+ readonly TAVERN_PINS: bigint;
50
+ readonly INTERACTIONS: bigint;
51
+ /** All non-privileged intents */
52
+ readonly DEFAULT: 32761n;
53
+ /** All intents including privileged */
54
+ readonly ALL: 65535n;
55
+ };
56
+ export declare enum CommandOptionType {
57
+ STRING = 1,
58
+ INTEGER = 2,
59
+ BOOLEAN = 3,
60
+ USER = 4,
61
+ CHANNEL = 5,
62
+ ROLE = 6,
63
+ NUMBER = 7
64
+ }
65
+ export declare enum GatewayEvent {
66
+ READY = "ready",
67
+ RECONNECTING = "reconnecting",
68
+ DISCONNECTED = "disconnected",
69
+ ERROR = "error",
70
+ DEBUG = "debug",
71
+ MESSAGE_CREATE = "tavern_message",
72
+ MESSAGE_EDIT = "tavern_message_edited",
73
+ MESSAGE_DELETE = "tavern_message_deleted",
74
+ MESSAGES_BULK_DELETE = "tavern_messages_bulk_deleted",
75
+ MESSAGE_PINNED = "tavern_message_pinned",
76
+ MESSAGE_UNPINNED = "tavern_message_unpinned",
77
+ MESSAGE_PUBLISHED = "tavern_message_published",
78
+ MESSAGE_MEDIA_PROCESSED = "tavern_message_media_processed",
79
+ MEMBER_JOINED = "tavern_member_joined",
80
+ MEMBER_LEFT = "tavern_member_left",
81
+ MEMBER_MUTED = "tavern_member_muted",
82
+ MEMBER_UNMUTED = "tavern_member_unmuted",
83
+ CHANNEL_CREATED = "tavern_channel_created",
84
+ CHANNEL_UPDATED = "tavern_channel_updated",
85
+ CHANNEL_DELETED = "tavern_channel_deleted",
86
+ THREAD_CREATED = "tavern_thread_created",
87
+ THREAD_UPDATED = "tavern_thread_updated",
88
+ THREAD_DELETED = "tavern_thread_deleted",
89
+ THREAD_ARCHIVED = "tavern_thread_archived",
90
+ THREAD_MESSAGE = "tavern_thread_message",
91
+ FORUM_POST_CREATED = "tavern_forum_post_created",
92
+ FORUM_SETTINGS_UPDATED = "tavern_forum_settings_updated",
93
+ FORUM_POST_TAGS_UPDATED = "tavern_forum_post_tags_updated",
94
+ ROLE_UPDATED = "tavern_role_updated",
95
+ ROLE_DELETED = "tavern_role_deleted",
96
+ TAVERN_UPDATED = "tavern_updated",
97
+ EVENT_CREATED = "tavern_event_created",
98
+ EVENT_UPDATED = "tavern_event_updated",
99
+ EVENT_DELETED = "tavern_event_deleted",
100
+ EVENT_STARTING = "tavern_event_starting",
101
+ EVENT_ENDED = "tavern_event_ended",
102
+ VOICE_STATE_UPDATE = "tavern_voice_state_update",
103
+ VOICE_SERVER_MUTE = "tavern_voice_server_mute",
104
+ VOICE_USER_DISCONNECTED = "tavern_voice_user_disconnected",
105
+ TYPING_START = "tavern_typing_start",
106
+ TYPING_STOP = "tavern_typing_stop",
107
+ BOT_INSTALLED = "bot_installed",
108
+ BOT_REMOVED = "bot_removed",
109
+ INTERACTION_CREATE = "interaction_create"
110
+ }
111
+ export declare enum GatewayAction {
112
+ HEARTBEAT = "heartbeat",
113
+ TYPING_START = "tavern_typing_start",
114
+ TYPING_STOP = "tavern_typing_stop",
115
+ MARK_READ = "tavern_mark_read"
116
+ }
117
+ export declare const FRIENDLY_EVENT_MAP: Record<string, string>;
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ /**
3
+ * taverns.js - Constants
4
+ *
5
+ * API versions, URLs, enums, and event names used throughout the SDK.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.FRIENDLY_EVENT_MAP = exports.GatewayAction = exports.GatewayEvent = exports.CommandOptionType = exports.GatewayIntents = exports.MemberStatus = exports.BotStatus = exports.MessageStatus = exports.ChannelType = exports.BOT_TOKEN_PREFIX = exports.DEFAULT_WS_URL = exports.DEFAULT_API_URL = exports.API_VERSION = void 0;
9
+ // ─── API Configuration ──────────────────────────────────────
10
+ exports.API_VERSION = 'v1';
11
+ exports.DEFAULT_API_URL = 'https://api.tav.gg/api/v1';
12
+ exports.DEFAULT_WS_URL = 'wss://ws.tav.gg';
13
+ // ─── Bot Token Prefix ────────────────────────────────────────
14
+ exports.BOT_TOKEN_PREFIX = 'tavbot_';
15
+ // ─── Channel Types ───────────────────────────────────────────
16
+ var ChannelType;
17
+ (function (ChannelType) {
18
+ ChannelType["TEXT"] = "TEXT";
19
+ ChannelType["ANNOUNCEMENT"] = "ANNOUNCEMENT";
20
+ ChannelType["THREAD"] = "THREAD";
21
+ ChannelType["VOICE"] = "VOICE";
22
+ ChannelType["MIRROR"] = "MIRROR";
23
+ ChannelType["FORUM"] = "FORUM";
24
+ })(ChannelType || (exports.ChannelType = ChannelType = {}));
25
+ // ─── Message Status ──────────────────────────────────────────
26
+ var MessageStatus;
27
+ (function (MessageStatus) {
28
+ MessageStatus["SENT"] = "SENT";
29
+ MessageStatus["FILTERED"] = "FILTERED";
30
+ MessageStatus["DELETED"] = "DELETED";
31
+ })(MessageStatus || (exports.MessageStatus = MessageStatus = {}));
32
+ // ─── Bot Application Status ─────────────────────────────────
33
+ var BotStatus;
34
+ (function (BotStatus) {
35
+ BotStatus["CREATED"] = "CREATED";
36
+ BotStatus["ACTIVE"] = "ACTIVE";
37
+ BotStatus["DISABLED"] = "DISABLED";
38
+ BotStatus["BANNED"] = "BANNED";
39
+ })(BotStatus || (exports.BotStatus = BotStatus = {}));
40
+ // ─── Member Status ──────────────────────────────────────────
41
+ var MemberStatus;
42
+ (function (MemberStatus) {
43
+ MemberStatus["ACTIVE"] = "ACTIVE";
44
+ MemberStatus["PENDING"] = "PENDING";
45
+ MemberStatus["BANNED"] = "BANNED";
46
+ })(MemberStatus || (exports.MemberStatus = MemberStatus = {}));
47
+ // ─── Gateway Intents ────────────────────────────────────────
48
+ // Bitfield values controlling which events the bot receives.
49
+ // Pass a combination of these to the Client constructor to filter events.
50
+ exports.GatewayIntents = {
51
+ TAVERN_MESSAGES: 1n << 0n,
52
+ MESSAGE_CONTENT: 1n << 1n, // Privileged
53
+ TAVERN_MEMBERS: 1n << 2n, // Privileged
54
+ TAVERN_MODERATION: 1n << 3n,
55
+ TAVERN_CHANNELS: 1n << 4n,
56
+ TAVERN_THREADS: 1n << 5n,
57
+ TAVERN_FORUMS: 1n << 6n,
58
+ TAVERN_ROLES: 1n << 7n,
59
+ TAVERN_SETTINGS: 1n << 8n,
60
+ TAVERN_EVENTS: 1n << 9n,
61
+ TAVERN_VOICE: 1n << 10n,
62
+ TAVERN_BROADCASTS: 1n << 11n,
63
+ TAVERN_TYPING: 1n << 12n,
64
+ TAVERN_REACTIONS: 1n << 13n,
65
+ TAVERN_PINS: 1n << 14n,
66
+ INTERACTIONS: 1n << 15n,
67
+ /** All non-privileged intents */
68
+ DEFAULT: 0x7ff9n,
69
+ /** All intents including privileged */
70
+ ALL: 0xffffn,
71
+ };
72
+ // ─── Command Option Types ───────────────────────────────────
73
+ // Types for slash command options.
74
+ var CommandOptionType;
75
+ (function (CommandOptionType) {
76
+ CommandOptionType[CommandOptionType["STRING"] = 1] = "STRING";
77
+ CommandOptionType[CommandOptionType["INTEGER"] = 2] = "INTEGER";
78
+ CommandOptionType[CommandOptionType["BOOLEAN"] = 3] = "BOOLEAN";
79
+ CommandOptionType[CommandOptionType["USER"] = 4] = "USER";
80
+ CommandOptionType[CommandOptionType["CHANNEL"] = 5] = "CHANNEL";
81
+ CommandOptionType[CommandOptionType["ROLE"] = 6] = "ROLE";
82
+ CommandOptionType[CommandOptionType["NUMBER"] = 7] = "NUMBER";
83
+ })(CommandOptionType || (exports.CommandOptionType = CommandOptionType = {}));
84
+ // ─── Gateway Events ─────────────────────────────────────────
85
+ // Events emitted by the WebSocket gateway that bots can listen to.
86
+ var GatewayEvent;
87
+ (function (GatewayEvent) {
88
+ // Connection lifecycle
89
+ GatewayEvent["READY"] = "ready";
90
+ GatewayEvent["RECONNECTING"] = "reconnecting";
91
+ GatewayEvent["DISCONNECTED"] = "disconnected";
92
+ GatewayEvent["ERROR"] = "error";
93
+ GatewayEvent["DEBUG"] = "debug";
94
+ // Messages
95
+ GatewayEvent["MESSAGE_CREATE"] = "tavern_message";
96
+ GatewayEvent["MESSAGE_EDIT"] = "tavern_message_edited";
97
+ GatewayEvent["MESSAGE_DELETE"] = "tavern_message_deleted";
98
+ GatewayEvent["MESSAGES_BULK_DELETE"] = "tavern_messages_bulk_deleted";
99
+ GatewayEvent["MESSAGE_PINNED"] = "tavern_message_pinned";
100
+ GatewayEvent["MESSAGE_UNPINNED"] = "tavern_message_unpinned";
101
+ GatewayEvent["MESSAGE_PUBLISHED"] = "tavern_message_published";
102
+ GatewayEvent["MESSAGE_MEDIA_PROCESSED"] = "tavern_message_media_processed";
103
+ // Members
104
+ GatewayEvent["MEMBER_JOINED"] = "tavern_member_joined";
105
+ GatewayEvent["MEMBER_LEFT"] = "tavern_member_left";
106
+ GatewayEvent["MEMBER_MUTED"] = "tavern_member_muted";
107
+ GatewayEvent["MEMBER_UNMUTED"] = "tavern_member_unmuted";
108
+ // Channels
109
+ GatewayEvent["CHANNEL_CREATED"] = "tavern_channel_created";
110
+ GatewayEvent["CHANNEL_UPDATED"] = "tavern_channel_updated";
111
+ GatewayEvent["CHANNEL_DELETED"] = "tavern_channel_deleted";
112
+ // Threads
113
+ GatewayEvent["THREAD_CREATED"] = "tavern_thread_created";
114
+ GatewayEvent["THREAD_UPDATED"] = "tavern_thread_updated";
115
+ GatewayEvent["THREAD_DELETED"] = "tavern_thread_deleted";
116
+ GatewayEvent["THREAD_ARCHIVED"] = "tavern_thread_archived";
117
+ GatewayEvent["THREAD_MESSAGE"] = "tavern_thread_message";
118
+ // Forum
119
+ GatewayEvent["FORUM_POST_CREATED"] = "tavern_forum_post_created";
120
+ GatewayEvent["FORUM_SETTINGS_UPDATED"] = "tavern_forum_settings_updated";
121
+ GatewayEvent["FORUM_POST_TAGS_UPDATED"] = "tavern_forum_post_tags_updated";
122
+ // Roles
123
+ GatewayEvent["ROLE_UPDATED"] = "tavern_role_updated";
124
+ GatewayEvent["ROLE_DELETED"] = "tavern_role_deleted";
125
+ // Tavern
126
+ GatewayEvent["TAVERN_UPDATED"] = "tavern_updated";
127
+ // Events
128
+ GatewayEvent["EVENT_CREATED"] = "tavern_event_created";
129
+ GatewayEvent["EVENT_UPDATED"] = "tavern_event_updated";
130
+ GatewayEvent["EVENT_DELETED"] = "tavern_event_deleted";
131
+ GatewayEvent["EVENT_STARTING"] = "tavern_event_starting";
132
+ GatewayEvent["EVENT_ENDED"] = "tavern_event_ended";
133
+ // Voice
134
+ GatewayEvent["VOICE_STATE_UPDATE"] = "tavern_voice_state_update";
135
+ GatewayEvent["VOICE_SERVER_MUTE"] = "tavern_voice_server_mute";
136
+ GatewayEvent["VOICE_USER_DISCONNECTED"] = "tavern_voice_user_disconnected";
137
+ // Typing
138
+ GatewayEvent["TYPING_START"] = "tavern_typing_start";
139
+ GatewayEvent["TYPING_STOP"] = "tavern_typing_stop";
140
+ // Bot lifecycle
141
+ GatewayEvent["BOT_INSTALLED"] = "bot_installed";
142
+ GatewayEvent["BOT_REMOVED"] = "bot_removed";
143
+ // Interactions (slash commands)
144
+ GatewayEvent["INTERACTION_CREATE"] = "interaction_create";
145
+ })(GatewayEvent || (exports.GatewayEvent = GatewayEvent = {}));
146
+ // ─── WebSocket Actions ──────────────────────────────────────
147
+ // Actions the bot can send to the gateway.
148
+ var GatewayAction;
149
+ (function (GatewayAction) {
150
+ GatewayAction["HEARTBEAT"] = "heartbeat";
151
+ GatewayAction["TYPING_START"] = "tavern_typing_start";
152
+ GatewayAction["TYPING_STOP"] = "tavern_typing_stop";
153
+ GatewayAction["MARK_READ"] = "tavern_mark_read";
154
+ })(GatewayAction || (exports.GatewayAction = GatewayAction = {}));
155
+ // ─── Friendly Event Name Map ────────────────────────────────
156
+ // Maps gateway wire events to friendly SDK event names.
157
+ exports.FRIENDLY_EVENT_MAP = {
158
+ [GatewayEvent.MESSAGE_CREATE]: 'messageCreate',
159
+ [GatewayEvent.MESSAGE_EDIT]: 'messageUpdate',
160
+ [GatewayEvent.MESSAGE_DELETE]: 'messageDelete',
161
+ [GatewayEvent.MESSAGES_BULK_DELETE]: 'messageDeleteBulk',
162
+ [GatewayEvent.MESSAGE_PINNED]: 'messagePinned',
163
+ [GatewayEvent.MESSAGE_UNPINNED]: 'messageUnpinned',
164
+ [GatewayEvent.MESSAGE_PUBLISHED]: 'messagePublished',
165
+ [GatewayEvent.MEMBER_JOINED]: 'memberJoin',
166
+ [GatewayEvent.MEMBER_LEFT]: 'memberLeave',
167
+ [GatewayEvent.MEMBER_MUTED]: 'memberMuted',
168
+ [GatewayEvent.MEMBER_UNMUTED]: 'memberUnmuted',
169
+ [GatewayEvent.CHANNEL_CREATED]: 'channelCreate',
170
+ [GatewayEvent.CHANNEL_UPDATED]: 'channelUpdate',
171
+ [GatewayEvent.CHANNEL_DELETED]: 'channelDelete',
172
+ [GatewayEvent.THREAD_CREATED]: 'threadCreate',
173
+ [GatewayEvent.THREAD_UPDATED]: 'threadUpdate',
174
+ [GatewayEvent.THREAD_DELETED]: 'threadDelete',
175
+ [GatewayEvent.THREAD_ARCHIVED]: 'threadArchived',
176
+ [GatewayEvent.ROLE_UPDATED]: 'roleUpdate',
177
+ [GatewayEvent.ROLE_DELETED]: 'roleDelete',
178
+ [GatewayEvent.TAVERN_UPDATED]: 'tavernUpdate',
179
+ [GatewayEvent.EVENT_CREATED]: 'eventCreate',
180
+ [GatewayEvent.EVENT_UPDATED]: 'eventUpdate',
181
+ [GatewayEvent.EVENT_DELETED]: 'eventDelete',
182
+ [GatewayEvent.EVENT_STARTING]: 'eventStarting',
183
+ [GatewayEvent.EVENT_ENDED]: 'eventEnded',
184
+ [GatewayEvent.VOICE_STATE_UPDATE]: 'voiceStateUpdate',
185
+ [GatewayEvent.TYPING_START]: 'typingStart',
186
+ [GatewayEvent.TYPING_STOP]: 'typingStop',
187
+ [GatewayEvent.BOT_INSTALLED]: 'botInstalled',
188
+ [GatewayEvent.BOT_REMOVED]: 'botRemoved',
189
+ [GatewayEvent.INTERACTION_CREATE]: 'interactionCreate',
190
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * taverns.js - Embed Types & Builder
3
+ *
4
+ * Types and a fluent builder for creating rich embed content
5
+ * in messages and interaction replies.
6
+ */
7
+ export interface EmbedImage {
8
+ url: string;
9
+ width?: number;
10
+ height?: number;
11
+ }
12
+ export interface EmbedFooter {
13
+ text: string;
14
+ iconUrl?: string;
15
+ }
16
+ export interface EmbedField {
17
+ name: string;
18
+ value: string;
19
+ inline?: boolean;
20
+ }
21
+ export interface Embed {
22
+ title?: string;
23
+ description?: string;
24
+ color?: string;
25
+ fields?: EmbedField[];
26
+ footer?: EmbedFooter;
27
+ thumbnail?: EmbedImage;
28
+ image?: EmbedImage;
29
+ }
30
+ export declare class EmbedBuilder {
31
+ private readonly data;
32
+ setTitle(title: string): this;
33
+ setDescription(description: string): this;
34
+ setColor(hex: string): this;
35
+ addField(name: string, value: string, inline?: boolean): this;
36
+ setFooter(text: string, iconUrl?: string): this;
37
+ setThumbnail(url: string): this;
38
+ setImage(url: string): this;
39
+ toJSON(): Embed;
40
+ }
package/dist/embed.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /**
3
+ * taverns.js - Embed Types & Builder
4
+ *
5
+ * Types and a fluent builder for creating rich embed content
6
+ * in messages and interaction replies.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EmbedBuilder = void 0;
10
+ class EmbedBuilder {
11
+ constructor() {
12
+ this.data = {};
13
+ }
14
+ setTitle(title) { this.data.title = title; return this; }
15
+ setDescription(description) { this.data.description = description; return this; }
16
+ setColor(hex) { this.data.color = hex; return this; }
17
+ addField(name, value, inline = false) {
18
+ var _a;
19
+ ((_a = this.data).fields ?? (_a.fields = [])).push({ name, value, inline });
20
+ return this;
21
+ }
22
+ setFooter(text, iconUrl) {
23
+ this.data.footer = { text, iconUrl };
24
+ return this;
25
+ }
26
+ setThumbnail(url) { this.data.thumbnail = { url }; return this; }
27
+ setImage(url) { this.data.image = { url }; return this; }
28
+ toJSON() { return { ...this.data }; }
29
+ }
30
+ exports.EmbedBuilder = EmbedBuilder;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * taverns.js - Gateway (WebSocket Client)
3
+ *
4
+ * Manages the WebSocket connection to the Tavern gateway.
5
+ * Handles authentication, heartbeats, auto-reconnection with exponential
6
+ * backoff, and event dispatching.
7
+ */
8
+ import { EventEmitter } from 'events';
9
+ export interface GatewayOptions {
10
+ /** Bot token (tavbot_...) */
11
+ token: string;
12
+ /** WebSocket URL (default: wss://ws.tav.gg) */
13
+ url?: string;
14
+ /** Heartbeat interval in milliseconds (default: 30000) */
15
+ heartbeatInterval?: number;
16
+ /** Whether to auto-reconnect on disconnect (default: true) */
17
+ autoReconnect?: boolean;
18
+ /** Maximum reconnect attempts before giving up (default: Infinity) */
19
+ maxReconnectAttempts?: number;
20
+ /** Gateway intents bitfield (session-level filtering, not persisted) */
21
+ intents?: bigint;
22
+ }
23
+ export declare class Gateway extends EventEmitter {
24
+ private ws;
25
+ private heartbeatTimer;
26
+ private reconnectTimer;
27
+ private state;
28
+ private reconnectAttempts;
29
+ private destroyed;
30
+ private token;
31
+ private readonly url;
32
+ private readonly heartbeatInterval;
33
+ private autoReconnect;
34
+ private readonly maxReconnectAttempts;
35
+ private readonly intents?;
36
+ constructor(options: GatewayOptions);
37
+ /** Whether the gateway is currently connected. */
38
+ get connected(): boolean;
39
+ /** Update the bot token (used when login() provides a new token). */
40
+ setToken(token: string): void;
41
+ /**
42
+ * Connect to the gateway.
43
+ * Resolves once the WebSocket connection is open.
44
+ */
45
+ connect(): Promise<void>;
46
+ /**
47
+ * Send a JSON message to the gateway.
48
+ */
49
+ send(action: string, data?: unknown): void;
50
+ /**
51
+ * Gracefully disconnect and clean up. The gateway cannot be reused after this.
52
+ */
53
+ destroy(): void;
54
+ /**
55
+ * Disconnect without destroying (allows reconnection).
56
+ */
57
+ disconnect(): void;
58
+ private onMessage;
59
+ private onClose;
60
+ private onError;
61
+ private startHeartbeat;
62
+ private stopHeartbeat;
63
+ private scheduleReconnect;
64
+ private cleanup;
65
+ }