mirror of https://github.com/Nofated095/Q2TG.git
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
|
import InChatCommandsService from '../services/InChatCommandsService';
|
||
|
import { getLogger, Logger } from 'log4js';
|
||
|
import Instance from '../models/Instance';
|
||
|
import Telegram from '../client/Telegram';
|
||
|
import OicqClient from '../client/OicqClient';
|
||
|
import { Api } from 'telegram';
|
||
|
|
||
|
export default class InChatCommandsController {
|
||
|
private readonly service: InChatCommandsService;
|
||
|
private readonly log: Logger;
|
||
|
|
||
|
constructor(private readonly instance: Instance,
|
||
|
private readonly tgBot: Telegram,
|
||
|
private readonly oicq: OicqClient) {
|
||
|
this.log = getLogger(`InChatCommandsController - ${instance.id}`);
|
||
|
this.service = new InChatCommandsService(instance, tgBot, oicq);
|
||
|
tgBot.addNewMessageEventHandler(this.onTelegramMessage);
|
||
|
}
|
||
|
|
||
|
private onTelegramMessage = async (message: Api.Message) => {
|
||
|
if (!message.message) return;
|
||
|
const messageParts = message.message.split(' ');
|
||
|
if (!messageParts.length || !messageParts[0].startsWith('/')) return;
|
||
|
let command: string = messageParts[0];
|
||
|
if (command.includes('@')) {
|
||
|
let target: string;
|
||
|
[command, target] = command.split('@');
|
||
|
if (target !== this.tgBot.me.username) return false;
|
||
|
}
|
||
|
const pair = this.instance.forwardPairs.find(message.chat);
|
||
|
switch (command) {
|
||
|
case '/info':
|
||
|
await this.service.info(message, pair);
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
}
|