@raven_app/raven.js 0.0.0-stage → 1.0.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/LICENSE +15 -0
- package/README.md +32 -2
- package/dist/index.cjs +3076 -0
- package/dist/index.mjs +2973 -0
- package/package.json +53 -4
- package/types/index.d.ts +586 -0
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raven_app/raven.js",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "SDK for building Raven bots on https://ravenapp.xyz (REST /api/v1 + live gateway, polling fallback)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./types/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/",
|
|
21
|
+
"types/",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://ravenapp.xyz",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"socket.io-client": "^4.8.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"esbuild": "^0.28.2"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "esbuild src/index.js --bundle --platform=node --packages=external --format=esm --outfile=dist/index.mjs && esbuild src/index.js --bundle --platform=node --packages=external --format=cjs --outfile=dist/index.cjs",
|
|
37
|
+
"prepublishOnly": "npm test && npm run build",
|
|
38
|
+
"test": "node test.js",
|
|
39
|
+
"example:ping": "node examples/ping.js",
|
|
40
|
+
"example:stats": "node examples/stats.js",
|
|
41
|
+
"example:gateway": "node examples/gateway-bot.js",
|
|
42
|
+
"example:showcase": "node examples/showcase-bot.js",
|
|
43
|
+
"example:ethan": "node examples/ethan.js",
|
|
44
|
+
"example:cooldowns": "node examples/redis-cooldown-store.js"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"raven",
|
|
48
|
+
"ravenapp",
|
|
49
|
+
"bot",
|
|
50
|
+
"sdk",
|
|
51
|
+
"chat"
|
|
52
|
+
],
|
|
53
|
+
"author": "andre5338",
|
|
54
|
+
"license": "ISC"
|
|
55
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
export const DEFAULT_BASE_URL: string
|
|
2
|
+
|
|
3
|
+
export interface ClientOptions {
|
|
4
|
+
token: string // `rvb_...`
|
|
5
|
+
timeoutMs?: number
|
|
6
|
+
retryOn429?: boolean
|
|
7
|
+
ethanKey?: string // `rve_...` (EthanPlus/Pro key for client.ethan)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type EthanPersonality = "friendly" | "objective" | "humorous" | "neutral" | "grumpy"
|
|
11
|
+
|
|
12
|
+
export interface EthanChatOptions {
|
|
13
|
+
message?: string
|
|
14
|
+
input?: string // alias for message
|
|
15
|
+
prompt?: string // alias for message
|
|
16
|
+
personality?: EthanPersonality | string // default "neutral"
|
|
17
|
+
reasoning?: boolean
|
|
18
|
+
temperature?: number // 0-100
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface EthanChatResult {
|
|
22
|
+
reply: string
|
|
23
|
+
thinking: string
|
|
24
|
+
model: string
|
|
25
|
+
plan: string | null
|
|
26
|
+
raw: unknown
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const ETHAN_MODEL: string
|
|
30
|
+
export const ETHAN_PERSONALITIES: string[]
|
|
31
|
+
export const ETHAN_MESSAGE_MAX: number
|
|
32
|
+
export const ETHAN_KEY_PREFIX: string
|
|
33
|
+
export function assertPersonality(personality: unknown): string
|
|
34
|
+
export function assertEthanMessage(message: unknown): string
|
|
35
|
+
export function assertTemperature(temperature: unknown): number | undefined
|
|
36
|
+
|
|
37
|
+
export class EthanClient {
|
|
38
|
+
constructor(options: { key: string; timeoutMs?: number; retryOn429?: boolean })
|
|
39
|
+
key: string
|
|
40
|
+
request(method: string, path: string, opts?: { query?: Record<string, unknown>; body?: unknown }): Promise<unknown>
|
|
41
|
+
models(): Promise<{ models: Array<{ id: string; name: string; via: string | null; raw: unknown }>; raw: unknown }>
|
|
42
|
+
chat(message: string | EthanChatOptions, opts?: EthanChatOptions): Promise<EthanChatResult>
|
|
43
|
+
ask(message: string | EthanChatOptions, opts?: EthanChatOptions): Promise<EthanChatResult>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createEthanClient(options: ConstructorParameters<typeof EthanClient>[0]): EthanClient
|
|
47
|
+
|
|
48
|
+
export type BotStatus = "online" | "idle" | "dnd"
|
|
49
|
+
|
|
50
|
+
export interface BotSelf {
|
|
51
|
+
id: string
|
|
52
|
+
username: string
|
|
53
|
+
avatar: string | null
|
|
54
|
+
applicationId: string
|
|
55
|
+
scopes: string[]
|
|
56
|
+
bot: boolean
|
|
57
|
+
status?: string
|
|
58
|
+
statusLocked?: boolean
|
|
59
|
+
raw: unknown
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface Guild {
|
|
63
|
+
id: string
|
|
64
|
+
name: string
|
|
65
|
+
description?: string
|
|
66
|
+
icon: string | null
|
|
67
|
+
ownerId: string
|
|
68
|
+
memberCount: number
|
|
69
|
+
verified?: boolean
|
|
70
|
+
raw: unknown
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface GuildStats {
|
|
74
|
+
guildId: string
|
|
75
|
+
memberCount: number
|
|
76
|
+
[key: string]: unknown
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface Channel {
|
|
80
|
+
id: string
|
|
81
|
+
name: string
|
|
82
|
+
type: string // "text" | "voice" | ...
|
|
83
|
+
position: number
|
|
84
|
+
parentId: string | null
|
|
85
|
+
raw: unknown
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ChannelDetail extends Channel {
|
|
89
|
+
guildId?: string
|
|
90
|
+
topic: string
|
|
91
|
+
icon: string
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ChannelCreateOptions {
|
|
95
|
+
name: string
|
|
96
|
+
type?: "text" | "voice" | string // default "text"
|
|
97
|
+
parentId?: string | null // category id
|
|
98
|
+
topic?: string // max 1024 chars
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ChannelUpdateOptions {
|
|
102
|
+
name?: string
|
|
103
|
+
type?: "text" | "voice" | string
|
|
104
|
+
topic?: string
|
|
105
|
+
parentId?: string | null // "" or null = no category
|
|
106
|
+
position?: number
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ChannelReorderItem {
|
|
110
|
+
id: string
|
|
111
|
+
position?: number
|
|
112
|
+
parentId?: string | null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface DmConversation {
|
|
116
|
+
channelId: string
|
|
117
|
+
counter: number
|
|
118
|
+
unread: number
|
|
119
|
+
lastMessageAt: Date | null
|
|
120
|
+
other: { id: string; username: string; displayName: string | null; avatar: string | null }
|
|
121
|
+
raw?: unknown
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface DmMessage {
|
|
125
|
+
id: string
|
|
126
|
+
channelId: string
|
|
127
|
+
authorId: string
|
|
128
|
+
content: string
|
|
129
|
+
counter?: number
|
|
130
|
+
createdAt: Date
|
|
131
|
+
editedAt?: Date | null
|
|
132
|
+
raw?: unknown
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface DmFetchOptions {
|
|
136
|
+
limit?: number // 1-100, default 50
|
|
137
|
+
before?: number // enc counter cursor
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const CHANNEL_TYPES: string[]
|
|
141
|
+
export function assertChannelType(type: unknown): string
|
|
142
|
+
export function assertChannelName(name: unknown): string
|
|
143
|
+
|
|
144
|
+
export interface Role {
|
|
145
|
+
id: string
|
|
146
|
+
name: string
|
|
147
|
+
color: string
|
|
148
|
+
hoist: boolean
|
|
149
|
+
mentionable: boolean
|
|
150
|
+
position: number
|
|
151
|
+
permissions: number
|
|
152
|
+
managed: boolean
|
|
153
|
+
raw: unknown
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface RoleCreateOptions {
|
|
157
|
+
name: string
|
|
158
|
+
color?: string // "#RRGGBB"
|
|
159
|
+
hoist?: boolean
|
|
160
|
+
mentionable?: boolean
|
|
161
|
+
permissions?: number // bitfield, masked to 0x1fff
|
|
162
|
+
position?: number
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface RoleUpdateOptions {
|
|
166
|
+
name?: string
|
|
167
|
+
color?: string
|
|
168
|
+
hoist?: boolean
|
|
169
|
+
mentionable?: boolean
|
|
170
|
+
permissions?: number
|
|
171
|
+
position?: number
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface MemberRoles {
|
|
175
|
+
userId: string
|
|
176
|
+
roleIds: string[]
|
|
177
|
+
raw?: unknown
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface Member {
|
|
181
|
+
id: string
|
|
182
|
+
username: string
|
|
183
|
+
displayName: string | null
|
|
184
|
+
avatar: string | null
|
|
185
|
+
tag: string
|
|
186
|
+
bio: string
|
|
187
|
+
badges: string[]
|
|
188
|
+
createdAt: Date | null
|
|
189
|
+
joinedAt: Date | null
|
|
190
|
+
roleIds: string[]
|
|
191
|
+
isOwner: boolean
|
|
192
|
+
isBot: boolean
|
|
193
|
+
raw?: unknown
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface MemberListOptions {
|
|
197
|
+
limit?: number // 1-100, default 50
|
|
198
|
+
after?: string // userId cursor
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface MemberListResult {
|
|
202
|
+
members: Member[]
|
|
203
|
+
hasMore: boolean
|
|
204
|
+
raw: unknown
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface BanOptions {
|
|
208
|
+
reason?: string // max 256 chars
|
|
209
|
+
duration?: number | string // seconds or "10m"/"1h"/"7d"/"1w"/"permanent"
|
|
210
|
+
durationSec?: number | string
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface BanResult {
|
|
214
|
+
userId?: string
|
|
215
|
+
reason: string
|
|
216
|
+
expiresAt?: Date | null
|
|
217
|
+
duration: string
|
|
218
|
+
[key: string]: unknown
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface BanEntry {
|
|
222
|
+
userId: string
|
|
223
|
+
reason: string
|
|
224
|
+
bannedBy: string | null
|
|
225
|
+
bannedAt: Date | null
|
|
226
|
+
expiresAt: Date | null
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface HierarchyCheck {
|
|
230
|
+
ok: boolean
|
|
231
|
+
reason: string | null
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export const PERMISSIONS: Record<string, number>
|
|
235
|
+
export const PERMISSION_MASK: number
|
|
236
|
+
export const DEFAULT_EVERYONE_PERMS: number
|
|
237
|
+
export const DEFAULT_ADMIN_PERMS: number
|
|
238
|
+
export function normalizeRole(r: unknown): Role
|
|
239
|
+
export function getHighestRole(roles: Role[], roleIds: string[], isOwner?: boolean): Role | null
|
|
240
|
+
export function getMemberPermissions(roles: Role[], roleIds: string[], isOwner?: boolean): number
|
|
241
|
+
export function hasPermission(roles: Role[], roleIds: string[], permission: number, isOwner?: boolean): boolean
|
|
242
|
+
export function canManageRole(actorRoles: Role[], actorRoleIds: string[], targetRole: Role, opts?: { actorIsOwner?: boolean }): HierarchyCheck
|
|
243
|
+
export function canAssignRole(actorRoles: Role[], actorRoleIds: string[], role: Role, opts?: { actorIsOwner?: boolean }): HierarchyCheck
|
|
244
|
+
export function canModerate(actorRoles: Role[], actorRoleIds: string[], targetRoleIds: string[], opts?: { actorIsOwner?: boolean; targetIsOwner?: boolean; self?: boolean }): HierarchyCheck
|
|
245
|
+
export function sortRoles(roles: Role[]): Role[]
|
|
246
|
+
export function assertRoleName(name: unknown): string
|
|
247
|
+
export function assertRoleColor(color: unknown): string | undefined
|
|
248
|
+
export function assertRolePermissions(permissions: unknown): number | undefined
|
|
249
|
+
|
|
250
|
+
export interface Message {
|
|
251
|
+
id: string
|
|
252
|
+
channelId: string
|
|
253
|
+
guildId?: string
|
|
254
|
+
authorId: string
|
|
255
|
+
isBot?: boolean
|
|
256
|
+
botId?: string | null
|
|
257
|
+
content: string
|
|
258
|
+
createdAt: Date
|
|
259
|
+
editedAt?: Date | null
|
|
260
|
+
raw?: unknown
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface FetchMessagesResult {
|
|
264
|
+
messages: Message[]
|
|
265
|
+
hasMore: boolean
|
|
266
|
+
raw: unknown
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface OAuthInfo {
|
|
270
|
+
clientId: string
|
|
271
|
+
username: string
|
|
272
|
+
scopes: string[]
|
|
273
|
+
authorizeUrl: string
|
|
274
|
+
installed: boolean | null
|
|
275
|
+
raw: unknown
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface PollOptions {
|
|
279
|
+
channelId?: string | string[]
|
|
280
|
+
channelIds?: string | string[]
|
|
281
|
+
channels?: string | string[]
|
|
282
|
+
pollInterval?: number // ms, min 1000, default 3000
|
|
283
|
+
limit?: number // 1-100, default 25
|
|
284
|
+
emitHistory?: boolean
|
|
285
|
+
ignoreBots?: boolean
|
|
286
|
+
selfAuthorId?: string | null
|
|
287
|
+
signal?: AbortSignal | null
|
|
288
|
+
onError?: ((err: Error) => void) | null
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export class MessagePoller {
|
|
292
|
+
on(event: "message", cb: (m: Message) => void): this
|
|
293
|
+
on(event: "error" | "stopped", cb: (e?: unknown) => void): this
|
|
294
|
+
start(): Promise<this>
|
|
295
|
+
stop(): this
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export const GATEWAY_EVENTS: string[]
|
|
299
|
+
export interface GatewayReadyInfo {
|
|
300
|
+
sessionId: string | null
|
|
301
|
+
bot: BotSelf | null
|
|
302
|
+
guilds: string[]
|
|
303
|
+
}
|
|
304
|
+
export class RavenGateway {
|
|
305
|
+
constructor(client: RavenClient, options?: { token?: string; identifyTimeoutMs?: number })
|
|
306
|
+
connected: boolean
|
|
307
|
+
sessionId: string | null
|
|
308
|
+
on(event: "ready", cb: (info: GatewayReadyInfo) => void): this
|
|
309
|
+
on(event: "message:new" | "message:update", cb: (m: Message) => void): this
|
|
310
|
+
on(event: "message:delete", cb: (d: { id: string; channelId: string; guildId?: string }) => void): this
|
|
311
|
+
on(event: "guildCreate" | "guildRemove", cb: (d: { guildId?: string; [key: string]: unknown }) => void): this
|
|
312
|
+
on(event: "roleCreate" | "roleUpdate" | "roleDelete", cb: (d: { guildId?: string; role?: Role; [key: string]: unknown }) => void): this
|
|
313
|
+
on(event: "rolesReordered", cb: (d: { guildId?: string; roles?: Role[]; [key: string]: unknown }) => void): this
|
|
314
|
+
on(event: "memberRolesUpdate", cb: (d: MemberRoles & { guildId?: string; [key: string]: unknown }) => void): this
|
|
315
|
+
on(event: "memberJoin", cb: (d: { guildId?: string; member?: Member; [key: string]: unknown }) => void): this
|
|
316
|
+
on(event: "memberLeave", cb: (d: { guildId?: string; userId?: string; [key: string]: unknown }) => void): this
|
|
317
|
+
on(event: "memberBan" | "memberUnban", cb: (d: { guildId?: string; userId?: string; reason?: string; [key: string]: unknown }) => void): this
|
|
318
|
+
on(event: "channelCreate" | "channelUpdate", cb: (d: { guildId?: string; channel?: ChannelDetail; [key: string]: unknown }) => void): this
|
|
319
|
+
on(event: "channelDelete", cb: (d: { guildId?: string; channelId?: string; [key: string]: unknown }) => void): this
|
|
320
|
+
on(event: "channelsReordered", cb: (d: { guildId?: string; channels?: ChannelDetail[]; [key: string]: unknown }) => void): this
|
|
321
|
+
on(event: "dmCreate", cb: (d: { channelId?: string; [key: string]: unknown }) => void): this
|
|
322
|
+
on(event: "dmMessage", cb: (d: DmMessage & { channelId: string; [key: string]: unknown }) => void): this
|
|
323
|
+
on(event: "dmMessageUpdate", cb: (d: DmMessage & { channelId: string; [key: string]: unknown }) => void): this
|
|
324
|
+
on(event: "dmMessageDelete", cb: (d: { id: string; channelId: string; [key: string]: unknown }) => void): this
|
|
325
|
+
on(event: "commandError", cb: (err: Error, ctx: CommandContext) => void): this
|
|
326
|
+
on(event: "*", cb: (event: string, ...args: unknown[]) => void): this
|
|
327
|
+
on(event: "dispatch", cb: (env: { op: string; t: string; s: number; d: unknown }) => void): this
|
|
328
|
+
on(event: string, cb: (...args: unknown[]) => void): this
|
|
329
|
+
once(event: string, cb: (...args: unknown[]) => void): this
|
|
330
|
+
off(event: string, cb: (...args: unknown[]) => void): this
|
|
331
|
+
connect(): Promise<GatewayReadyInfo>
|
|
332
|
+
send(channelId: string, content: string | { content: string; replyTo?: string; reply_to?: string }): Promise<Message>
|
|
333
|
+
reply(channelId: string, messageId: string, content: string): Promise<Message>
|
|
334
|
+
edit(channelId: string, messageId: string, content: string): Promise<Message>
|
|
335
|
+
delete(channelId: string, messageId: string): Promise<{ id: string }>
|
|
336
|
+
listRoles(guildId: string): Promise<Role[]>
|
|
337
|
+
getRole(guildId: string, roleId: string): Promise<Role>
|
|
338
|
+
createRole(guildId: string, opts: RoleCreateOptions): Promise<Role>
|
|
339
|
+
updateRole(guildId: string, roleId: string, patch: RoleUpdateOptions): Promise<Role | Role[]>
|
|
340
|
+
deleteRole(guildId: string, roleId: string): Promise<{ id: string }>
|
|
341
|
+
reorderRoles(guildId: string, orderedIds: string[]): Promise<Role[]>
|
|
342
|
+
memberRoles(guildId: string, userId: string): Promise<MemberRoles>
|
|
343
|
+
setMemberRoles(guildId: string, userId: string, roleIds: string[]): Promise<MemberRoles>
|
|
344
|
+
listMembers(guildId: string, opts?: MemberListOptions): Promise<MemberListResult>
|
|
345
|
+
getMember(guildId: string, userId: string): Promise<Member>
|
|
346
|
+
kick(guildId: string, userId: string, reason?: string | { reason?: string }): Promise<{ id: string }>
|
|
347
|
+
ban(guildId: string, userId: string, opts?: BanOptions | string): Promise<BanResult>
|
|
348
|
+
unban(guildId: string, userId: string): Promise<{ id: string }>
|
|
349
|
+
bans(guildId: string): Promise<{ bans: BanEntry[]; bannedUserIds: string[] }>
|
|
350
|
+
getChannel(channelId: string): Promise<ChannelDetail>
|
|
351
|
+
createChannel(guildId: string, opts: ChannelCreateOptions): Promise<ChannelDetail>
|
|
352
|
+
updateChannel(channelId: string, patch: ChannelUpdateOptions): Promise<ChannelDetail>
|
|
353
|
+
deleteChannel(channelId: string): Promise<{ id: string }>
|
|
354
|
+
reorderChannels(guildId: string, items: ChannelReorderItem[]): Promise<ChannelDetail[]>
|
|
355
|
+
listDms(): Promise<{ conversations: DmConversation[] }>
|
|
356
|
+
openDm(userId: string): Promise<DmConversation>
|
|
357
|
+
fetchDm(channelId: string, opts?: DmFetchOptions): Promise<{ messages: DmMessage[]; hasMore: boolean }>
|
|
358
|
+
sendDm(channelId: string, content: string): Promise<DmMessage>
|
|
359
|
+
editDm(channelId: string, messageId: string, content: string): Promise<DmMessage>
|
|
360
|
+
deleteDm(channelId: string, messageId: string): Promise<{ id: string }>
|
|
361
|
+
readDm(channelId: string): Promise<{ ok: boolean }>
|
|
362
|
+
setStatus(status: BotStatus | string | null): Promise<{ status: string; locked: boolean }>
|
|
363
|
+
sync(): Promise<{ guilds: string[]; channels: number }>
|
|
364
|
+
disconnect(): this
|
|
365
|
+
attachPoller(poller: MessagePoller): this
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface CommandContext {
|
|
369
|
+
message: Message
|
|
370
|
+
content: string
|
|
371
|
+
args: string[]
|
|
372
|
+
rawArgs: string
|
|
373
|
+
command: string
|
|
374
|
+
authorId: string
|
|
375
|
+
channelId: string
|
|
376
|
+
guildId?: string
|
|
377
|
+
user: { id: string; [key: string]: unknown } | unknown
|
|
378
|
+
guild: { id: string } | null
|
|
379
|
+
channel: { id: string } | null
|
|
380
|
+
reply(content: string): Promise<Message>
|
|
381
|
+
send(content: string): Promise<Message>
|
|
382
|
+
delete(): Promise<{ id: string }>
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface CommandOptions {
|
|
386
|
+
description?: string
|
|
387
|
+
usage?: string
|
|
388
|
+
aliases?: string | string[]
|
|
389
|
+
alias?: string | string[]
|
|
390
|
+
cooldown?: number
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export interface HelpOptions {
|
|
394
|
+
prefix?: boolean | string
|
|
395
|
+
descriptions?: boolean
|
|
396
|
+
command?: string
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface CooldownStore {
|
|
400
|
+
get(key: string): number | string | null | Promise<number | string | null>
|
|
401
|
+
set(key: string, expiresAt: number, ttlMs: number): void | Promise<void>
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export class MemoryCooldownStore implements CooldownStore {
|
|
405
|
+
constructor(options?: { maxKeys?: number })
|
|
406
|
+
get(key: string): number | null
|
|
407
|
+
set(key: string, expiresAt: number): void
|
|
408
|
+
readonly size: number
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export class CommandHandler {
|
|
412
|
+
constructor(options?: { prefix?: string; ignoreBots?: boolean; cooldownStore?: CooldownStore; onUnknown?: (ctx: CommandContext) => void | Promise<void>; onError?: (err: Error, ctx: CommandContext) => void | Promise<void>; onCooldown?: (ctx: CommandContext, waitSeconds: number) => void | Promise<void> })
|
|
413
|
+
command(name: string, fn: (ctx: CommandContext) => void | Promise<void>, opts?: CommandOptions): this
|
|
414
|
+
resolve(name: string): string | null
|
|
415
|
+
suggestCommand(name: string): string | null
|
|
416
|
+
parse(content: string): { name: string; args: string[]; raw: string } | null
|
|
417
|
+
handle(client: RavenClient, message: Message): Promise<boolean>
|
|
418
|
+
attach(client: RavenClient, channelIds: string | string[], pollOptions?: PollOptions): Promise<{ poller: MessagePoller; stop: () => void }>
|
|
419
|
+
help(options?: HelpOptions): string
|
|
420
|
+
helpText(): string
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export function createCommandHandler(options?: ConstructorParameters<typeof CommandHandler>[0]): CommandHandler
|
|
424
|
+
|
|
425
|
+
export interface BotOptions {
|
|
426
|
+
token: string // `rvb_...`
|
|
427
|
+
prefix?: string // default "!"
|
|
428
|
+
status?: BotStatus | string | null // startup status, null = server-managed
|
|
429
|
+
testGuild?: string // test area server (or RAVEN_TEST_GUILD env): errors land in #bot-test / #test / first text channel
|
|
430
|
+
testChannel?: string // explicit bug channel (or RAVEN_TEST_CHANNEL env): wins over testGuild resolution
|
|
431
|
+
timeoutMs?: number
|
|
432
|
+
retryOn429?: boolean
|
|
433
|
+
log?: boolean | ((...args: unknown[]) => void)
|
|
434
|
+
debug?: boolean
|
|
435
|
+
cooldownStore?: CooldownStore
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface BotStartInfo {
|
|
439
|
+
bot: BotSelf | null
|
|
440
|
+
guilds: string[]
|
|
441
|
+
channels: number
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export class RavenBot {
|
|
445
|
+
constructor(options: BotOptions)
|
|
446
|
+
client: RavenClient
|
|
447
|
+
commands: CommandHandler
|
|
448
|
+
errors: { format(err: unknown, opts?: { color?: boolean }): string; suggest(input: unknown, candidates: unknown[]): Suggestion | null }
|
|
449
|
+
started: boolean
|
|
450
|
+
debug: boolean
|
|
451
|
+
testChannelId: string | null
|
|
452
|
+
command(name: string, fn: (ctx: CommandContext) => void | Promise<void>, opts?: CommandOptions): this
|
|
453
|
+
on(event: string, fn: (...args: unknown[]) => void): this
|
|
454
|
+
once(event: string, fn: (...args: unknown[]) => void): this
|
|
455
|
+
off(event: string, fn: (...args: unknown[]) => void): this
|
|
456
|
+
start(): Promise<BotStartInfo>
|
|
457
|
+
stop(): this
|
|
458
|
+
info(): { bot: BotSelf | null; guilds: string[] }
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export function createBot(options: BotOptions): RavenBot
|
|
462
|
+
|
|
463
|
+
export class RavenClient {
|
|
464
|
+
constructor(options: ClientOptions)
|
|
465
|
+
token: string
|
|
466
|
+
ethanKey: string | null
|
|
467
|
+
ethan: EthanClient
|
|
468
|
+
me: {
|
|
469
|
+
get(): Promise<BotSelf>
|
|
470
|
+
setStatus(status: BotStatus | string | null): Promise<{ status: string; locked: boolean; shown: string; raw: unknown }>
|
|
471
|
+
}
|
|
472
|
+
guilds: {
|
|
473
|
+
list(): Promise<Guild[]>
|
|
474
|
+
get(guildId: string): Promise<Guild>
|
|
475
|
+
stats(guildId: string): Promise<GuildStats>
|
|
476
|
+
}
|
|
477
|
+
channels: {
|
|
478
|
+
list(guildId: string): Promise<Channel[]>
|
|
479
|
+
get(channelId: string): Promise<ChannelDetail>
|
|
480
|
+
create(guildId: string, opts: ChannelCreateOptions): Promise<ChannelDetail>
|
|
481
|
+
update(channelId: string, patch: ChannelUpdateOptions): Promise<ChannelDetail>
|
|
482
|
+
delete(channelId: string): Promise<{ id: string }>
|
|
483
|
+
reorder(guildId: string, items: ChannelReorderItem[]): Promise<ChannelDetail[]>
|
|
484
|
+
}
|
|
485
|
+
dms: {
|
|
486
|
+
list(): Promise<{ conversations: DmConversation[]; raw: unknown }>
|
|
487
|
+
open(userId: string): Promise<DmConversation>
|
|
488
|
+
fetch(channelId: string, opts?: DmFetchOptions): Promise<{ messages: DmMessage[]; hasMore: boolean; raw: unknown }>
|
|
489
|
+
fetchAll(channelId: string, opts?: { max?: number; pageSize?: number }): Promise<DmMessage[]>
|
|
490
|
+
send(channelId: string, content: string): Promise<DmMessage>
|
|
491
|
+
edit(channelId: string, messageId: string, content: string): Promise<DmMessage>
|
|
492
|
+
delete(channelId: string, messageId: string): Promise<{ id: string; raw: unknown }>
|
|
493
|
+
read(channelId: string): Promise<{ ok: boolean; raw: unknown }>
|
|
494
|
+
}
|
|
495
|
+
roles: {
|
|
496
|
+
list(guildId: string): Promise<Role[]>
|
|
497
|
+
get(guildId: string, roleId: string): Promise<Role>
|
|
498
|
+
create(guildId: string, opts: RoleCreateOptions): Promise<Role>
|
|
499
|
+
update(guildId: string, roleId: string, patch: RoleUpdateOptions): Promise<Role | Role[]>
|
|
500
|
+
delete(guildId: string, roleId: string): Promise<{ id: string }>
|
|
501
|
+
reorder(guildId: string, orderedIds: string[]): Promise<Role[]>
|
|
502
|
+
memberRoles(guildId: string, userId: string): Promise<MemberRoles>
|
|
503
|
+
setMemberRoles(guildId: string, userId: string, roleIds: string[]): Promise<MemberRoles>
|
|
504
|
+
addMemberRole(guildId: string, userId: string, roleId: string): Promise<MemberRoles>
|
|
505
|
+
removeMemberRole(guildId: string, userId: string, roleId: string): Promise<MemberRoles>
|
|
506
|
+
highestOf(roles: Role[], roleIds: string[], isOwner?: boolean): Role | null
|
|
507
|
+
highestPosition(roles: Role[], roleIds: string[], isOwner?: boolean): number
|
|
508
|
+
memberPermissions(roles: Role[], roleIds: string[], isOwner?: boolean): number
|
|
509
|
+
hasPermission(roles: Role[], roleIds: string[], permission: number, isOwner?: boolean): boolean
|
|
510
|
+
canManage(roles: Role[], actorRoleIds: string[], targetRole: Role, opts?: { actorIsOwner?: boolean }): HierarchyCheck
|
|
511
|
+
canAssign(roles: Role[], actorRoleIds: string[], role: Role, opts?: { actorIsOwner?: boolean }): HierarchyCheck
|
|
512
|
+
canModerate(roles: Role[], actorRoleIds: string[], targetRoleIds: string[], opts?: { actorIsOwner?: boolean; targetIsOwner?: boolean; self?: boolean }): HierarchyCheck
|
|
513
|
+
}
|
|
514
|
+
members: {
|
|
515
|
+
list(guildId: string, opts?: MemberListOptions): Promise<MemberListResult>
|
|
516
|
+
get(guildId: string, userId: string): Promise<Member>
|
|
517
|
+
kick(guildId: string, userId: string, reason?: string | { reason?: string }): Promise<{ id: string; raw: unknown }>
|
|
518
|
+
ban(guildId: string, userId: string, opts?: BanOptions | string): Promise<BanResult>
|
|
519
|
+
unban(guildId: string, userId: string): Promise<{ id: string; raw: unknown }>
|
|
520
|
+
bans(guildId: string): Promise<{ bans: BanEntry[]; bannedUserIds: string[]; raw: unknown }>
|
|
521
|
+
}
|
|
522
|
+
messages: {
|
|
523
|
+
send(channelId: string, content: string | { content: string; replyTo?: string; reply_to?: string }): Promise<Message>
|
|
524
|
+
reply(channelId: string, messageId: string, content: string): Promise<Message>
|
|
525
|
+
edit(channelId: string, messageId: string, content: string): Promise<Message>
|
|
526
|
+
delete(channelId: string, messageId: string): Promise<{ id: string }>
|
|
527
|
+
fetch(channelId: string, opts?: { limit?: number; before?: string }): Promise<FetchMessagesResult>
|
|
528
|
+
fetchAll(channelId: string, opts?: { max?: number; pageSize?: number }): Promise<Message[]>
|
|
529
|
+
}
|
|
530
|
+
oauth: { info(guildId?: string): Promise<OAuthInfo> }
|
|
531
|
+
gateway: RavenGateway
|
|
532
|
+
request(method: string, path: string, opts?: { query?: Record<string, unknown>; body?: unknown }): Promise<unknown>
|
|
533
|
+
onMessage(callback: (m: Message) => void | Promise<void>, opts: PollOptions): Promise<MessagePoller>
|
|
534
|
+
discoverTextChannels(): Promise<Array<{ guild: Guild; channel: Channel }>>
|
|
535
|
+
createCommands(options?: ConstructorParameters<typeof CommandHandler>[0]): CommandHandler
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export function createClient(options: ClientOptions): RavenClient
|
|
539
|
+
|
|
540
|
+
export class RavenError extends Error {
|
|
541
|
+
status: number
|
|
542
|
+
code: string
|
|
543
|
+
details: unknown
|
|
544
|
+
retryAfter: number | null
|
|
545
|
+
endpoint?: string | null
|
|
546
|
+
suggestion?: string
|
|
547
|
+
suggestions?: string[]
|
|
548
|
+
suggestionsHint?: string
|
|
549
|
+
validTitle?: string
|
|
550
|
+
valid?: string[]
|
|
551
|
+
received?: string
|
|
552
|
+
expected?: string
|
|
553
|
+
example?: string
|
|
554
|
+
hints?: string[]
|
|
555
|
+
docs?: string
|
|
556
|
+
}
|
|
557
|
+
export class RavenAPIError extends RavenError { endpoint: string | null }
|
|
558
|
+
export class RavenAuthError extends RavenAPIError {}
|
|
559
|
+
export class RavenPermissionError extends RavenAPIError {}
|
|
560
|
+
export class RavenRateLimitError extends RavenAPIError {}
|
|
561
|
+
export class RavenValidationError extends RavenAPIError {}
|
|
562
|
+
export class RavenNotFoundError extends RavenAPIError {}
|
|
563
|
+
export class AuthenticationError extends RavenError {}
|
|
564
|
+
export class MissingScopeError extends RavenError { scope: string }
|
|
565
|
+
export class NotInstalledError extends RavenError {}
|
|
566
|
+
export class NotFoundError extends RavenError {}
|
|
567
|
+
export class ValidationError extends RavenError {}
|
|
568
|
+
export class RateLimitedError extends RavenError {}
|
|
569
|
+
export class GatewayNotAvailableError extends RavenError {}
|
|
570
|
+
|
|
571
|
+
export function sanitizeContent(s: unknown): string
|
|
572
|
+
export function escapeContent(s: unknown): string
|
|
573
|
+
export function isBotAuthorId(id: unknown): boolean
|
|
574
|
+
export function toCamel(obj: unknown): unknown
|
|
575
|
+
export function parseMentions(content: unknown): { userIds: string[]; everyone: boolean; here: boolean }
|
|
576
|
+
|
|
577
|
+
export interface Suggestion { value: string; distance: number; confidence: number }
|
|
578
|
+
export function editDistance(a: unknown, b: unknown): number
|
|
579
|
+
export function suggest(input: unknown, candidates: unknown[], options?: { limit?: number }): Suggestion | null
|
|
580
|
+
export function suggestAll(input: unknown, candidates: unknown[], options?: { limit?: number }): Suggestion[]
|
|
581
|
+
export function withSuggestions<T extends object>(target: T, label: string): T
|
|
582
|
+
export function formatError(err: unknown, options?: { color?: boolean; baseDir?: string; file?: string; line?: number; column?: number }): string
|
|
583
|
+
export function markDiff(received: unknown, suggested: unknown): string | null
|
|
584
|
+
export function unknownOption(args: { option: string; valid: string[]; label?: string }): RavenError
|
|
585
|
+
export function invalidChoice(args: { label: string; received: string; valid: string[]; validTitle?: string }): RavenError
|
|
586
|
+
export function missingArgument(args: { label: string; param: string; example?: string }): RavenError
|