mirror of https://github.com/Nofated095/Q2TG.git
feat: /q 后自动在 tg pin 原消息,在 QQ 将原消息设为精华
This commit is contained in:
parent
d2a60b3cd0
commit
fdbfda72d4
|
@ -728,7 +728,7 @@ Network Trash Folder
|
||||||
Temporary Items
|
Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
|
|
||||||
data/
|
data
|
||||||
config.yaml
|
config.yaml
|
||||||
build
|
build
|
||||||
.yarn/*
|
.yarn/*
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
|
@ -7,6 +7,7 @@ enum flags {
|
||||||
NO_AUTO_CREATE_PM = 1 << 5,
|
NO_AUTO_CREATE_PM = 1 << 5,
|
||||||
COLOR_EMOJI_PREFIX = 1 << 6,
|
COLOR_EMOJI_PREFIX = 1 << 6,
|
||||||
RICH_HEADER = 1 << 7,
|
RICH_HEADER = 1 << 7,
|
||||||
|
NO_QUOTE_PIN = 1 << 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default flags;
|
export default flags;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Instance from '../models/Instance';
|
||||||
import Telegram from '../client/Telegram';
|
import Telegram from '../client/Telegram';
|
||||||
import OicqClient from '../client/OicqClient';
|
import OicqClient from '../client/OicqClient';
|
||||||
import { getLogger, Logger } from 'log4js';
|
import { getLogger, Logger } from 'log4js';
|
||||||
import { GroupMessageEvent, PrivateMessageEvent } from 'icqq';
|
import { Group, GroupMessageEvent, PrivateMessageEvent } from 'icqq';
|
||||||
import { Api } from 'telegram';
|
import { Api } from 'telegram';
|
||||||
import quotly from 'quote-api/methods/generate.js';
|
import quotly from 'quote-api/methods/generate.js';
|
||||||
import { CustomFile } from 'telegram/client/uploads';
|
import { CustomFile } from 'telegram/client/uploads';
|
||||||
|
@ -13,6 +13,7 @@ import { getAvatarUrl } from '../utils/urls';
|
||||||
import convert from '../helpers/convert';
|
import convert from '../helpers/convert';
|
||||||
import { Pair } from '../models/Pair';
|
import { Pair } from '../models/Pair';
|
||||||
import env from '../models/env';
|
import env from '../models/env';
|
||||||
|
import flags from '../constants/flags';
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
private readonly log: Logger;
|
private readonly log: Logger;
|
||||||
|
@ -55,16 +56,14 @@ export default class {
|
||||||
this.log.error('找不到 sourceMessage');
|
this.log.error('找不到 sourceMessage');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
setTimeout(async () => {
|
if (!((pair.flags | this.instance.flags) & flags.NO_QUOTE_PIN)) {
|
||||||
// 异步发送,为了让 /q 先到达
|
this.pinMessageOnBothSide(pair, sourceMessage).then();
|
||||||
try {
|
}
|
||||||
await this.sendQuote(pair, sourceMessage);
|
// 异步发送,为了让 /q 先到达
|
||||||
}
|
this.sendQuote(pair, sourceMessage).catch(async e => {
|
||||||
catch (e) {
|
this.log.error(e);
|
||||||
this.log.error(e);
|
await event.reply(e.toString(), true);
|
||||||
await event.reply(e.toString(), true);
|
});
|
||||||
}
|
|
||||||
}, 50);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private onTelegramMessage = async (message: Api.Message) => {
|
private onTelegramMessage = async (message: Api.Message) => {
|
||||||
|
@ -91,22 +90,39 @@ export default class {
|
||||||
this.log.error('找不到 sourceMessage');
|
this.log.error('找不到 sourceMessage');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
setTimeout(async () => {
|
if (!((pair.flags | this.instance.flags) & flags.NO_QUOTE_PIN)) {
|
||||||
try {
|
this.pinMessageOnBothSide(pair, sourceMessage).then();
|
||||||
await this.sendQuote(pair, sourceMessage);
|
}
|
||||||
}
|
// 异步发送,为了让 /q 先到达
|
||||||
catch (e) {
|
this.sendQuote(pair, sourceMessage).catch(async e => {
|
||||||
this.log.error(e);
|
this.log.error(e);
|
||||||
await message.reply({
|
await message.reply({
|
||||||
message: e.toString(),
|
message: e.toString(),
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}, 50);
|
|
||||||
|
|
||||||
// 个人模式下,/q 这条消息不转发到 QQ,怪话图只有自己可见
|
// 个人模式下,/q 这条消息不转发到 QQ,怪话图只有自己可见
|
||||||
if (this.instance.workMode === 'personal') return true;
|
if (this.instance.workMode === 'personal') return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private async pinMessageOnBothSide(pair: Pair, sourceMessage: Awaited<ReturnType<typeof db.message.findFirst>>) {
|
||||||
|
if (pair.qq instanceof Group) {
|
||||||
|
try {
|
||||||
|
await pair.qq.addEssence(sourceMessage.seq, Number(sourceMessage.rand));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.log.warn('无法添加精华消息,群:', pair.qqRoomId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const tgMessage = await pair.tg.getMessage({ ids: sourceMessage.tgMsgId });
|
||||||
|
await tgMessage.pin({ notify: false, pmOneSide: false });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.log.warn('无法置顶消息,群:', pair.tgId, '消息 ID:', sourceMessage.tgMsgId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async genQuote(message: Message) {
|
private async genQuote(message: Message) {
|
||||||
const GROUP_ANONYMOUS_BOT = 1087968824n;
|
const GROUP_ANONYMOUS_BOT = 1087968824n;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue