|
@@ -6,15 +6,38 @@ import { getLogger } from './loggers';
|
|
|
|
|
|
const logger = getLogger('qqbot');
|
|
|
|
|
|
+type ExecuterParams = [
|
|
|
+ chat: IChat, args: string[], replyfn: (msg: string) => any
|
|
|
+];
|
|
|
+
|
|
|
interface IQQProps {
|
|
|
access_token: string;
|
|
|
host: string;
|
|
|
port: number;
|
|
|
bot_id: number;
|
|
|
- list(chat: IChat, args: string[], replyfn: (msg: string) => any): void;
|
|
|
- sub(chat: IChat, args: string[], replyfn: (msg: string) => any): void;
|
|
|
- unsub(chat: IChat, args: string[], replyfn: (msg: string) => any): void;
|
|
|
- unsubAll(chat: IChat, args: string[], replyfn: (msg: string) => any): void;
|
|
|
+ list(..._: ExecuterParams): void;
|
|
|
+ sub(..._: ExecuterParams): void;
|
|
|
+ unsub(..._: ExecuterParams): void;
|
|
|
+ unsubAll(..._: ExecuterParams): void;
|
|
|
+}
|
|
|
+
|
|
|
+const batchExec = (
|
|
|
+ executer: (..._: ExecuterParams) => void,
|
|
|
+ ...[chat, args, reply]: ExecuterParams
|
|
|
+) => {
|
|
|
+ let combinedMsg = '';
|
|
|
+ let promise = Promise.resolve();
|
|
|
+ args.forEach(arg => {
|
|
|
+ promise = promise.then(() => new Promise(resolve => {
|
|
|
+ executer(chat, [arg], (msg: string) => {
|
|
|
+ combinedMsg += msg + '\n';
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ }));
|
|
|
+ });
|
|
|
+ promise.then(() => {
|
|
|
+ if (combinedMsg) reply(combinedMsg.slice(0, -1));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
export const Message = {
|
|
@@ -228,10 +251,10 @@ export default class {
|
|
|
query(chat, cmdObj.args, reply);
|
|
|
break;
|
|
|
case 'twi_sub':
|
|
|
- this.botInfo.sub(chat, cmdObj.args, reply);
|
|
|
+ batchExec(this.botInfo.sub, chat, cmdObj.args, reply);
|
|
|
break;
|
|
|
case 'twi_unsub':
|
|
|
- this.botInfo.unsub(chat, cmdObj.args, reply);
|
|
|
+ batchExec(this.botInfo.unsub, chat, cmdObj.args, reply);
|
|
|
break;
|
|
|
case 'twi_unsuball':
|
|
|
this.botInfo.unsubAll(chat, cmdObj.args, reply);
|
|
@@ -243,8 +266,9 @@ export default class {
|
|
|
if (cmdObj.args[0] === 'twi') {
|
|
|
reply(`推特搬运机器人:
|
|
|
/twi_listsub - 查询当前聊天中的推文订阅
|
|
|
-/twi_sub〈链接|用户名〉- 订阅 Twitter 推文搬运
|
|
|
-/twi_unsub〈链接|用户名〉- 退订 Twitter 推文搬运
|
|
|
+/twi_sub〈链接|用户名〉[〈链接|用户名〉...] - 订阅一个或多个推文搬运
|
|
|
+/twi_unsub〈链接|用户名〉[〈链接|用户名〉...] - 退订一个或多个推文搬运
|
|
|
+/twi_unsuball - 退订当前聊天中全部的推文搬运
|
|
|
/twi_view〈链接|表达式〉[{force|refresh}={on|off}] - 查看推文(可选强制重新载入)
|
|
|
/twi_resendlast〈用户名〉- 强制重发该用户最后一条推文
|
|
|
/twi_query〈链接|用户名〉[参数列表...] - 查询时间线(详见 /help twi_query)\
|