Skip to content

Commit

Permalink
fix(qqguild): check empty attachments, fix #687, fix #716 (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW authored Jul 3, 2022
1 parent b4d678c commit bc3b504
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion plugins/adapter/qqguild/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ export class QQGuildBot extends Bot<BotConfig> {
session.content = (msg.content ?? '')
.replace(/<@!(.+)>/, (_, $1) => segment.at($1))
.replace(/<#(.+)>/, (_, $1) => segment.sharp($1))
session.content = (msg as any as { attachments: any[] }).attachments
const { attachments = [] } = msg as any as { attachments?: any[] }
if (attachments.length > 0) {
session.content += attachments.map((attachment) => {
if (attachment.contentType.startsWith('image')) {
return segment.image(attachment.url)
}
}).join('')
}
session.content = attachments
.filter(({ contentType }) => contentType.startsWith('image'))
.reduce((content, attachment) => content + segment.image(attachment.url), session.content)
return new Session(this, session)
Expand Down
3 changes: 1 addition & 2 deletions plugins/adapter/qqguild/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export class WebSocketClient extends Adapter<BotConfig, AdapterConfig> {

async connect(bot: QQGuildBot) {
Object.assign(bot, await bot.getSelf())
bot.resolve()
await bot.$innerBot.startClient(bot.config.intents)
bot.$innerBot.on('ready', bot.resolve)
bot.$innerBot.on('ready', bot.resolve.bind(bot))
bot.$innerBot.on('message', msg => {
const session = bot.adaptMessage(msg)
if (session) {
Expand Down

0 comments on commit bc3b504

Please sign in to comment.