mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-31 22:25:15 +00:00
feat: WIP update context.js to TS
Intermediate commit to trick git into diffing correctly
This commit is contained in:
@@ -1,55 +1,79 @@
|
|||||||
'use strict';
|
import warn from "../actions/warn";
|
||||||
|
import ban from "../actions/ban";
|
||||||
|
import batchBan from "../actions/batchBan";
|
||||||
|
import { scheduleDeletion } from "../utils/tg";
|
||||||
|
|
||||||
const warn = require('../actions/warn');
|
import { config } from "../utils/config";
|
||||||
const ban = require('../actions/ban');
|
import { ContextExtensions } from "../typings/context";
|
||||||
const batchBan = require('../actions/batchBan');
|
|
||||||
const { scheduleDeletion } = require('../utils/tg');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
warnInlineKeyboard,
|
warnInlineKeyboard,
|
||||||
chats = {},
|
chats = {},
|
||||||
deleteWarnsAfter = false,
|
deleteWarnsAfter = false,
|
||||||
deleteBansAfter = false,
|
deleteBansAfter = false,
|
||||||
} = require('../utils/config').config;
|
} = config;
|
||||||
|
|
||||||
const normalisedDeleteWarnsAfter = typeof deleteWarnsAfter === 'object'
|
const normalisedDeleteWarnsAfter =
|
||||||
? { auto: false, manual: false, ...deleteWarnsAfter }
|
typeof deleteWarnsAfter === "object"
|
||||||
: { auto: deleteWarnsAfter, manual: deleteWarnsAfter };
|
? deleteWarnsAfter
|
||||||
|
: { auto: deleteWarnsAfter, manual: deleteWarnsAfter };
|
||||||
|
|
||||||
const reply_markup = { inline_keyboard: warnInlineKeyboard };
|
const reply_markup = { inline_keyboard: warnInlineKeyboard };
|
||||||
|
|
||||||
/** @type { import('../typings/context').ContextExtensions } */
|
export const extn: ContextExtensions = {
|
||||||
module.exports = {
|
async ban({ admin, reason, userToBan, msg }) {
|
||||||
async ban({ admin, reason, userToBan }) {
|
|
||||||
const banMessage = await ban({ admin, reason, userToBan });
|
const banMessage = await ban({ admin, reason, userToBan });
|
||||||
return this.loggedReply(banMessage)
|
|
||||||
.then(scheduleDeletion(deleteBansAfter));
|
const done = this.loggedReply(banMessage, msg).then(
|
||||||
|
scheduleDeletion(deleteBansAfter)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (msg)
|
||||||
|
this.telegram
|
||||||
|
.deleteMessage(msg.chat.id, msg.message_id)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
return done;
|
||||||
},
|
},
|
||||||
|
|
||||||
async batchBan({ admin, reason, targets }) {
|
async batchBan({ admin, reason, targets }) {
|
||||||
const banMessage = await batchBan({ admin, reason, targets });
|
const banMessage = await batchBan({ admin, reason, targets });
|
||||||
return this.loggedReply(banMessage)
|
return this.loggedReply(banMessage).then(scheduleDeletion(deleteBansAfter));
|
||||||
.then(scheduleDeletion(deleteBansAfter));
|
|
||||||
},
|
|
||||||
async warn({ admin, amend, reason, userToWarn, mode }) {
|
|
||||||
const warnMessage = await warn({ admin, amend, reason, userToWarn });
|
|
||||||
return this.loggedReply(warnMessage, { reply_markup })
|
|
||||||
.then(scheduleDeletion(normalisedDeleteWarnsAfter[mode]));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loggedReply(html, extra) {
|
async warn({ admin, amend, reason, userToWarn, mode, msg }) {
|
||||||
|
const warnMessage = await warn({ admin, amend, reason, userToWarn });
|
||||||
|
|
||||||
|
const done = this.loggedReply(warnMessage, msg, { reply_markup }).then(
|
||||||
|
scheduleDeletion(normalisedDeleteWarnsAfter[mode])
|
||||||
|
);
|
||||||
|
|
||||||
|
if (msg)
|
||||||
|
this.telegram
|
||||||
|
.deleteMessage(msg.chat.id, msg.message_id)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
},
|
||||||
|
|
||||||
|
async loggedReply(html, reply, extra) {
|
||||||
if (chats.adminLog) {
|
if (chats.adminLog) {
|
||||||
this.tg
|
const msg =
|
||||||
.sendMessage(
|
reply &&
|
||||||
|
(await this.telegram.forwardMessage(
|
||||||
chats.adminLog,
|
chats.adminLog,
|
||||||
html.toJSON().replace(/\[<code>(\d+)<\/code>\]/g, '[#u$1]'),
|
reply.chat.id,
|
||||||
{ parse_mode: 'HTML' },
|
reply.message_id
|
||||||
)
|
));
|
||||||
|
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,
|
||||||
|
})
|
||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
}
|
}
|
||||||
|
// @ts-expect-error sendMessage is monkeypatched to accept TgHtml
|
||||||
return this.replyWithHTML(html, extra);
|
return this.replyWithHTML(html, extra);
|
||||||
},
|
},
|
||||||
|
|
||||||
replyWithCopy(content, options) {
|
|
||||||
return this.telegram.sendCopy(this.chat.id, content, options);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user