Skip to content

Commit 261c6ce

Browse files
committed
feat: Updated MuteService to accept optional durationStr parameter and WarnService to call MuteService with a 1-day mute duration after warning limit is reached.
1 parent 04f85a0 commit 261c6ce

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/bot/service/admin/Mute.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ export class MuteService {
88
* @param ctx - The bot context.
99
* @returns A message indicating the duration of the mute.
1010
*/
11-
static async muteUser(ctx: Context): Promise<string> {
11+
static async muteUser(ctx: Context, durationStr?: string | null): Promise<string> {
1212
const replyMessage = ctx.message?.reply_to_message;
1313
if (!replyMessage) {
1414
return 'Please reply to a user to mute them.';
1515
}
1616

1717
const userId = replyMessage.from?.id!;
18-
const durationStr = MuteService.extractDurationFromCommand(ctx.message?.text);
18+
if (!durationStr) {
19+
durationStr = MuteService.extractDurationFromCommand(ctx.message?.text);
20+
}
1921
const durationMs = durationStr ? parseDuration(durationStr) : null;
2022

2123
const expiration = durationMs ? new Date(tehranZone().getTime() + durationMs) : null;

src/bot/service/admin/Warn.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Context } from 'grammy';
22
import { AdminValidationService } from './validation';
33
import { ServiceProvider } from '../../../service/database/ServiceProvider';
4+
import { MuteService } from './Mute';
45

56
export class WarnService {
67
static async warnUser(ctx: Context): Promise<{
@@ -64,6 +65,7 @@ export class WarnService {
6465
};
6566
await warnService.delete(warn.id);
6667
await Promise.all([groupService.update(updatedGroup), userService.update(updatedUser)]);
68+
await MuteService.muteUser(ctx, '1d');
6769
return {
6870
warningApplied: true,
6971
isWarningLimitReached: true,

0 commit comments

Comments
 (0)