Initial commit
This commit is contained in:
7
src/bot/helpers/keyboard.ts
Normal file
7
src/bot/helpers/keyboard.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function chunk<T>(array: T[], size: number) {
|
||||
const result = []
|
||||
for (let index = 0; index < array.length; index += size)
|
||||
result.push(array.slice(index, index + size))
|
||||
|
||||
return result
|
||||
}
|
||||
20
src/bot/helpers/logging.ts
Normal file
20
src/bot/helpers/logging.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { Context } from '#root/bot/context.js'
|
||||
import type { Update } from '@grammyjs/types'
|
||||
import type { Middleware } from 'grammy'
|
||||
|
||||
export function getUpdateInfo(ctx: Context): Omit<Update, 'update_id'> {
|
||||
const { update_id, ...update } = ctx.update
|
||||
|
||||
return update
|
||||
}
|
||||
|
||||
export function logHandle(id: string): Middleware<Context> {
|
||||
return (ctx, next) => {
|
||||
ctx.logger.info({
|
||||
msg: `Handle "${id}"`,
|
||||
...(id.startsWith('unhandled') ? { update: getUpdateInfo(ctx) } : {}),
|
||||
})
|
||||
|
||||
return next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user