feat: initial commit

This commit is contained in:
devilreef 2025-11-21 19:04:14 +06:00
commit e54dee08c8
29 changed files with 4857 additions and 0 deletions

View file

@ -0,0 +1,53 @@
import { BotType } from "@/bot/index.js"
import { isChatAdmin } from "@/bot/utilities/perms.js"
import { RoleService } from "@/shared/services/role.js"
import { bold, code, format } from "gramio"
export default (bot: BotType) => {
bot.command('roledel', async (ctx) => {
if (!['group', 'supergroup'].includes(ctx.chat.type)) {
return ctx.reply('this command can only be used in groups or supergroups')
}
const isAdmin = await isChatAdmin(ctx.chat.id, ctx.from.id)
if (!isAdmin) {
return ctx.reply('this command can only be used by admins')
}
let [roleSlug] = (ctx.args ?? '').trim().split(' ')
if (!roleSlug) {
return ctx.reply(format`where is the role name bro?\nusage: ${code('/roledel <name>')}`)
}
roleSlug = roleSlug.toLowerCase()
const role = await RoleService.getBySlugOrAlias(roleSlug, ctx.chatId)
if (!role) {
return ctx.reply('role not found')
}
const members = await RoleService.getMemberIds(roleSlug, ctx.chatId)
await Promise.all(members.map((member) => RoleService.removeMember(role.id!, member)))
const deletedRole = await RoleService.delete(role.id!)
if (!deletedRole) {
return ctx.reply('failed to delete role, skill issue')
}
setImmediate(async () => {
const roles = await RoleService.getByChatId(ctx.chatId)
await bot.api.setMyCommands({
scope: {
chat_id: ctx.chatId,
type: 'chat'
},
commands: roles.map((role) => ({
command: role.slug,
description: `Mention all members of this role`,
})),
})
})
return ctx.reply(format`role ${bold(role.slug)} deleted`)
})
}