import { bold, format, join, mention, TelegramUser, User } from 'gramio' import { chunk } from '../utilities/chunk.js' import { RoleService } from './role.js' import { bot } from '@/bot/index.js' export class MentionService { static async mentionAll(query: string, chatId: number, caller: User, replyMessageId?: number) { const role = await RoleService.getBySlugOrAlias(query, chatId) if (!role) { throw new Error('Role not found') } const members = await RoleService.getMemberIds(query, chatId) const membersChunks = chunk(members, 5) for (const memberChunk of membersChunks) { const message = format` ${bold('Mass mention by')} ${bold(mention('user', { id: caller.id, is_bot: caller.isBot(), first_name: caller.firstName }))} ${join(this.buildMentions(memberChunk), (entity) => entity, ' ')} ` await bot.api.sendMessage({ chat_id: role.chatId, text: message, ...(replyMessageId ? { reply_parameters: { message_id: replyMessageId, allow_sending_without_reply: true } }: {}) }) } } static buildMentions (ids: number[]) { return ids.map((id) => mention('👋', { id, is_bot: false, first_name: '' })) } }