mirror of https://github.com/Nofated095/Q2TG.git
feat: 通过命令设置 flags
This commit is contained in:
parent
a2ea2d014b
commit
d6dcdd0bbf
|
@ -67,6 +67,16 @@ export default class InChatCommandsController {
|
|||
pair.flags &= ~flags.DISABLE_TG2Q;
|
||||
await message.reply({ message: 'TG->QQ已启用' });
|
||||
return true;
|
||||
case '/flags':
|
||||
case '/flag':
|
||||
if (!message.senderId.eq(this.instance.owner)) {
|
||||
await message.reply({ message: '权限不够' });
|
||||
return true;
|
||||
}
|
||||
await message.reply({
|
||||
message: await this.service.editFlags(messageParts, pair),
|
||||
});
|
||||
return true;
|
||||
case '/refresh':
|
||||
if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false;
|
||||
await pair.updateInfo();
|
||||
|
|
|
@ -11,6 +11,7 @@ import db from '../models/db';
|
|||
import { Friend, Group } from 'icqq';
|
||||
import { format } from 'date-and-time';
|
||||
import ZincSearch from 'zincsearch-node';
|
||||
import flags from '../constants/flags';
|
||||
|
||||
export default class InChatCommandsService {
|
||||
private readonly log: Logger;
|
||||
|
@ -145,4 +146,35 @@ export default class InChatCommandsService {
|
|||
});
|
||||
return rpy.join('\n');
|
||||
}
|
||||
|
||||
public async editFlags(params: string[], pair: Pair) {
|
||||
if (!params.length) {
|
||||
return '0b' + pair.flags.toString(2);
|
||||
}
|
||||
if (params.length !== 2) return '参数格式错误';
|
||||
|
||||
let operand = Number(params[1]);
|
||||
if (isNaN(operand)) {
|
||||
operand = flags[params[1].toUpperCase()];
|
||||
}
|
||||
if (isNaN(operand)) return 'flag 格式错误';
|
||||
|
||||
switch (params[0]) {
|
||||
case 'add':
|
||||
case 'set':
|
||||
pair.flags |= operand;
|
||||
break;
|
||||
case 'rm':
|
||||
case 'remove':
|
||||
case 'del':
|
||||
case 'delete':
|
||||
pair.flags &= ~operand;
|
||||
break;
|
||||
case 'put':
|
||||
pair.flags = operand;
|
||||
break;
|
||||
}
|
||||
|
||||
return '0b' + pair.flags.toString(2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue