feat: 个人模式下给群成员禁言

This commit is contained in:
Clansty 2024-02-22 17:55:00 +08:00
parent 88c2d7238f
commit 5706491f9a
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
3 changed files with 89 additions and 1 deletions

View File

@ -28,6 +28,10 @@ const personalPrivateCommands = [
command: 'login',
description: '当 QQ 处于下线状态时,使用此命令重新登录 QQ',
}),
new Api.BotCommand({
command: 'flags',
description: 'WARNING: EXPERIMENTAL FEATURES AHEAD!',
}),
];
// 服务器零号实例的管理员
@ -57,6 +61,10 @@ const inChatCommands = [
command: 'search',
description: '搜索消息',
}),
new Api.BotCommand({
command: 'q',
description: '生成 QuotLy 图片',
}),
];
const groupInChatCommands = [
@ -93,6 +101,10 @@ const personalInChatCommands = [
command: 'nick',
description: '获取/设置群名片',
}),
new Api.BotCommand({
command: 'mute',
description: '设置 QQ 成员禁言',
}),
];
export default {

View File

@ -44,6 +44,13 @@ export default class InChatCommandsController {
case '/poke':
await this.service.poke(message, pair);
return true;
case '/unmute':
messageParts.unshift('0');
case '/mute':
if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false;
if (!(pair.qq instanceof Group)) return true;
await this.service.mute(message, pair, messageParts);
return true;
case '/forwardoff':
pair.flags |= flags.DISABLE_Q2TG | flags.DISABLE_TG2Q;
await message.reply({ message: '转发已禁用' });
@ -85,7 +92,7 @@ export default class InChatCommandsController {
return true;
case '/nick':
if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false;
if (!(pair.qq instanceof Group)) return;
if (!(pair.qq instanceof Group)) return true;
if (!params) {
await message.reply({
message: `群名片:<i>${pair.qq.pickMember(this.instance.qqUin, true).card}</i>`,

View File

@ -146,4 +146,73 @@ export default class InChatCommandsService {
});
return rpy.join('\n');
}
// 禁言 QQ 成员
public async mute(message: Api.Message, pair: Pair, args: string[]) {
try {
const group = pair.qq as Group;
if(!(group.is_admin||group.is_owner)){
await message.reply({
message: '<i>无管理员权限</i>',
});
return;
}
let target: number;
if (message.replyToMsgId) {
const dbEntry = await db.message.findFirst({
where: {
tgChatId: pair.tgId,
tgMsgId: message.replyToMsgId,
},
});
if (dbEntry) {
target = Number(dbEntry.qqSenderId);
}
}
if (!target) {
await message.reply({
message: '<i>请回复一条消息</i>',
});
return;
}
if (!args.length) {
await message.reply({
message: '<i>请输入禁言的时间</i>',
});
return;
}
let time = Number(args[0]);
if (isNaN(time)) {
const unit = args[0].substring(args[0].length - 1, args[0].length);
time = Number(args[0].substring(0, args[0].length - 1));
switch (unit) {
case 'd':
time *= 24;
case 'h':
time *= 60;
case 'm':
time *= 60;
break;
default:
time = NaN;
}
}
if (isNaN(time)) {
await message.reply({
message: '<i>请输入正确的时间</i>',
});
return;
}
await group.muteMember(target, time);
await message.reply({
message: '<i>成功</i>',
});
}
catch (e) {
await message.reply({
message: `<i>错误</i>\n${e.message}`,
});
}
}
}