feat: 通过命令设置 flags

This commit is contained in:
Clansty 2024-01-12 23:18:12 +08:00
parent a2ea2d014b
commit d6dcdd0bbf
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
2 changed files with 42 additions and 0 deletions

View File

@ -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();

View File

@ -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);
}
}