-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Instance from '../models/Instance'; | ||
import Telegram from '../client/Telegram'; | ||
import { GroupNameChangeEvent, QQClient } from '../client/QQClient'; | ||
import flags from '../constants/flags'; | ||
import { NapCatGroupMember } from '../client/NapCatClient'; | ||
import env from '../models/env'; | ||
import helper from '../helpers/forwardHelper'; | ||
import { getLogger, Logger } from 'log4js'; | ||
|
||
export default class GroupNameRefreshController { | ||
private readonly log: Logger; | ||
|
||
constructor(private readonly instance: Instance, | ||
private readonly tgBot: Telegram, | ||
private readonly tgUser: Telegram, | ||
private readonly oicq: QQClient) { | ||
oicq.addGroupNameChangeHandler(this.handleGroupNameChange.bind(this)); | ||
this.log = getLogger(`GroupNameRefreshController - ${instance.id}`); | ||
} | ||
|
||
private async handleGroupNameChange(event: GroupNameChangeEvent) { | ||
this.log.debug(event); | ||
const pair = this.instance.forwardPairs.find(event.group); | ||
if (!pair) return; | ||
|
||
if ((pair.flags | this.instance.flags) & flags.NAME_LOCKED) return; | ||
await pair.tg.editTitle(event.newName); | ||
|
||
if(event.operator instanceof NapCatGroupMember) { | ||
const operatorInfo = await event.operator.renew(); | ||
let operatorName = operatorInfo.card || operatorInfo.nickname; | ||
if (!((pair.flags | this.instance.flags) & flags.DISABLE_RICH_HEADER) && env.WEB_ENDPOINT) { | ||
const richHeaderUrl = helper.generateRichHeaderUrl(pair.apiKey, operatorInfo.user_id, operatorName); | ||
operatorName = `<a href="${richHeaderUrl}">${operatorName}</a>`; | ||
} | ||
|
||
await pair.tg.sendMessage({ | ||
message: `<i>${operatorName} 修改群名为 <b>${event.newName}</b></i>`, | ||
parseMode: 'html', | ||
silent: true, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters