-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: #169 from feat/better-admin-log
- Loading branch information
Showing
16 changed files
with
2,299 additions
and
1,673 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
name: Checks | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run : npm ci | ||
- name: Lint | ||
run: npm run -s lint | ||
- name: Typecheck | ||
run: npm run -s typecheck |
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
import warn from "../actions/warn"; | ||
import ban from "../actions/ban"; | ||
import batchBan from "../actions/batchBan"; | ||
import { scheduleDeletion } from "../utils/tg"; | ||
|
||
import { config } from "../utils/config"; | ||
import { ContextExtensions } from "../typings/context"; | ||
|
||
const { | ||
warnInlineKeyboard, | ||
chats = {}, | ||
deleteWarnsAfter = false, | ||
deleteBansAfter = false, | ||
} = config; | ||
|
||
const normalisedDeleteWarnsAfter = | ||
typeof deleteWarnsAfter === "object" | ||
? deleteWarnsAfter | ||
: { auto: deleteWarnsAfter, manual: deleteWarnsAfter }; | ||
|
||
const reply_markup = { inline_keyboard: warnInlineKeyboard }; | ||
|
||
export const extn: ContextExtensions = { | ||
async ban({ admin, reason, userToBan, msg }) { | ||
const banMessage = await ban({ admin, reason, userToBan }); | ||
|
||
const done = await 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 }) { | ||
const banMessage = await batchBan({ admin, reason, targets }); | ||
return this.loggedReply(banMessage).then(scheduleDeletion(deleteBansAfter)); | ||
}, | ||
|
||
async warn({ admin, amend, reason, userToWarn, mode, msg }) { | ||
const warnMessage = await warn({ admin, amend, reason, userToWarn }); | ||
|
||
const done = await 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) { | ||
const msg = | ||
reply && | ||
(await this.telegram.forwardMessage( | ||
chats.adminLog, | ||
reply.chat.id, | ||
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); | ||
} | ||
// @ts-expect-error sendMessage is monkeypatched to accept TgHtml | ||
return this.replyWithHTML(html, extra); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,28 @@ | ||
import { CallbackQuery, Message, Update } from "telegraf/types"; | ||
import { config } from "../../utils/config"; | ||
import type { ExtendedContext } from "../../typings/context"; | ||
|
||
export = (ctx: ExtendedContext) => { | ||
export = async ( | ||
ctx: ExtendedContext<Update.CallbackQueryUpdate<CallbackQuery.DataQuery>>, | ||
) => { | ||
if (ctx.from?.status !== "admin") { | ||
return ctx.answerCbQuery("✋ Not permitted!", false, { cache_time: 600 }); | ||
return ctx.answerCbQuery("✋ Not permitted!", { cache_time: 600 }); | ||
} | ||
|
||
const [, chatId, msgId] = ctx.match!; | ||
// @ts-expect-error ctx.match is available but not registered in this callback type | ||
const [, chatId, msgId] = (ctx.match as string[])!; | ||
|
||
// delete the report in the actual chat | ||
await ctx.telegram.deleteMessage(+chatId, +msgId); | ||
|
||
if (config.chats?.noReportChatDeletion) return null; | ||
return Promise.all([ | ||
// delete the report in the report chat | ||
ctx.deleteMessage(), | ||
ctx.telegram.deleteMessage(+chatId, +msgId), | ||
// delete the forwarded contextual message in report chat | ||
ctx.deleteMessage( | ||
(ctx.callbackQuery.message as Message.TextMessage)?.reply_to_message | ||
?.message_id, | ||
), | ||
]); | ||
}; |
Oops, something went wrong.