Skip to content

Commit

Permalink
feat(qq): rename qqguild to qq
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 26, 2023
1 parent efc08e3 commit 07f3e46
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 29 deletions.
18 changes: 10 additions & 8 deletions packages/core/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from '@koishijs/utils'
import { defineProperty, Dict, MaybeArray } from 'cosmokit'
import { Database, Driver, Update } from '@minatojs/core'
import { Context, Fragment, Schema } from '@satorijs/core'
import { Context, Fragment, Schema, Universal } from '@satorijs/core'
import { Plugin } from './context'

declare module '@satorijs/core' {
Expand Down Expand Up @@ -199,13 +199,15 @@ export class DatabaseService extends Database<Tables> {
return (await Promise.all(this.app.bots.map((bot) => {
const targets = assignMap[bot.platform]?.[bot.selfId]
if (!targets) return Promise.resolve([])
const sessions = targets.map(({ id, guildId, locales }) => bot.session({
type: 'message',
subtype: 'group',
channelId: id,
guildId,
locales,
}))
const sessions = targets.map(({ id, guildId, locales }) => {
const session = bot.session({
type: 'message',
channel: { id, type: Universal.Channel.Type.TEXT },
guild: { id: guildId },
})
session.locales = locales
return session
})
return bot.broadcast(sessions, content)
}))).flat(1)
}
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extend, observe } from '@koishijs/utils'
import { Awaitable, defineProperty, isNullable, makeArray } from 'cosmokit'
import { Context, Fragment, h, Logger, Session } from '@satorijs/core'
import { Context, Fragment, h, Logger, Session, Universal } from '@satorijs/core'
import { Eval, executeEval, isEvalExpr } from '@minatojs/core'
import { Argv, Command } from './command'
import { Channel, Tables, User } from './database'
Expand All @@ -21,7 +21,7 @@ declare module '@satorijs/core' {
stripped?: Stripped
scope?: string
username?: string
send(content: Fragment, options?: SendOptions): Promise<string[]>
send(content: Fragment, options?: Universal.SendOptions): Promise<string[]>
cancelQueued(delay?: number): void
sendQueued(content: Fragment, delay?: number): Promise<string[]>
resolve<T, R extends any[]>(source: T | Eval.Expr | ((session: Session, ...args: R) => T), ...args: R):
Expand Down Expand Up @@ -196,7 +196,7 @@ extend(Session.prototype as Session.Private, {
atSelf = appel = true
}
// quote messages may contain mentions
if (!self.quote || self.quote.userId !== attrs.id) {
if (self.quote?.user?.id && self.quote.user.id !== attrs.id) {
hasAt = true
}
// @ts-ignore
Expand All @@ -220,7 +220,7 @@ extend(Session.prototype as Session.Private, {

async getChannel(id = this.channelId, fields = []) {
const { app, platform, guildId } = this
if (!fields.length) return { platform, id, guildId }
if (!fields.length) return { platform, id, guildId } as Channel
const channel = await app.database.getChannel(platform, id, fields)
if (channel) return channel
const assignee = this.resolve(app.config.autoAssign) ? this.selfId : ''
Expand Down Expand Up @@ -273,7 +273,7 @@ extend(Session.prototype as Session.Private, {

async getUser(userId = this.userId, fields = []) {
const { app, platform } = this
if (!fields.length) return {}
if (!fields.length) return {} as User
const user = await app.database.getUser(platform, userId, fields)
if (user) return user
const authority = this.resolve(app.config.autoAuthorize)
Expand Down Expand Up @@ -302,7 +302,7 @@ extend(Session.prototype as Session.Private, {
}

// 匿名消息不会写回数据库
if (this.author?.anonymous) {
if (this.author?.['anonymous']) {
const fallback = this.app.model.tables.user.create()
fallback.authority = this.resolve(this.app.config.autoAuthorize)
const user = observe(fallback, () => Promise.resolve())
Expand All @@ -318,7 +318,7 @@ extend(Session.prototype as Session.Private, {
cache = observe(data, diff => this.app.database.setUser(this.platform, userId, diff as any), `user ${this.uid}`)
this.app.$internal._userCache.set(this.id, this.uid, cache as any)
}
return this.user = cache
return this.user = cache as any
},

async withScope(scope, callback: () => any) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@koishijs/plugin-adapter-qqguild",
"description": "QQ Guild Adapter for Koishi",
"name": "@koishijs/plugin-adapter-qq",
"description": "QQ Adapter for Koishi",
"version": "4.0.1",
"main": "lib/index.js",
"module": "lib/index.mjs",
Expand All @@ -13,17 +13,18 @@
"repository": {
"type": "git",
"url": "git+https://github.com/satorijs/satori.git",
"directory": "adapters/qqguild"
"directory": "adapters/qq"
},
"bugs": {
"url": "https://github.com/satorijs/satori/issues"
},
"homepage": "https://koishi.chat/plugins/adapter/qqguild.html",
"homepage": "https://koishi.chat/plugins/adapter/qq.html",
"keywords": [
"bot",
"chatbot",
"qqbot",
"qqguild",
"qq",
"koishi"
],
"koishi": {
Expand All @@ -45,6 +46,6 @@
"koishi": "^4.14.6"
},
"dependencies": {
"@satorijs/adapter-qqguild": "^4.0.1"
"@satorijs/adapter-qq": "^4.0.1"
}
}
5 changes: 5 additions & 0 deletions plugins/adapter/qq/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@koishijs/plugin-adapter-qq](https://koishi.chat/plugins/adapter/qq.html)

QQ / QQ Guild adapter for [Koishi](https://koishi.chat).

- [Documentation](https://koishi.chat/plugins/adapter/qq.html)
4 changes: 4 additions & 0 deletions plugins/adapter/qq/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { QQBot } from '@satorijs/adapter-qq'

export default QQBot
export * from '@satorijs/adapter-qq'
File renamed without changes.
5 changes: 0 additions & 5 deletions plugins/adapter/qqguild/readme.md

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/adapter/qqguild/src/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions plugins/adapter/satori/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
tsconfig.tsbuildinfo
50 changes: 50 additions & 0 deletions plugins/adapter/satori/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@koishijs/plugin-adapter-satori",
"description": "Satori Protocol Adapter for Koishi",
"version": "1.0.0-alpha.0",
"main": "lib/index.js",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
"files": [
"lib"
],
"author": "Shigma <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/satorijs/satori.git",
"directory": "adapters/satori"
},
"bugs": {
"url": "https://github.com/satorijs/satori/issues"
},
"homepage": "https://koishi.chat/plugins/adapter/satori.html",
"keywords": [
"bot",
"adapter",
"satori",
"protocol",
"chatbot",
"koishi"
],
"koishi": {
"description": {
"en": "Satori Protocol Adapter",
"zh": "Satori 协议适配器"
},
"service": {
"implements": [
"adapter"
]
}
},
"peerDependencies": {
"koishi": "^4.14.6"
},
"devDependencies": {
"koishi": "^4.14.6"
},
"dependencies": {
"@satorijs/adapter-satori": "^1.0.0-alpha.0"
}
}
5 changes: 5 additions & 0 deletions plugins/adapter/satori/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@koishijs/plugin-adapter-satori](https://koishi.chat/plugins/adapter/satori.html)

Satori protocol adapter for [Koishi](https://koishi.chat).

- [Documentation](https://koishi.chat/plugins/adapter/satori.html)
4 changes: 4 additions & 0 deletions plugins/adapter/satori/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SatoriBot } from '@satorijs/adapter-satori'

export default SatoriBot
export * from '@satorijs/adapter-satori'
10 changes: 10 additions & 0 deletions plugins/adapter/satori/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
},
"include": [
"src",
],
}

0 comments on commit 07f3e46

Please sign in to comment.