Skip to content

Commit

Permalink
add preview command
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Sep 26, 2024
1 parent bd69b63 commit 213caa3
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/modules/hmny/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { type BroadcastError } from './types'
// import { docsMenu, docsMenuLabel } from './helpers'

export enum SupportedCommands {
broadcast = 'broadcast'
broadcast = 'broadcast',
preview = 'preview'
// docs = 'docs'
}

Expand Down Expand Up @@ -67,6 +68,11 @@ export class HmnyBot implements PayableBot {
// return
// }

if (ctx.hasCommand(SupportedCommands.preview)) {
await this.onBroadcast(ctx, true)
return
}

if (ctx.hasCommand(SupportedCommands.broadcast)) {
await this.onBroadcast(ctx)
return
Expand Down Expand Up @@ -103,7 +109,7 @@ export class HmnyBot implements PayableBot {
// ctx.transient.analytics.sessionState = RequestState.Success
// }

onBroadcast = async (ctx: OnMessageContext | OnCallBackQueryData): Promise<void> => {
onBroadcast = async (ctx: OnMessageContext | OnCallBackQueryData, isPreview = false): Promise<void> => {
const chatErrors: BroadcastError[] = []
let errorMessage = ''
if (await isAdmin(ctx, false, true) && ctx.chat?.type === 'private') {
Expand All @@ -113,6 +119,17 @@ export class HmnyBot implements PayableBot {
ctx.transient.analytics.actualResponseTime = now()
return
}
const urls = ctx.entities('url')
const linksPreview = urls.length > 1
if (isPreview) {
await ctx.reply(
ctx.match as string,
{
parse_mode: 'Markdown',
link_preview_options: { is_disabled: linksPreview }
})
return
}
const chatsArray = await statsService.getAllChatId()
// const chatsArray = [
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
Expand All @@ -136,12 +153,9 @@ export class HmnyBot implements PayableBot {
// 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380,
// 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400
// ]
const urls = ctx.entities('url')
const linksPreview = urls.length > 1
let counter = 0
const batchSize = 29
const delayMs = 2000

for (let i = 0; i < chatsArray.length; i += batchSize) {
const batch = chatsArray.slice(i, i + batchSize)

Expand Down

0 comments on commit 213caa3

Please sign in to comment.