2023-09-19 23:39:41 +05:30
|
|
|
import warn from "../actions/warn";
|
|
|
|
import ban from "../actions/ban";
|
|
|
|
import batchBan from "../actions/batchBan";
|
|
|
|
import { scheduleDeletion } from "../utils/tg";
|
2018-05-04 14:21:51 +02:00
|
|
|
|
2023-09-19 23:39:41 +05:30
|
|
|
import { config } from "../utils/config";
|
|
|
|
import { ContextExtensions } from "../typings/context";
|
2018-05-04 14:21:51 +02:00
|
|
|
|
2018-11-20 11:47:30 +05:30
|
|
|
const {
|
|
|
|
warnInlineKeyboard,
|
2020-05-14 23:18:25 +02:00
|
|
|
chats = {},
|
2018-11-20 11:47:30 +05:30
|
|
|
deleteWarnsAfter = false,
|
|
|
|
deleteBansAfter = false,
|
2023-09-19 23:39:41 +05:30
|
|
|
} = config;
|
2018-05-04 14:21:51 +02:00
|
|
|
|
2023-09-19 23:39:41 +05:30
|
|
|
const normalisedDeleteWarnsAfter =
|
|
|
|
typeof deleteWarnsAfter === "object"
|
|
|
|
? deleteWarnsAfter
|
|
|
|
: { auto: deleteWarnsAfter, manual: deleteWarnsAfter };
|
2018-11-20 11:47:30 +05:30
|
|
|
|
|
|
|
const reply_markup = { inline_keyboard: warnInlineKeyboard };
|
2018-05-04 14:21:51 +02:00
|
|
|
|
2023-09-19 23:39:41 +05:30
|
|
|
export const extn: ContextExtensions = {
|
|
|
|
async ban({ admin, reason, userToBan, msg }) {
|
2018-11-20 11:47:30 +05:30
|
|
|
const banMessage = await ban({ admin, reason, userToBan });
|
2023-09-19 23:39:41 +05:30
|
|
|
|
2023-09-20 02:15:12 +05:30
|
|
|
const done = await this.loggedReply(banMessage, msg).then(
|
|
|
|
scheduleDeletion(deleteBansAfter),
|
2023-09-19 23:39:41 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
this.telegram
|
|
|
|
.deleteMessage(msg.chat.id, msg.message_id)
|
|
|
|
.catch(() => null);
|
|
|
|
|
|
|
|
return done;
|
2018-11-20 11:47:30 +05:30
|
|
|
},
|
2023-09-19 23:39:41 +05:30
|
|
|
|
2020-05-14 23:18:25 +02:00
|
|
|
async batchBan({ admin, reason, targets }) {
|
|
|
|
const banMessage = await batchBan({ admin, reason, targets });
|
2023-09-19 23:39:41 +05:30
|
|
|
return this.loggedReply(banMessage).then(scheduleDeletion(deleteBansAfter));
|
2019-01-31 20:19:39 +01:00
|
|
|
},
|
2023-09-19 23:39:41 +05:30
|
|
|
|
|
|
|
async warn({ admin, amend, reason, userToWarn, mode, msg }) {
|
2019-05-31 17:02:00 +02:00
|
|
|
const warnMessage = await warn({ admin, amend, reason, userToWarn });
|
2023-09-19 23:39:41 +05:30
|
|
|
|
2023-09-20 02:15:12 +05:30
|
|
|
const done = await this.loggedReply(warnMessage, msg, {
|
|
|
|
reply_markup,
|
|
|
|
}).then(scheduleDeletion(normalisedDeleteWarnsAfter[mode]));
|
2023-09-19 23:39:41 +05:30
|
|
|
|
|
|
|
if (msg)
|
|
|
|
this.telegram
|
|
|
|
.deleteMessage(msg.chat.id, msg.message_id)
|
|
|
|
.catch(() => null);
|
|
|
|
|
|
|
|
return done;
|
2018-05-04 14:21:51 +02:00
|
|
|
},
|
2020-02-19 08:11:32 +01:00
|
|
|
|
2023-09-19 23:39:41 +05:30
|
|
|
async loggedReply(html, reply, extra) {
|
2020-05-14 23:18:25 +02:00
|
|
|
if (chats.adminLog) {
|
2023-09-19 23:39:41 +05:30
|
|
|
const msg =
|
|
|
|
reply &&
|
|
|
|
(await this.telegram.forwardMessage(
|
2020-05-14 23:18:25 +02:00
|
|
|
chats.adminLog,
|
2023-09-19 23:39:41 +05:30
|
|
|
reply.chat.id,
|
2023-09-20 02:15:12 +05:30
|
|
|
reply.message_id,
|
2023-09-19 23:39:41 +05:30
|
|
|
));
|
|
|
|
this.telegram
|
|
|
|
// @ts-expect-error sendMessage is monkeypatched to accept TgHtml
|
|
|
|
.sendMessage(chats.adminLog, html, {
|
|
|
|
parse_mode: "HTML",
|
|
|
|
reply_to_message_id: msg?.message_id,
|
|
|
|
})
|
2020-05-14 23:18:25 +02:00
|
|
|
.catch(() => null);
|
|
|
|
}
|
2023-09-19 23:39:41 +05:30
|
|
|
// @ts-expect-error sendMessage is monkeypatched to accept TgHtml
|
2020-05-14 23:18:25 +02:00
|
|
|
return this.replyWithHTML(html, extra);
|
|
|
|
},
|
2023-10-09 00:55:57 +05:30
|
|
|
|
|
|
|
replyWithCopy(content, options) {
|
|
|
|
return this.telegram.sendCopy(this.chat.id, content, options);
|
|
|
|
},
|
2018-05-04 14:21:51 +02:00
|
|
|
};
|