fix cqcode format

This commit is contained in:
super1207 2024-03-09 15:04:09 +08:00 committed by GitHub
parent c906bcf7ea
commit 7bdb84b11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,15 +46,22 @@ export function decodeCQCode(source: string): OB11MessageData[] {
export function encodeCQCode(data: OB11MessageData) {
const CQCodeEscape = (text: string) => {
return text.replace(/\[/g, '[')
const CQCodeEscapeText = (text: string) => {
return text.replace(/\&/g, '&')
.replace(/\[/g, '[')
.replace(/\]/g, ']')
};
const CQCodeEscape = (text: string) => {
return text.replace(/\&/g, '&')
.replace(/\[/g, '[')
.replace(/\]/g, ']')
.replace(/\&/g, '&')
.replace(/,/g, ',');
};
if (data.type === 'text') {
return CQCodeEscape(data.data.text);
return CQCodeEscapeText(data.data.text);
}
let result = '[CQ:' + data.type;
@ -68,4 +75,4 @@ export function encodeCQCode(data: OB11MessageData) {
// const result = parseCQCode("[CQ:at,qq=114514]早上好啊[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]")
// const result = parseCQCode("好好好")
// console.log(JSON.stringify(result))
// console.log(JSON.stringify(result))