import type { BotType } from '@/bot/index.js' import { bold, code, format } from 'gramio' import { updateChatCommands } from '@/bot/utilities/commands.js' import { PermissionService } from '@/shared/services/permission.js' import { RoleService } from '@/shared/services/role.js' 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 canManage = await PermissionService.canManageRoles(ctx.chat.id, ctx.from.id) if (!canManage) { return ctx.reply('You don\'t have permission to manage roles') } let [roleSlug] = (ctx.args ?? '').trim().split(' ') if (!roleSlug) { return ctx.reply(format`where is the role name bro?\nusage: ${code('/roledel ')}`) } 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') } updateChatCommands(bot, ctx.chatId) return ctx.reply(format`role ${bold(role.slug)} deleted`) }) }