@satorijs/adapter-discord 4.3.1 → 4.5.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.
package/src/message.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Context, Dict, h, MessageEncoder, Quester, Schema, Universal } from '@satorijs/satori'
1
+ import { Context, Dict, h, MessageEncoder, Schema, Universal } from '@satorijs/core'
2
2
  import { DiscordBot } from './bot'
3
3
  import { ActionRow, Button, ButtonStyles, Channel, ComponentType, Message } from './types'
4
4
  import { decodeMessage, sanitize } from './utils'
@@ -70,7 +70,7 @@ export class DiscordMessageEncoder<C extends Context = Context> extends MessageE
70
70
 
71
71
  return message
72
72
  } catch (e) {
73
- if (Quester.Error.is(e) && e.response) {
73
+ if (this.bot.http.isError(e) && e.response) {
74
74
  if (e.response.data?.code === 10015) {
75
75
  this.bot.logger.debug('webhook has been deleted, recreating..., %o', e.response.data)
76
76
  if (!this.bot.webhookLock[this.channelId]) this.bot.webhooks[this.channelId] = null
@@ -88,7 +88,8 @@ export class DiscordMessageEncoder<C extends Context = Context> extends MessageE
88
88
  const { filename, data, mime } = await this.bot.ctx.http.file(attrs.src || attrs.url, attrs)
89
89
  const form = new FormData()
90
90
  const value = new Blob([data], { type: mime })
91
- form.append('file', value, attrs.file || filename)
91
+ // https://discord.com/developers/docs/reference#uploading-files
92
+ form.append('files[0]', value, attrs.file || filename)
92
93
  form.append('payload_json', JSON.stringify(payload))
93
94
  return this.post(form)
94
95
  }
@@ -300,7 +301,15 @@ export class DiscordMessageEncoder<C extends Context = Context> extends MessageE
300
301
  } else if (type === 'audio') {
301
302
  await this.sendAsset('file', attrs, {
302
303
  ...this.addition,
303
- content: this.buffer.trim(),
304
+ content: '',
305
+ attachments: [
306
+ {
307
+ waveform: '', // base64 encoded bytearray representing a sampled waveform
308
+ id: 0,
309
+ duration_secs: attrs.duration ?? 0,
310
+ },
311
+ ],
312
+ flags: Message.Flag.IS_VOICE_MESSAGE,
304
313
  })
305
314
  this.buffer = ''
306
315
  } else if (type === 'author') {
@@ -1,13 +1,13 @@
1
- import { Dict, makeArray, Quester } from '@satorijs/satori'
1
+ import { Dict, HTTP, makeArray } from '@satorijs/core'
2
2
  import { DiscordBot } from '../bot'
3
3
 
4
4
  export class Internal {
5
5
  constructor(private bot: DiscordBot) {}
6
6
 
7
- static define(routes: Dict<Partial<Record<Quester.Method, string | string[]>>>) {
7
+ static define(routes: Dict<Partial<Record<HTTP.Method, string | string[]>>>) {
8
8
  for (const path in routes) {
9
9
  for (const key in routes[path]) {
10
- const method = key as Quester.Method
10
+ const method = key as HTTP.Method
11
11
  for (const name of makeArray(routes[path][method])) {
12
12
  Internal.prototype[name] = async function (this: Internal, ...args: any[]) {
13
13
  const raw = args.join(', ')
@@ -15,7 +15,7 @@ export class Internal {
15
15
  if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`)
16
16
  return args.shift()
17
17
  })
18
- const config: Quester.RequestConfig = {}
18
+ const config: HTTP.RequestConfig = {}
19
19
  if (args.length === 1) {
20
20
  if (method === 'GET' || method === 'DELETE') {
21
21
  config.params = args[0]
@@ -32,7 +32,7 @@ export class Internal {
32
32
  this.bot.logger.debug(`${method} ${url}`, config)
33
33
  return (await this.bot.http(method, url, config)).data
34
34
  } catch (error) {
35
- if (!Quester.Error.is(error) || !error.response) throw error
35
+ if (!this.bot.http.isError(error) || !error.response) throw error
36
36
  throw new Error(`[${error.response.status}] ${JSON.stringify(error.response.data)}`)
37
37
  }
38
38
  }
@@ -134,6 +134,10 @@ export namespace Message {
134
134
  LOADING = 1 << 7,
135
135
  /** this message failed to mention some roles and add their members to the thread */
136
136
  FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8,
137
+ /** this message will not trigger push and desktop notifications */
138
+ SUPPRESS_NOTIFICATIONS = 1 << 12,
139
+ /** this message is a voice message */
140
+ IS_VOICE_MESSAGE = 1 << 13,
137
141
  }
138
142
 
139
143
  /** https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure */
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Context, Dict, h, pick, Session, Universal, valueMap } from '@satorijs/satori'
1
+ import { Context, Dict, h, pick, Session, Universal, valueMap } from '@satorijs/core'
2
2
  import { DiscordBot } from './bot'
3
3
  import * as Discord from './types'
4
4
 
package/src/ws.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Adapter, Context, Schema } from '@satorijs/satori'
1
+ import { Adapter, Context, Schema } from '@satorijs/core'
2
2
  import { Gateway } from './types'
3
3
  import { adaptSession, decodeUser } from './utils'
4
4
  import { DiscordBot } from './bot'