Skip to content

Commit

Permalink
fix: v12 添加get_msg接口
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-cn committed Jun 12, 2023
1 parent 962ba64 commit 77e5ff9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"@koa/router": "^10.1.1",
"@zhinjs/shared": "^0.0.9",
"icqq": "^0.3.6",
"icqq": "^0.3.15",
"icqq-cq-enable": "^1.0.0",
"js-yaml": "^4.1.0",
"koa": "^2.13.4",
Expand Down
11 changes: 7 additions & 4 deletions src/onebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {EventEmitter} from 'events'
import {App} from "./server/app";
import {deepClone, deepMerge, omit} from "./utils";
import {join} from "path";
import {Client} from "icqq";
import {Client, Platform} from "icqq";
import {genDmMessageId, genGroupMessageId} from 'icqq/lib/message'
import {V11} from "./service/V11";
import {V12} from "./service/V12";
Expand All @@ -24,7 +24,9 @@ export class OneBot<V extends OneBot.Version> extends EventEmitter {
constructor(public app: App, public readonly uin: number, config: MayBeArray<OneBotConfig>) {
super()
config = [].concat(config)
let platform=this.app.config.platform
this.config = config.map(c => {
if(c.platform) platform=c.platform
if (c.password) this.password = c.password
if (!c.version) c.version = 'V11'
switch (c.version) {
Expand All @@ -36,7 +38,7 @@ export class OneBot<V extends OneBot.Version> extends EventEmitter {
throw new Error('不支持的oneBot版本:' + c.version)
}
})
this.client = new Client({platform: this.app.config.platform, data_dir: join(App.configDir, 'data')})
this.client = new Client({platform, data_dir: join(App.configDir, 'data')})
this.instances = this.config.map(c => {
switch (c.version) {
case 'V11':
Expand Down Expand Up @@ -151,13 +153,13 @@ export class OneBot<V extends OneBot.Version> extends EventEmitter {
if (data.source) {
switch (data.message_type) {
case 'group':
data.message.shift({
data.message.unshift({
type: 'reply',
message_id: genGroupMessageId(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time)
})
break;
case 'private':
data.message.shift({
data.message.unshift({
type: 'reply',
message_id: genDmMessageId(data.source.user_id, data.source.seq, data.source.rand, data.source.time)
})
Expand All @@ -179,6 +181,7 @@ export namespace OneBot {
export type Version = 'V11' | 'V12'
export type Config<V extends Version = 'V11'> = ({
version?: V
platform?:Platform
password?: string
} & (V extends 'V11' ? V11.Config : V12.Config))

Expand Down
12 changes: 12 additions & 0 deletions src/service/V12/action/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ export class CommonAction{
deleteMsg(this:V12,message_id:string){
return this.client.deleteMsg(message_id)
}

/**
* 获取消息详情
*/F
async getMsg(this:V12,message_id:string){
const message=await this.client.getMsg(message_id)
if(!message) throw new Error('消息不存在')
return {
...message,
message: V12.toSegment(message.message)
}
}
getSelfInfo(this:V12){
return {
user_id:this.oneBot.uin+'',
Expand Down
2 changes: 1 addition & 1 deletion src/service/V12/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export class V12 extends EventEmitter implements OneBot.Base {
} else {
code = 10003
this.logger.debug(e)
message = "请求格式错误"
message = e?.message||"请求格式错误"
}
ws.send(JSON.stringify({
retcode: code,
Expand Down

0 comments on commit 77e5ff9

Please sign in to comment.