feat: improve mention handling in bot and mention services
This commit is contained in:
parent
e54dee08c8
commit
1f1985c1ac
2 changed files with 24 additions and 23 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import { join } from 'node:path'
|
||||
import { autoload } from '@gramio/autoload'
|
||||
import { Bot, mention } from 'gramio'
|
||||
import { Bot } from 'gramio'
|
||||
import env from '@/shared/env.js'
|
||||
import { RoleService } from '@/shared/services/role.js'
|
||||
import { MentionService } from '@/shared/services/mention.js'
|
||||
import { RoleService } from '@/shared/services/role.js'
|
||||
|
||||
let botUsername: string | undefined
|
||||
|
||||
|
|
@ -15,10 +15,6 @@ export const bot = new Bot(env.botToken)
|
|||
export type BotType = typeof bot
|
||||
|
||||
bot.on('message', async (ctx, next) => {
|
||||
// if (ctx.chatId !== -1003212318013) {
|
||||
// return
|
||||
// }
|
||||
|
||||
if (!ctx.hasEntities('mention')) {
|
||||
return next()
|
||||
}
|
||||
|
|
@ -27,14 +23,14 @@ bot.on('message', async (ctx, next) => {
|
|||
if (!mentions.length) {
|
||||
return next()
|
||||
}
|
||||
const rolesToMention = await Promise.all(mentions.map((mention) => RoleService.getBySlugOrAlias(mention.slice(1), ctx.chatId))).then((roles) => roles.filter((role) => role !== null))
|
||||
const rolesToMention = await Promise.all(mentions.map(mention => RoleService.getBySlugOrAlias(mention.slice(1), ctx.chatId))).then(roles => roles.filter(role => role !== null))
|
||||
|
||||
if (!rolesToMention.length) {
|
||||
return next()
|
||||
}
|
||||
|
||||
for (const role of rolesToMention) {
|
||||
await MentionService.mentionAll(role.slug, ctx.chatId, ctx.from, ctx.replyMessage?.id ?? undefined)
|
||||
await MentionService.mentionAll(role.slug, ctx.chatId, ctx.from, ctx.replyMessage?.id ?? ctx.id)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -74,7 +70,7 @@ bot.onStart(async ({ info }) => {
|
|||
|
||||
await bot.api.setMyCommands({
|
||||
scope: {
|
||||
type: 'default'
|
||||
type: 'default',
|
||||
},
|
||||
commands: [
|
||||
{ command: 'roleadd', description: 'Add a new role in this chat' },
|
||||
|
|
@ -84,6 +80,6 @@ bot.onStart(async ({ info }) => {
|
|||
{ command: 'myroles', description: 'View your roles in this chat' },
|
||||
{ command: 'roles', description: 'View all roles in this chat' },
|
||||
],
|
||||
suppress: true
|
||||
suppress: true,
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue