Skip to content

Commit

Permalink
fix(adapter): fix adapters do not support send options
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 10, 2023
1 parent dfb951d commit da47c88
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion adapters/discord/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-discord",
"description": "Discord Adapter for Satorijs",
"version": "3.4.0",
"version": "3.4.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
10 changes: 5 additions & 5 deletions adapters/discord/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Fragment, Quester, Schema, segment } from '@satorijs/satori'
import { Bot, Context, Fragment, Quester, Schema, SendOptions, segment } from '@satorijs/satori'
import { adaptChannel, adaptGuild, adaptMessage, adaptUser } from './utils'
import { DiscordMessenger } from './message'
import { Internal } from './types'
Expand Down Expand Up @@ -26,12 +26,12 @@ export class DiscordBot extends Bot<DiscordBot.Config> {
return adaptUser(data)
}

async sendMessage(channelId: string, content: Fragment, guildId?: string) {
return new DiscordMessenger(this, channelId, guildId).send(content)
async sendMessage(channelId: string, content: Fragment, guildId?: string, options?: SendOptions) {
return new DiscordMessenger(this, channelId, guildId, options).send(content)
}

async sendPrivateMessage(channelId: string, content: Fragment) {
return new DiscordMessenger(this, channelId).send(content)
async sendPrivateMessage(channelId: string, content: Fragment, options?: SendOptions) {
return new DiscordMessenger(this, channelId, null, options).send(content)
}

async deleteMessage(channelId: string, messageId: string) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/feishu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-feishu",
"description": "Feishu Adapter for Satorijs",
"version": "1.1.0",
"version": "1.1.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
10 changes: 5 additions & 5 deletions adapters/feishu/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Logger, Quester, Schema } from '@satorijs/satori'
import { Bot, Context, Logger, Quester, Schema, SendOptions } from '@satorijs/satori'

import { HttpServer } from './http'
import { FeishuMessenger } from './message'
Expand Down Expand Up @@ -59,12 +59,12 @@ export class FeishuBot extends Bot<FeishuBot.Config> {
this.http.config.headers.Authorization = `Bearer ${v}`
}

async sendMessage(channelId: string, content: string, guildId?: string): Promise<string[]> {
return new FeishuMessenger(this, channelId, guildId).send(content)
async sendMessage(channelId: string, content: string, guildId?: string, options?: SendOptions): Promise<string[]> {
return new FeishuMessenger(this, channelId, guildId, options).send(content)
}

async sendPrivateMessage(userId: string, content: string): Promise<string[]> {
return this.sendMessage(userId, content)
async sendPrivateMessage(userId: string, content: string, options?: SendOptions): Promise<string[]> {
return this.sendMessage(userId, content, null, options)
}

async deleteMessage(channelId: string, messageId: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion adapters/kook/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-kook",
"description": "Kook (Kaiheila) Adapter for Satorijs",
"version": "3.5.1",
"version": "3.5.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
10 changes: 5 additions & 5 deletions adapters/kook/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Fragment, Quester, Schema, segment } from '@satorijs/satori'
import { Bot, Context, Fragment, Quester, Schema, SendOptions, segment } from '@satorijs/satori'
import { Method } from 'axios'
import { adaptAuthor, adaptGroup, adaptMessage, adaptUser } from './utils'
import * as Kook from './types'
Expand Down Expand Up @@ -37,13 +37,13 @@ export class KookBot<T extends KookBot.Config = KookBot.Config> extends Bot<T> {
}
}

async sendMessage(channelId: string, content: Fragment, guildId?: string) {
return new KookMessenger(this, channelId, guildId).send(content)
async sendMessage(channelId: string, content: Fragment, guildId?: string, options?: SendOptions) {
return new KookMessenger(this, channelId, guildId, options).send(content)
}

async sendPrivateMessage(target_id: string, content: Fragment) {
async sendPrivateMessage(target_id: string, content: Fragment, options?: SendOptions) {
const { code } = await this.request('POST', '/user-chat/create', { target_id })
return this.sendMessage(code, content)
return this.sendMessage(code, content, null, options)
}

async deleteMessage(channelId: string, msg_id: string) {
Expand Down
6 changes: 3 additions & 3 deletions adapters/kook/src/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Messenger, Schema, segment } from '@satorijs/satori'
import { Messenger, Schema, SendOptions, segment } from '@satorijs/satori'
import FormData from 'form-data'
import { KookBot } from './bot'
import { adaptMessage } from './utils'
Expand All @@ -13,8 +13,8 @@ export class KookMessenger extends Messenger<KookBot> {
private additional = {} as Partial<Kook.MessageParams>
private buffer: string = ''

constructor(bot: KookBot, channelId: string, guildId?: string) {
super(bot, channelId, guildId)
constructor(bot: KookBot, channelId: string, guildId?: string, options?: SendOptions) {
super(bot, channelId, guildId, options)
if (channelId.length > 30) {
this.params.chat_code = channelId
this.path = '/user-chat/create-msg'
Expand Down
2 changes: 1 addition & 1 deletion adapters/onebot/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-onebot",
"description": "OneBot Adapter for Satorijs",
"version": "5.5.3",
"version": "5.5.4",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
10 changes: 5 additions & 5 deletions adapters/onebot/src/bot/base.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Bot, Fragment, Schema } from '@satorijs/satori'
import { Bot, Fragment, Schema, SendOptions } from '@satorijs/satori'
import * as OneBot from '../utils'
import { OneBotMessenger } from './message'

export class BaseBot<T extends BaseBot.Config = BaseBot.Config> extends Bot<T> {
public parent?: BaseBot
public internal: OneBot.Internal

sendMessage(channelId: string, fragment: Fragment, guildId?: string) {
sendMessage(channelId: string, fragment: Fragment, guildId?: string, options?: SendOptions) {
if (!this.parent && !channelId.startsWith('private:')) {
guildId = channelId
}
return new OneBotMessenger(this, channelId, guildId).send(fragment)
return new OneBotMessenger(this, channelId, guildId, options).send(fragment)
}

sendPrivateMessage(userId: string, fragment: Fragment) {
return this.sendMessage('private:' + userId, fragment)
sendPrivateMessage(userId: string, fragment: Fragment, options?: SendOptions) {
return this.sendMessage('private:' + userId, fragment, null, options)
}

async getMessage(channelId: string, messageId: string) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/telegram/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-telegram",
"description": "Telegram Adapter for Satorijs",
"version": "3.6.0",
"version": "3.6.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
10 changes: 5 additions & 5 deletions adapters/telegram/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, Dict, Fragment, Logger, Quester, Schema, segment, Session, Time, Universal } from '@satorijs/satori'
import { Bot, Context, Dict, Fragment, Logger, Quester, Schema, segment, SendOptions, Session, Time, Universal } from '@satorijs/satori'
import * as Telegram from './types'
import { adaptGuildMember, adaptUser } from './utils'
import { TelegramMessenger } from './message'
Expand Down Expand Up @@ -169,12 +169,12 @@ export class TelegramBot<T extends TelegramBot.Config = TelegramBot.Config> exte
}
}

async sendMessage(channelId: string, fragment: Fragment, guildId?: string) {
return new TelegramMessenger(this, channelId, guildId).send(fragment)
async sendMessage(channelId: string, fragment: Fragment, guildId?: string, options?: SendOptions) {
return new TelegramMessenger(this, channelId, guildId, options).send(fragment)
}

async sendPrivateMessage(userId: string, content: Fragment) {
return this.sendMessage('private:' + userId, content)
async sendPrivateMessage(userId: string, content: Fragment, options?: SendOptions) {
return this.sendMessage('private:' + userId, content, null, options)
}

async getMessage() {
Expand Down
6 changes: 3 additions & 3 deletions adapters/telegram/src/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createReadStream } from 'fs'
import { fileURLToPath } from 'url'
import { Dict, Logger, Messenger, segment } from '@satorijs/satori'
import { Dict, Logger, Messenger, SendOptions, segment } from '@satorijs/satori'
import { fromBuffer } from 'file-type'
import FormData from 'form-data'
import { TelegramBot } from './bot'
Expand Down Expand Up @@ -77,8 +77,8 @@ export class TelegramMessenger extends Messenger<TelegramBot> {
private payload: Dict
private mode: RenderMode = 'default'

constructor(bot: TelegramBot, channelId: string, guildId?: string) {
super(bot, channelId, guildId)
constructor(bot: TelegramBot, channelId: string, guildId?: string, options?: SendOptions) {
super(bot, channelId, guildId, options)
const chat_id = channelId.startsWith('private:')
? channelId.slice(8)
: channelId
Expand Down

0 comments on commit da47c88

Please sign in to comment.