import { FmtString } from './format' export const env = process.env export type Expand = T extends object ? T extends infer O ? { [K in keyof O]: O[K] } : never : T type MaybeExtra = (Extra & { caption?: string }) | undefined export function fmtCaption< Extra extends { caption?: string | FmtString } & Record >(extra?: Extra): MaybeExtra { const caption = extra?.caption if (!caption || typeof caption === 'string') return extra as MaybeExtra const { text, entities } = caption return { ...extra, caption: text, ...(entities && { caption_entities: entities, parse_mode: undefined, }), } } export function deprecate( method: string, ignorable: string | undefined, use: string | undefined, see?: string ) { // don't use deprecate() yet // wait for a couple minor releases of telegraf so the news reaches more people return const ignorer = `IGNORE_DEPRECATED_${ignorable}` if (env[ignorer]) return const stack: { stack: string } = { stack: '' } Error.captureStackTrace(stack) const line = (stack.stack.split('\n')[3] || '').trim() const useOther = use ? `; use ${use} instead` : '' const pad = ' '.repeat('[WARN]'.length) console.warn(`[WARN] ${method} is deprecated${useOther}`) if (line) console.warn(pad, line) if (see) console.warn(pad, `SEE ${see}`) }