feat: 支持发起戳一戳

This commit is contained in:
Clansty 2022-04-07 15:06:50 +08:00
parent bb0992a04c
commit fed155000a
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
4 changed files with 44 additions and 4 deletions

View File

@ -49,12 +49,16 @@ const groupInChatCommands = [
}),
];
const privateInChatCommands = [
const personalInChatCommands = [
...groupInChatCommands,
new Api.BotCommand({
command: 'refresh',
description: '刷新头像和简介',
}),
new Api.BotCommand({
command: 'poke',
description: '戳一戳',
}),
];
export default {
@ -64,5 +68,5 @@ export default {
groupPrivateSuperAdminCommands,
personalPrivateSuperAdminCommands,
groupInChatCommands,
privateInChatCommands,
personalInChatCommands,
};

View File

@ -33,6 +33,9 @@ export default class InChatCommandsController {
case '/info':
await this.service.info(message, pair);
return true;
case '/poke':
await this.service.poke(message, pair);
return true;
case '/refresh':
if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false;
await pair.updateInfo();

View File

@ -153,7 +153,7 @@ export default class Instance {
}
// 设定群组内的
await this.tgBot.setCommands(
this.workMode === 'personal' ? commands.privateInChatCommands : commands.groupInChatCommands,
this.workMode === 'personal' ? commands.personalInChatCommands : commands.groupInChatCommands,
// 普通用户其实不需要这些命令,这样可以让用户的输入框少点东西
new Api.BotCommandScopeChatAdmins(),
);

View File

@ -8,7 +8,7 @@ import { Pair } from '../models/Pair';
import { CustomFile } from 'telegram/client/uploads';
import { getAvatar } from '../utils/urls';
import db from '../models/db';
import { Friend } from 'oicq';
import { Friend, Group } from 'oicq';
import { format } from 'date-and-time';
export default class InChatCommandsService {
@ -83,4 +83,37 @@ export default class InChatCommandsService {
});
}
}
public async poke(message: Api.Message, pair: Pair) {
try {
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 (pair.qq instanceof Group && !target) {
await message.reply({
message: '<i>请回复一条消息</i>',
});
}
else if (pair.qq instanceof Group) {
await pair.qq.pokeMember(target);
}
else {
await pair.qq.poke(target && target !== pair.qqRoomId);
}
}
catch (e) {
await message.reply({
message: `<i>错误</i>\n${e.message}`,
});
}
}
}