|
1 | | -'use strict'; |
| 1 | +import warn from "../actions/warn"; |
| 2 | +import ban from "../actions/ban"; |
| 3 | +import batchBan from "../actions/batchBan"; |
| 4 | +import { scheduleDeletion } from "../utils/tg"; |
2 | 5 |
|
3 | | -const warn = require('../actions/warn'); |
4 | | -const ban = require('../actions/ban'); |
5 | | -const batchBan = require('../actions/batchBan'); |
6 | | -const { scheduleDeletion } = require('../utils/tg'); |
| 6 | +import { config } from "../utils/config"; |
| 7 | +import { ContextExtensions } from "../typings/context"; |
7 | 8 |
|
8 | 9 | const { |
9 | 10 | warnInlineKeyboard, |
10 | 11 | chats = {}, |
11 | 12 | deleteWarnsAfter = false, |
12 | 13 | deleteBansAfter = false, |
13 | | -} = require('../utils/config').config; |
| 14 | +} = config; |
14 | 15 |
|
15 | | -const normalisedDeleteWarnsAfter = typeof deleteWarnsAfter === 'object' |
16 | | - ? { auto: false, manual: false, ...deleteWarnsAfter } |
17 | | - : { auto: deleteWarnsAfter, manual: deleteWarnsAfter }; |
| 16 | +const normalisedDeleteWarnsAfter = |
| 17 | + typeof deleteWarnsAfter === "object" |
| 18 | + ? deleteWarnsAfter |
| 19 | + : { auto: deleteWarnsAfter, manual: deleteWarnsAfter }; |
18 | 20 |
|
19 | 21 | const reply_markup = { inline_keyboard: warnInlineKeyboard }; |
20 | 22 |
|
21 | | -/** @type { import('../typings/context').ContextExtensions } */ |
22 | | -module.exports = { |
23 | | - async ban({ admin, reason, userToBan }) { |
| 23 | +export const extn: ContextExtensions = { |
| 24 | + async ban({ admin, reason, userToBan, msg }) { |
24 | 25 | const banMessage = await ban({ admin, reason, userToBan }); |
25 | | - return this.loggedReply(banMessage) |
26 | | - .then(scheduleDeletion(deleteBansAfter)); |
| 26 | + |
| 27 | + const done = this.loggedReply(banMessage, msg).then( |
| 28 | + scheduleDeletion(deleteBansAfter) |
| 29 | + ); |
| 30 | + |
| 31 | + if (msg) |
| 32 | + this.telegram |
| 33 | + .deleteMessage(msg.chat.id, msg.message_id) |
| 34 | + .catch(() => null); |
| 35 | + |
| 36 | + return done; |
27 | 37 | }, |
| 38 | + |
28 | 39 | async batchBan({ admin, reason, targets }) { |
29 | 40 | const banMessage = await batchBan({ admin, reason, targets }); |
30 | | - return this.loggedReply(banMessage) |
31 | | - .then(scheduleDeletion(deleteBansAfter)); |
| 41 | + return this.loggedReply(banMessage).then(scheduleDeletion(deleteBansAfter)); |
32 | 42 | }, |
33 | | - async warn({ admin, amend, reason, userToWarn, mode }) { |
| 43 | + |
| 44 | + async warn({ admin, amend, reason, userToWarn, mode, msg }) { |
34 | 45 | const warnMessage = await warn({ admin, amend, reason, userToWarn }); |
35 | | - return this.loggedReply(warnMessage, { reply_markup }) |
36 | | - .then(scheduleDeletion(normalisedDeleteWarnsAfter[mode])); |
| 46 | + |
| 47 | + const done = this.loggedReply(warnMessage, msg, { reply_markup }).then( |
| 48 | + scheduleDeletion(normalisedDeleteWarnsAfter[mode]) |
| 49 | + ); |
| 50 | + |
| 51 | + if (msg) |
| 52 | + this.telegram |
| 53 | + .deleteMessage(msg.chat.id, msg.message_id) |
| 54 | + .catch(() => null); |
| 55 | + |
| 56 | + return done; |
37 | 57 | }, |
38 | 58 |
|
39 | | - loggedReply(html, extra) { |
| 59 | + async loggedReply(html, reply, extra) { |
40 | 60 | if (chats.adminLog) { |
41 | | - this.tg |
42 | | - .sendMessage( |
| 61 | + const msg = |
| 62 | + reply && |
| 63 | + (await this.telegram.forwardMessage( |
43 | 64 | chats.adminLog, |
44 | | - html.toJSON().replace(/\[<code>(\d+)<\/code>\]/g, '[#u$1]'), |
45 | | - { parse_mode: 'HTML' }, |
46 | | - ) |
| 65 | + reply.chat.id, |
| 66 | + reply.message_id |
| 67 | + )); |
| 68 | + this.telegram |
| 69 | + // @ts-expect-error sendMessage is monkeypatched to accept TgHtml |
| 70 | + .sendMessage(chats.adminLog, html, { |
| 71 | + parse_mode: "HTML", |
| 72 | + reply_to_message_id: msg?.message_id, |
| 73 | + }) |
47 | 74 | .catch(() => null); |
48 | 75 | } |
| 76 | + // @ts-expect-error sendMessage is monkeypatched to accept TgHtml |
49 | 77 | return this.replyWithHTML(html, extra); |
50 | 78 | }, |
51 | | - |
52 | | - replyWithCopy(content, options) { |
53 | | - return this.telegram.sendCopy(this.chat.id, content, options); |
54 | | - }, |
55 | 79 | }; |
0 commit comments