Commit 216fbffb authored by mrhso's avatar mrhso

sync

parent f4daeb37
LilyWhiteBot
===
[傳統漢字版](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README.md)
[傳統漢字版](https://github.com/mrhso/LilyWhiteBot/blob/master/README.md)
[简化字版](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README-hans.md)
[简化字版](https://github.com/mrhso/LilyWhiteBot/blob/master/README-hans.md)
在多个群组间传话的机器人。
......
LilyWhiteBot
===
[傳統漢字版](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README.md)
[傳統漢字版](https://github.com/mrhso/LilyWhiteBot/blob/master/README.md)
[简化字版(内地用语)](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README-hans-cn.md)
[简化字版(内地用语)](https://github.com/mrhso/LilyWhiteBot/blob/master/README-hans-cn.md)
在多个群组间传话的机器人。
......
LilyWhiteBot
===
[简化字版](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README-hans.md)
[简化字版](https://github.com/mrhso/LilyWhiteBot/blob/master/README-hans.md)
[简化字版(内地用语)](https://github.com/mrhso/LilyWhiteBot-Ishisashi/blob/master/README-hans-cn.md)
[简化字版(内地用语)](https://github.com/mrhso/LilyWhiteBot/blob/master/README-hans-cn.md)
在多個群組間傳話的機器人。
......
......@@ -351,9 +351,9 @@ const faces = {
const parseMessage = (message) => {
let images = [];
let records = [];
let at = {};
let at = [];
let text = message.replace(/\n/gu, '
').replace(/\[CQ:(.*?),(.*?)\]/gu, (_, type, param) => {
let text = message.replace(/\n/gu, '
').replace(/\[CQ:([^,]*?)\]/gu, '[CQ:$1,]').replace(/\[CQ:(.*?)((?:,).*?)\]/gu, (_, type, param) => {
let tmp;
let tmp1;
let tmp2;
......@@ -373,7 +373,7 @@ const parseMessage = (message) => {
if (tmp && tmp[1]) {
return String.fromCodePoint(tmp[1]);
} else {
return '';
return '[绘文字]';
}
case 'bface':
......@@ -393,7 +393,7 @@ const parseMessage = (message) => {
images.push(tmp[1]);
return '[图片]';
} else {
return '';
return '[图片]';
}
case 'rich':
......@@ -404,21 +404,21 @@ const parseMessage = (message) => {
if (tmp1 && tmp1[1]) {
return `[分享链接:${tmp1[1]}]`;
} else if (tmp2 && tmp2[1]) {
return `[${tmp2[1]}]`;
return tmp2[1];
} else {
return '';
return '[富文本]';
}
case 'record':
// 一般語音 [CQ:record,file=C091016F9A0CCFF1741AF0B442BD4F70.silk]
// 領語音紅包為 [CQ:record,file=C091016F9A0CCFF1741AF0B442BD4F70.silk,hb=true]
// 一般語音 [CQ:record,file=C091016F9A0CCFF1741AF0B442BD4F70.silk]
// 領取語音紅包 [CQ:record,file=C091016F9A0CCFF1741AF0B442BD4F70.silk,hb=true]
// 依據客户端之不同,可能是 silk,也可能是 amr
tmp = param.match(/(?:^|,)file=(.*?)(?:,|$)/u);
if (tmp && tmp[1]) {
records.push(tmp[1]);
return '[语音]';
} else {
return '';
return '[语音]';
}
case 'at':
......@@ -428,11 +428,11 @@ const parseMessage = (message) => {
if (tmp[1] === 'all') {
return '@全体成员';
} else {
at[tmp[1]] = true;
at.push(parseInt(tmp[1]));
return `@${tmp[1]}`; // 只給出 QQ 號,至於應該 @ 什麼內容,讓使用者處理吧
}
} else {
return '';
return '[at]';
}
case 'share':
......@@ -441,7 +441,7 @@ const parseMessage = (message) => {
if (tmp && tmp[1]) {
return `[分享链接:${tmp[1]}]`;
} else {
return '';
return '[分享]';
}
case 'hb':
......@@ -450,7 +450,7 @@ const parseMessage = (message) => {
if (tmp && tmp[1]) {
return `[红包:${tmp[1]}]`;
} else {
return '';
return '[红包]';
}
case 'sign':
......@@ -459,7 +459,7 @@ const parseMessage = (message) => {
if (tmp && tmp[1]) {
return `[签到:${tmp[1]}]`;
} else {
return '';
return '[签到]';
}
case 'location':
......@@ -476,7 +476,7 @@ const parseMessage = (message) => {
if (tmp.length > 0) {
return `[位置:${tmp.join(' ')}]`;
} else {
return '';
return '[位置]';
}
case 'contact':
......@@ -489,21 +489,65 @@ const parseMessage = (message) => {
} else if (tmp1 && tmp1[1] && tmp2 && tmp2[1] === 'qq') {
return `[好友邀请:${tmp1[1]}]`;
} else {
return '';
return '[邀请]';
}
case 'music':
// 外鏈 [CQ:music,type=custom,url=https://kg3.qq.com/node/play?s=tddsOFtqHK4YxtGy&shareuid=66999e87222a308c36&topsource=a0_pn201001004_z11_u443277772_l1_t1551967343__,title=翅膀,content=我唱了一首歌,快来听听吧。,image=http://url.cn/478RlhQ,audio=http://url.cn/5ICzaEj]
// 網易雲 [CQ:music,type=163,id=509842]
// QQ 音樂 [CQ:music,type=qq,id=200732275]
// 蝦米 [CQ:music,type=xiami,id=1769370187]
tmp = param.match(/(?:^|,)type=(.*?)(?:,|$)/u);
tmp1 = param.match(/(?:^|,)url=(.*?)(?:,|$)/u);
tmp2 = param.match(/(?:^|,)id=(.*?)(?:,|$)/u);
if (tmp && tmp[1] === 'custom' && tmp1 && tmp1[1]) {
return `[分享音乐:${tmp1[1]}]`;
} else if (tmp && tmp[1] === '163' && tmp2 && tmp2[1]) {
return `[分享音乐:https://music.163.com/#/song?id=${tmp2[1]}]`
} else if (tmp && tmp[1] === 'qq' && tmp2 && tmp2[1]) {
return `[分享音乐:https://y.qq.com/n/yqq/song/${tmp2[1]}_num.html]`
} else if (tmp && tmp[1] === 'xiami' && tmp2 && tmp2[1]) {
return `[分享音乐:https://www.xiami.com/song/${tmp2[1]}]`
} else {
return '[分享音乐]';
}
case 'rps':
// [CQ:rps,type=1]
tmp = param.match(/(?:^|,)type=(.*?)(?:,|$)/u);
if (tmp && tmp[1] === '1') {
return '[猜拳:石头]';
} else if (tmp && tmp[1] === '2') {
return '[猜拳:剪刀]';
} else if (tmp && tmp[1] === '3') {
return '[猜拳:布]';
} else {
return '[猜拳]';
}
case 'dice':
// [CQ:dice,type=1]
tmp = param.match(/(?:^|,)type=(.*?)(?:,|$)/u);
if (tmp && tmp[1]) {
return `[骰子:${tmp[1]}]`;
} else {
return '[骰子]';
}
case 'shake':
// [CQ:shake]
// 戳一戳,即窗口抖动
return '[戳一戳]';
default:
return '';
}
}).replace(/
/gu, '\n');
// at 去重
let ats = [];
for (let k in at) {
ats.push(parseInt(k));
}
let ats = [...new Set(at)];
text = text.replace(/[/gu, '[').replace(/]/gu, ']').replace(/&/gu, '&');
text = text.replace(/[/gu, '[').replace(/]/gu, ']').replace(/,/gu, ',').replace(/&/gu, '&');
return {
text: text,
......
......@@ -30,8 +30,6 @@ class QQMessageHandler extends MessageHandler {
this._isPro = options.CoolQPro && true;
this._keepSilence = options.keepSilence || [];
this._pendingQueries = new Map(); // 用於查詢使用者資料
this._stat = new LRU({
max: 500,
maxAge: 60000,
......@@ -148,13 +146,6 @@ class QQMessageHandler extends MessageHandler {
client.on('GroupAdmin', (rawdata) => {
this.emit('admin', rawdata);
});
client.on('GroupMemberInfo', (info) => {
let key = `${info.group}_${info.qq}`;
let callback = this._pendingQueries.get(key);
this._pendingQueries.delete(key);
callback(info);
});
}
get qq() { return this._qq; }
......@@ -229,22 +220,7 @@ class QQMessageHandler extends MessageHandler {
}
groupMemberInfo(group, qq) {
return new Promise((resolve, reject) => {
let stop = false;
let timeOut = setTimeout(() => {
stop = true;
reject();
}, 1000);
const done = (info) => {
if (!stop) {
clearTimeout(timeOut);
resolve(info);
}
};
this._pendingQueries.set(`${group}_${qq}`, done);
this._client.groupMemberInfo(group, qq);
});
return this._client.groupMemberInfo(group, qq);
}
parseMessage(message) {
......
/**
* LilyWhiteBot
* https://github.com/mrhso/LilyWhiteBot-Ishisashi
* https://github.com/mrhso/LilyWhiteBot
*
* @author vjudge1, Ishisashi
* @description
......
......@@ -110,7 +110,7 @@ const uploadToVimCN = (file) => new Promise((resolve, reject) => {
const post = (pendingfile, callback) => request.post({
url: 'https://img.vim-cn.com/',
headers: {
'User-Agent': 'LilyWhiteBot/1.3 (https://github.com/mrhso/LilyWhiteBot-Ishisashi)'
'User-Agent': 'LilyWhiteBot/1.3 (https://github.com/mrhso/LilyWhiteBot)'
},
formData: {
name: pendingfile,
......@@ -153,7 +153,7 @@ const uploadToSmms = (file) => new Promise((resolve, reject) => {
const post = (pendingfile, callback) => request.post({
url: 'https://sm.ms/api/upload',
headers: {
'User-Agent': 'LilyWhiteBot/1.3 (https://github.com/mrhso/LilyWhiteBot-Ishisashi)'
'User-Agent': 'LilyWhiteBot/1.3 (https://github.com/mrhso/LilyWhiteBot)'
},
json: true,
formData: {
......@@ -411,7 +411,7 @@ const getQQPhotoUrl = name => new Promise((resolve, reject) => {
} else {
try {
let info = data.toString('ascii');
let [ ,url] = info.match(/url=(.*?)[\r\n]/u) || [];
let [, url] = info.match(/url=(.*?)[\r\n]/u) || [];
resolve({ url: url });
} catch (ex) {
......@@ -420,7 +420,7 @@ const getQQPhotoUrl = name => new Promise((resolve, reject) => {
}
});
});
const getQQVoicePath = (name) => Promise.resolve({ path: path.join(servemedia.coolqCache, 'record', name)});
const getQQVoicePath = (name) => Promise.resolve({ path: path.join(servemedia.coolqCache, 'record', name) });
const processQQFile = file => new Promise((resolve, reject) => {
if (file.type === 'photo') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment