feat: initial commit
This commit is contained in:
commit
e54dee08c8
29 changed files with 4857 additions and 0 deletions
39
src/shared/services/mention.ts
Normal file
39
src/shared/services/mention.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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: '' }))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue