import { api } from '@rocket.chat/core-services'; import type { SlashCommandCallbackParams } from '@rocket.chat/core-typings'; import { Users } from '@rocket.chat/models'; import { i18n } from '../../lib/i18n'; import { slashCommands } from '../../lib/utils/slashCommand'; import { unmuteUserInRoom } from '../../meteor-methods/rooms/unmuteUserInRoom'; import { settings } from '../../settings'; /* * Unmute is a named function that will replace /unmute commands */ slashCommands.add({ command: 'unmute', callback: async function Unmute({ params, message, userId }: SlashCommandCallbackParams<'unmute'>): Promise { const username = params.trim().replace('@', ''); if (username === '') { return; } const unmutedUser = await Users.findOneByUsernameIgnoringCase(username); if (unmutedUser == null) { void api.broadcast('notify.ephemeralMessage', userId, message.rid, { msg: i18n.t('Username_doesnt_exist', { interpolation: { escapeValue: false }, username, lng: settings.get('Language') || 'en', }), }); return; } await unmuteUserInRoom(userId, { rid: message.rid, username, }); }, options: { description: 'Unmute_someone_in_room', params: '@username', permission: 'mute-user', }, });