Skip to content

Commit

Permalink
fix: post message format
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-cn committed Feb 23, 2024
1 parent f9f7c2a commit 4aa9980
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![oneBot V12](https://img.shields.io/badge/OneBot-12-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://12.onebot.dev/) [![node engine](https://img.shields.io/node/v/onebots?color=339933&style=flat-square&labelColor=FAFAFA&logo=Node.js)](https://nodejs.org)
[![qq group](https://img.shields.io/badge/group-860669870-blue?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAA+CAMAAABEH1h2AAACB1BMVEX///8AAADoHx/6rgjnFhb/tQj9/f3/sggEAgLyICD//vztICAGBgbrHx8MDAwJCQn7rwj09PTi4uKbm5uBgYHvICAREREODg79sQgkJCT39/f/+/HExMT3q6tNTU37vTRFMQI4JwIgFgHt7e3r6+vd3d3b29u7u7uwsLDyenp4eHjxc3NZWVn//fj//PTf399vb29UVFQ8PDwuLi76uCUgICDfHh7oGhoYGBgVFRWjcgf6+vrR0dG2traYmJiUlJRqampiYmJXV1dDQ0M2Njbk5OTX19fKysr+5a70lJTyfX1zc3P90Gz+yFBGRkbsRET+vCn6tyLUHBwcHBzDGhqxFxesFxeeFRV4EBD/twjGiwa0fwaodgUbAwMJBgD++PjT09O/v7+xsbGpqamoqKj4p6eJiYloaGgxMTEnJyfv7+/96Ojm5ubq5eX84ODP1NTOzs7Nzc3/wcH4vb34urqioqKKioqCfXTvZWWeY2OMfmCgh1G8l0TdqjrqKirZHR3mHBy3GBiXFBSSExN/EREmERHmDg76sAxVCwtICgr/vQlECQnupwjupgjrpQg4CAjUlAfQkgfMjwbAhga7gwYiBQWJYASAWgR3UwRrSwNiRQMUAgISAgISDQEUDgD/9+X+9uX60dH3sbH94aP94aK/kZG+kJCMjIzzhobwbm7uXl7uWlrpLCyL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UiigKNiOyBN0nEhvr3CgV6SzBxphE5O4iGglY63ojCfFHbH8oV4A8vU4lFsllX8C4zVMmzDQjwIHYXEPn4fDd/HE8sKOyCz69kJTDM4LYjS8CjgAjGYn2Cp86wjKE8HHapzbQC3ZUQ+FsEtHWAUFeIFDyinER9iVLQOD39hmakJD4zr6JzE84ivzzpNEM2r0+VN7YnXeHbe+vfqVjxnv060N5UrwvkfPWiWue/F51kk3MgKnjaGI2Y8MdxHM47nU74C3abTo3lCnzfqA+zgrDsScc86hHllNE8I6dro/LurQ3q902lxDlmGn/neANEb37NhyxBadur1Q1ff0t/e1Nbu8VRVbd5c1dXlOX3q5ImjR0+cPHXa09WF16o8nva2pnzl9MvKlyGVl5Xl5wtPop+y+TWC/jf9BuxZscgeRqlfAAAAAElFTkSuQmCC&logoColor=000000)](https://jq.qq.com/?_wv=1027&k=B22VGXov)

[Type Docs](https://lc-cn.github.io/onebots)
[Docs](https://docs.onebots.org)

</p>
</div>
Expand Down
24 changes: 24 additions & 0 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:root {
--vp-home-hero-name-color: transparent;
--vp-home-hero-name-background: linear-gradient(120deg, #34fe77, #41d1ff);
--vp-button-brand-bg: #409eff;
--vp-c-gray-1: #9f9e9e;
--vp-c-gray-2: #e4e7ed;
--vp-c-gray-3: #f2f6fc;
--vp-c-indigo-1: #409eff;
--vp-c-indigo-2: #4d9ff8;
--vp-c-indigo-3: #6897fd;
--vp-c-green-1: #05b062;
--vp-c-green-2: #06c46e;
--vp-c-green-3: #07d97a;
--vp-c-yellow-1: #f1c02d;
--vp-c-yellow-2: #f0d03d;
--vp-c-yellow-3: #efe04d;
--vp-c-red-1: #f5222d;
--vp-c-red-2: #f6323d;
--vp-c-red-3: #f7424d;
}

.dark {
--vp-c-text-1: rgba(155, 155, 147, 0.86);
}
14 changes: 12 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import Theme from 'vitepress/theme'
import {h} from 'vue'
import DefaultTheme from 'vitepress/theme'
import './custom.css'
import ElementUI from 'element-plus'
import {EnhanceAppContext} from "vitepress";

export default {
...Theme,
extends:DefaultTheme,
Layout:()=>h(DefaultTheme.Layout,null,{

}),
enhanceApp({app}:EnhanceAppContext){
app.use(ElementUI)
}
}
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hero:
text: OneBot V12
link: /v12/index
- theme: alt
text: 仓库地址
text: Repository
link: https://github.com/icqqjs/onebots
features:
- title: OneBot(s) 全面
Expand Down
21 changes: 21 additions & 0 deletions docs/vite.config.mts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {defineConfig} from "vite";
import { createStyleImportPlugin } from "vite-plugin-style-import"
export default defineConfig({
resolve:{
alias:{
vue:'vue/dist/vue.esm-bundler.js'
}
},
plugins:[
createStyleImportPlugin({
libs:[
{
libraryName: 'element-plus',
resolveStyle: (name) => {
return `element-plus/lib/theme-chalk/${name}.css`;
}
}
]
})
]
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"unplugin-auto-import": "^0.17.3",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.10",
"vite-plugin-style-import": "^2.0.0",
"vitepress": "^1.0.0-rc.33",
"vue": "^3.4.0",
"vue-router": "^4.2.5"
Expand Down
9 changes: 8 additions & 1 deletion src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { App } from "@/server/app";
import { OneBot } from "@/onebot";
import { Dict } from "@zhinjs/shared";
import { Logger } from "log4js";
import { V11 } from "@/service/V11";

export abstract class Adapter<T extends string = string> extends EventEmitter {
oneBots: Map<string, OneBot> = new Map<string, OneBot>();
Expand All @@ -15,7 +16,13 @@ export abstract class Adapter<T extends string = string> extends EventEmitter {
) {
super();
}

transformMessage(uin: string, version: OneBot.Version, message: any) {
const onebot = this.getOneBot(uin);
const instance = onebot.instances.find(V => V.version === version) as V11;
return instance.config.post_message_format === "string"
? this.toCqcode(version, message)
: this.toSegment(version, message);
}
getOneBot<C = any>(uin: string) {
return this.oneBots.get(uin) as OneBot<C> | undefined;
}
Expand Down
4 changes: 4 additions & 0 deletions src/adapters/dingtalk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { App } from "@/server/app";
import { OneBot, OneBotStatus } from "@/onebot";
import { Bot, Sendable } from "node-dd-bot";
import * as path from "path";
import { V11 } from "@/service/V11";

export default class DingtalkAdapter extends Adapter<"dingtalk"> {
constructor(app: App, config: DingtalkAdapter.Config) {
Expand Down Expand Up @@ -244,6 +245,9 @@ export default class DingtalkAdapter extends Adapter<"dingtalk"> {
message_id: `${data.message_type}:${data.group_id || data.user_id}:${data.message_id}`,
};
delete result.bot;
if (event === "message") {
result.message = this.transformMessage(uin, version, result.message);
}
if (version === "V11") {
oneBot.V11.transformStrToIntForObj(result, ["user_id", "group_id", "message_id"]);
}
Expand Down
8 changes: 7 additions & 1 deletion src/adapters/icqq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OneBot, OneBotStatus } from "@/onebot";
import * as path from "path";
import { shareMusic } from "@/service/shareMusicCustom";
import { genDmMessageId, genGroupMessageId } from "@icqqjs/icqq/lib/message";
import { V11 } from "@/service/V11";

async function processMessages(
this: IcqqAdapter,
Expand Down Expand Up @@ -122,7 +123,9 @@ export default class IcqqAdapter extends Adapter<"icqq"> {
const oneBot = super.createOneBot<Client>(uin, protocol, versions);
this.#password = this.app.config[`icqq.${uin}`].password;
oneBot.avatar = `https://q1.qlogo.cn/g?b=qq&s=100&nk=` + uin;
const pkg = require(path.resolve(path.dirname(require.resolve("@icqqjs/icqq")), "../package.json"));
const pkg = require(
path.resolve(path.dirname(require.resolve("@icqqjs/icqq")), "../package.json"),
);
oneBot.dependency = `icqq v${pkg.version}`;
oneBot.status = OneBotStatus.Online;
oneBot.internal = new Client({
Expand Down Expand Up @@ -183,6 +186,9 @@ export default class IcqqAdapter extends Adapter<"icqq"> {
data.message.unshift(replyEl);
}
}
if (event === "message") {
result.message = this.transformMessage(uin, version, result.message);
}
if (version === "V11" && result.message_id) {
result.message_id = oneBot.V11.transformToInt("message_id", result.message_id);
}
Expand Down
4 changes: 4 additions & 0 deletions src/adapters/qq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { App } from "@/server/app";
import { OneBot, OneBotStatus } from "@/onebot";
import { Bot, Sendable, Quotable } from "qq-group-bot";
import * as path from "path";
import { V11 } from "@/service/V11";

export default class QQAdapter extends Adapter<"qq"> {
constructor(app: App, config: QQAdapter.Config) {
Expand Down Expand Up @@ -290,6 +291,9 @@ export default class QQAdapter extends Adapter<"qq"> {
}
delete result.bot;
const oneBot = this.getOneBot<Bot>(uin);
if (event === "message") {
result.message = this.transformMessage(uin, version, result.message);
}
switch (version) {
case "V11":
oneBot.V11.transformStrToIntForObj(result, ["message_id", "user_id", "group_id"]);
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/wechat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ export default class WechatAdapter extends Adapter<"wechat"> {
delete result.bot;
delete result.c;
delete result.parser;
if (event === "message") {
result.message = this.transformMessage(uin, version, result.message);
}
if (version === "V11") {
bot.V11.transformStrToIntForObj(result, ["user_id", "group_id", "message_id"]);
bot.V11.transformStrToIntForObj(result.self, ["user_id"]);
Expand Down

0 comments on commit 4aa9980

Please sign in to comment.