Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Aug 7, 2024
1 parent 839438b commit 41fd68d
Show file tree
Hide file tree
Showing 33 changed files with 349 additions and 218 deletions.
14 changes: 14 additions & 0 deletions modules/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Todo

- [ ] [Minecraft Bedrock Identity Query](https://github.com/Teahouse-Studios/akari-bot/tree/master/modules/idlist)
- [ ] [Tic Tac Toe](https://github.com/Teahouse-Studios/akari-bot/tree/master/modules/tic_tac_toe)
- [ ] [Minecraft Mod Query](https://github.com/Teahouse-Studios/akari-bot/blob/master/modules/mcmod)
- [ ] [Minecraft Achievements Generator](https://www.mcmod.cn/tools/achievements/)
- [ ] [Math Calc](https://github.com/Teahouse-Studios/akari-bot/tree/master/modules/calc)
- [ ] [Convert](https://github.com/Teahouse-Studios/akari-bot/tree/master/modules/convert)
- [ ] [Minecraft Wiki Weekly](https://github.com/Teahouse-Studios/akari-bot/blob/master/modules/weekly)
- [ ] [whois](https://bot.teahouse.team/wiki/whois)
- [ ] [wordle](https://github.com/Teahouse-Studios/akari-bot/blob/master/modules/wordle)
- [ ] [twenty-four](https://github.com/Teahouse-Studios/akari-bot/blob/master/modules/twenty_four)
- [ ] [emoji-mix](https://github.dev/Teahouse-Studios/akari-bot/blob/master/modules/emojimix)
- [ ] [chemical-code](https://github.dev/Teahouse-Studios/akari-bot/modules/chemical_code)
6 changes: 4 additions & 2 deletions modules/adapter-discord/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ export class DiscordAdapter extends Adapter<DiscordApi, DiscordConfig, DiscordEl
public handle() {}

public async start() {
this.client.on('ready', () =>
this.client.on('ready', () => {
this.ctx.emit('connect', {
type: 'connect',
mode: 'other',
adapter: this,
normal: true,
address: 'discord.js'
})
)
this.online()
})
this.client.on('error', (error) => this.ctx.emit('error', KotoriError.from(error, this.ctx.identity?.toString())))
this.client.on('messageCreate', async (message) => {
this.session('on_message', {
Expand Down Expand Up @@ -83,6 +84,7 @@ export class DiscordAdapter extends Adapter<DiscordApi, DiscordConfig, DiscordEl
normal: true,
address: 'discord.js'
})
this.offline()
}

public send() {}
Expand Down
6 changes: 3 additions & 3 deletions modules/adapter-mail/locales/common.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"adapter_mail.descr.mail": "Send mail by target email",
"adapter_mail.msg.mail.input_target": "Please input received email",
"adapter_mail.msg.mail.input_title": "Please input mail title",
"adapter_mail.msg.mail.input_content": "Please input mail content",
"adapter_mail.msg.mail.input_target": "Please input received email:",
"adapter_mail.msg.mail.input_title": "Please input mail title:",
"adapter_mail.msg.mail.input_content": "Please input mail content:",
"adapter_mail.msg.mail.sure": "Title: {0}\nContent: {1}\n-------------\nMak sure to send mail to {2}? (Input \"1\" to send, any other key to cancel)",
"adapter_mail.msg.mail.cancel": "Cancel successfully to send",
"adapter_mail.msg.mail.success": "Succeeded in sending mail to {0}",
Expand Down
6 changes: 3 additions & 3 deletions modules/adapter-mail/locales/ja_JP.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"adapter_mail.descr.mail": "指定メールアドレスにメールを送信",
"adapter_mail.msg.mail.input_target": "受信メールアドレスを入力してください",
"adapter_mail.msg.mail.input_title": "メールの件名を入力してください",
"adapter_mail.msg.mail.input_content": "メールの内容を入力してください",
"adapter_mail.msg.mail.input_target": "受信メールアドレスを入力してください",
"adapter_mail.msg.mail.input_title": "メールの件名を入力してください",
"adapter_mail.msg.mail.input_content": "メールの内容を入力してください",
"adapter_mail.msg.mail.sure": "件名:{0}\n内容:{1}\n-------------\n{2}にメールを送信しますか?(「1」で送信、他のキーでキャンセル)",
"adapter_mail.msg.mail.cancel": "送信をキャンセルしました",
"adapter_mail.msg.mail.success": "{0}へのメール送信に成功しました",
Expand Down
6 changes: 3 additions & 3 deletions modules/adapter-mail/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"adapter_mail.descr.mail": "通过目标邮箱发送邮件",
"adapter_mail.msg.mail.input_target": "请输入接收邮箱",
"adapter_mail.msg.mail.input_title": "请输入邮件标题",
"adapter_mail.msg.mail.input_content": "请输入邮件内容",
"adapter_mail.msg.mail.input_target": "请输入接收邮箱",
"adapter_mail.msg.mail.input_title": "请输入邮件标题",
"adapter_mail.msg.mail.input_content": "请输入邮件内容",
"adapter_mail.msg.mail.sure": "标题:{0}\n内容:{1}\n-------------\n确定发送邮件至{2}?(输入\"1\"发送,其他键取消)",
"adapter_mail.msg.mail.cancel": "成功取消发送",
"adapter_mail.msg.mail.success": "成功发送邮件至{0}",
Expand Down
3 changes: 2 additions & 1 deletion modules/adapter-mail/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as imap from 'imap-simple'
import { simpleParser } from 'mailparser'

export const config = Tsu.Object({
title: Tsu.String().domain().default('Love from kotori bot mailer').describe('Mail default title'),
title: Tsu.String().default('Love from kotori bot mailer').describe('Mail default title'),
commandEnable: Tsu.Boolean()
.default(true)
.describe("Whether to enable command, other bot's master can send mail by the command, please set at top mail bot"),
Expand Down Expand Up @@ -156,6 +156,7 @@ export class MailAdapter extends Adapter<MailApi, MailConfig, MailElements> {
normal: true,
address: `imap://${this.config.imapHost}:${this.config.imapPort}`
})
this.online()
await sleep(10 * 1000)
this.timerId = setInterval(() => this.handle(), this.config.interval * 1000)
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion modules/adapter-mail/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function main(ctx: Context, config: { forward: string[]; enable: boolean
])
}

const instance = instances.find((instance) => instance.config.user === email)
const instance = instances.find((instance) => instance.config.user === email || instance.identity === email)
if (!instance) return session.format('adapter_mail.msg.mail.fail.2', [email])

const target = await session.prompt(ctx.i18n.t`adapter_mail.msg.mail.input_target`)
Expand Down
2 changes: 1 addition & 1 deletion modules/adapter-minecraft/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Blog: https://hotaru.icu
* @Date: 2023-09-29 14:31:09
* @LastEditors: Hotaru [email protected]
* @LastEditTime: 2024-08-04 18:59:38
* @LastEditTime: 2024-08-07 19:07:55
*/
import { type AdapterConfig, Adapters, type Context, MessageScope, Tsu, stringTemp, KotoriError } from 'kotori-bot'
import Mcwss from 'mcwss'
Expand Down
3 changes: 2 additions & 1 deletion modules/adapter-onebot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Blog: https://hotaru.icu
* @Date: 2023-09-29 14:31:09
* @LastEditors: Hotaru [email protected]
* @LastEditTime: 2024-08-04 15:37:44
* @LastEditTime: 2024-08-07 19:07:03
*/
import {
Adapters,
Expand Down Expand Up @@ -74,6 +74,7 @@ export class OnebotAdapter extends Adapters.WebSocket<OnebotApi, OnebotConfig, O
if (!this.isReverse) return
this.connection = (ws) => {
this.socket = ws
this.online()
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/adapter-qq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const config = Tsu.Object({

### Events

- on_message (exclude `MessageScope.PRIVATE`)
- on_message

### Api

Expand Down
109 changes: 73 additions & 36 deletions modules/adapter-qq/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class QQAdapter extends Adapter<QQApi, QQConfig, QQElements> {
headers: {
Authorization: `QQBot ${this.token}`,
'X-Union-Appid': this.config.appid
},
validateStatus: () => true
}
// validateStatus: () => true
})
}

Expand All @@ -66,7 +66,7 @@ export class QQAdapter extends Adapter<QQApi, QQConfig, QQElements> {
op: 2,
d: {
token: `QQBot ${this.token}`,
intents: 1241513984,
intents: 0 | (1 << 12) | (1 << 25) | (1 << 30),
shard: [0, 1]
}
})
Expand Down Expand Up @@ -95,11 +95,39 @@ export class QQAdapter extends Adapter<QQApi, QQConfig, QQElements> {
})
this.msgIdList.set(data.d.group_openid, data.d.id)
} else if (data.t === 'DIRECT_MESSAGE_CREATE') {
const id = `channel-${data.d.author.id}`
this.session('on_message', {
type: MessageScope.PRIVATE,
userId: id,
messageId: data.d.id,
message: data.d.content.replace(/<@(.*?)>( )?/, '').trim(),
messageAlt: data.d.content.trim(),
time: new Date(data.d.timestamp).getTime(),
sender: {
nickname: ''
}
})
this.msgIdList.set(id, data.d.id)
} else if (data.t === 'C2C_MESSAGE_CREATE') {
this.session('on_message', {
type: MessageScope.PRIVATE,
userId: data.d.author.user_openid,
messageId: data.d.id,
message: data.d.content.replace(/<@(.*?)>( )?/, '').trim(),

messageAlt: data.d.content.trim(),
time: new Date(data.d.timestamp).getTime(),
sender: {
nickname: ''
}
})
this.msgIdList.set(data.d.author.user_openid, data.d.id)
} else if (data.t === 'AT_MESSAGE_CREATE') {
this.session('on_message', {
type: MessageScope.CHANNEL,
userId: data.d.author.id,
messageId: data.d.id,
message: data.d.content.trim(),
message: data.d.content.replace(/<@(.*?)>( )?/, '').trim(),
messageAlt: data.d.content.trim(),
channelId: data.d.channel_id,
guildId: data.d.guild_id,
Expand Down Expand Up @@ -142,26 +170,32 @@ export class QQAdapter extends Adapter<QQApi, QQConfig, QQElements> {
if (!params) return
if (action === 'sendGroupMsg') {
const { groupId, message, media: mediaRaw } = params as ParamsMapping['sendGroupMsg'][0]
let media: string[] = []
if (mediaRaw.length > 0) {
media = await Promise.all(
mediaRaw.map(
async ({ type, value }) =>
(
(await this.req(`groups/${groupId}/files`, { file_type: type, url: value, srv_send_msg: false })) as {
file_info: string
}
).file_info
)
)
}
// let media: string[] = []
// if (mediaRaw.length > 0) {
// media = await Promise.all(
// mediaRaw.map(
// async ({ type, value }) =>
// (
// (await this.req(`groups/${groupId}/files`, { file_type: type, url: value, srv_send_msg: false })) as {
// file_info: string
// }
// ).file_info
// )
// )
// }
const media = mediaRaw.length > 0 ? mediaRaw[mediaRaw.length - 1] : undefined

return this.req(`groups/${groupId}/messages`, {
const params2 = {
content: filterLinks(message),
msg_type: media.length > 0 ? 7 : 0,
msg_type: media ? 7 : 0,
msg_id: this.msgIdList.get(groupId) ?? null,
msg_seq: this.getMsgSeq()
})
msg_seq: this.getMsgSeq(),
media: media
? await this.req(`groups/${groupId}/files`, { file_type: media.type, url: media.value, srv_send_msg: false })
: null
}
const res = await this.req(`groups/${groupId}/messages`, params2)
return res
}
if (action === 'sendChannelMsg') {
const { guildId, channelId, content, image } = params as ParamsMapping['sendChannelMsg'][0]
Expand All @@ -171,32 +205,35 @@ export class QQAdapter extends Adapter<QQApi, QQConfig, QQElements> {
image
})
}
// TODO: supports private

return
}

private socket: WebSocket | null = null

private async connect() {
this.socket = new WebSocket(WS_ADDRESS)
this.socket.on('close', () => {
this.ctx.emit('connect', {
type: 'disconnect',
adapter: this,
normal: false,
address: WS_ADDRESS,
mode: 'ws'
})
this.socket.on('close', (code) => {
this.ctx.logger.debug(code)
// this.ctx.emit('connect', {
// type: 'disconnect',
// adapter: this,
// normal: false,
// address: WS_ADDRESS,
// mode: 'ws'
// })
clearTimeout(this.heartbeatTimerId)
setTimeout(() => {
if (!this.socket) return
this.socket.close()
this.ctx.emit('connect', {
type: 'connect',
adapter: this,
normal: false,
mode: 'ws',
address: WS_ADDRESS
})
// this.ctx.emit('connect', {
// type: 'connect',
// adapter: this,
// normal: false,
// mode: 'ws',
// address: WS_ADDRESS
// })
this.start()
}, this.config.retry * 1000)
})
Expand Down
2 changes: 1 addition & 1 deletion modules/adapter-qq/src/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class QQElements extends Elements {
if (!Object.keys(mapping).includes(message.data.type)) return ''
const meta = {
type: mapping[message.data.type as 'image'],
value: (message.data as unknown as { value: string }).value
value: (message.data as unknown as { content: string }).content
}
if (!list) {
Reflect.defineMetadata(MEDIA_KEY, [meta], message)
Expand Down
2 changes: 1 addition & 1 deletion modules/adapter-qq/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ interface DIRECT_MESSAGE_CREATE {
}
}

type AT_MESSAGE_CREATE = Message
type AT_MESSAGE_CREATE = DIRECT_MESSAGE_CREATE
type MESSAGE_CREATE = Message

interface GUILD_CREATE {
Expand Down
4 changes: 3 additions & 1 deletion modules/adapter-sandbox/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Blog: https://hotaru.icu
* @Date: 2023-09-29 14:31:09
* @LastEditors: Hotaru [email protected]
* @LastEditTime: 2024-08-05 16:27:49
* @LastEditTime: 2024-08-07 14:45:14
*/
import { type AdapterConfig, type Context, Tsu, Adapters } from 'kotori-bot'
import SandboxApi from './api'
Expand Down Expand Up @@ -57,6 +57,8 @@ export class SandboxAdapter extends Adapters.WebSocket<SandboxApi, SandboxConfig
public start() {
this.connection = (ws) => {
this.wsSend = ws.send.bind(ws)
this.online()
ws.on('close', () => this.offline())
}
}

Expand Down
2 changes: 2 additions & 0 deletions modules/adapter-slack/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class SlackAdapter extends Adapter<SlackApi, SlackConfig, SlackElements>
normal: true,
address: '@slack/bolt'
})
this.online()
}

public stop() {
Expand All @@ -98,6 +99,7 @@ export class SlackAdapter extends Adapter<SlackApi, SlackConfig, SlackElements>
normal: true,
address: '@slack/bolt'
})
this.offline()
}

public send() {}
Expand Down
2 changes: 2 additions & 0 deletions modules/adapter-telegram/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ export class TelegramAdapter extends Adapter<TelegramApi, TelegramConfig, Telegr
normal: true,
address: 'node-telegram-bot-api'
})
this.online()
}

public stop() {
this.bot?.close()
this.offline()
}

public send() {}
Expand Down
Loading

0 comments on commit 41fd68d

Please sign in to comment.