Skip to content

Commit

Permalink
fix: 消息编码解码
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-cn committed Mar 3, 2024
1 parent 85ed8b3 commit dc00d61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function parseFromTemplate(template: string | MessageElem): MessageElem[]
result.push({
type: 'text',
data: {
text: prevText,
text: decodeURIComponent(prevText),
},
});
template = template.slice(index + matched.length);
Expand All @@ -63,9 +63,9 @@ export function parseFromTemplate(template: string | MessageElem): MessageElem[]
attrArr.map(([source, key, v1, v2]) => {
const value = v1 || v2;
try {
return [key, JSON.parse(value)];
return [key, JSON.parse(decodeURIComponent(value))];
} catch {
return [key, value];
return [key, decodeURIComponent(value)];
}
}),
);
Expand All @@ -78,7 +78,7 @@ export function parseFromTemplate(template: string | MessageElem): MessageElem[]
result.push({
type: 'text',
data: {
text: template,
text: decodeURIComponent(template),
},
});
}
Expand Down Expand Up @@ -115,16 +115,17 @@ export namespace Message {
}
}
export const segment: Message.DefineSegment = function (type, data) {
if (type === 'text') return segment.text(data.text || '');
return `<${type} ${Object.entries(data)
.map(([key, value]) => {
return `${key}='${JSON.stringify(value)}'`;
return `${key}='${encodeURIComponent(JSON.stringify(value))}'`;
})
.join(' ')}/>`;
} as Message.DefineSegment;
segment.text = text => text;
segment.face = (id: number) => `<face id='${id}'/>`;
segment.image = (file: string) => `<image src='${file}'/>`;
segment.at = user_id => `<at user_id='${user_id}'/>`;
segment.text = text => encodeURIComponent(text);
segment.face = (id: number) => `<face id='${encodeURIComponent(id)}'/>`;
segment.image = (file: string) => `<image file='${encodeURIComponent(file)}'/>`;
segment.at = user_id => `<at user_id='${encodeURIComponent(user_id)}'/>`;
type MessageSender = {
user_id?: string | number;
user_name?: string;
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defineConfigWithTheme} from "vitepress";

const pkg=require('../../core/package.json')
export default defineConfigWithTheme({
title: '知音(Zhin)',
titleTemplate: ':title - 知音(Zhin)',
Expand Down Expand Up @@ -69,7 +69,7 @@ export default defineConfigWithTheme({
// { text: '插件市场', link: '/market/', activeMatch: '/market/' },
// { text: 'Playground', link: 'https://playground.zhin.icu', activeMatch: '/playground/' },
{
text: require('../../package.json').version,
text: pkg.version,
items: [
{
text: 'Changelog',
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/icqq/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ icqq.define('sendMsg', async (bot_id, target_id, target_type, message, source) =
const disabledQuote =
!bot.quote_self ||
msg.some(e => {
return ['forward', 'music', 'share', 'reply', 'quote'].includes(e.type);
return ['node', 'music', 'share', 'reply', 'quote'].includes(e.type);
});
switch (target_type) {
case 'group':
Expand Down

0 comments on commit dc00d61

Please sign in to comment.