feat(lib): adding the getUserRoles function in lib

- Needed by other modules so terminated on the lib
This commit is contained in:
Raphael 2025-11-25 15:12:01 +01:00 committed by Raphaël
parent 16f2236dd9
commit d447937c1b
2 changed files with 11 additions and 9 deletions

View file

@ -12,6 +12,7 @@ import {
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { User as UserPrisma } from '@prisma/client';
import { Guild as GuildPrisma } from '@prisma/client';
import { getUserRoles } from '@lib/roles';
import { log } from '@lib/log';
function getGuildRoles(guild: Guild): string {
@ -23,15 +24,6 @@ function getGuildRoles(guild: Guild): string {
return roles.length > 0 ? roles.join(', ') : 'No role';
}
function getUserRoles(target: GuildMember): string {
const roles = target.roles.cache
.filter((role) => role.id !== target.guild.id)
.sort((a, b) => b.position - a.position)
.map((role) => roleMention(role.id));
return roles.length > 0 ? roles.join(', ') : 'No role';
}
function getUserBadges(userData: {
isDev?: boolean;
isEnium?: boolean;

10
src/lib/roles.ts Normal file
View file

@ -0,0 +1,10 @@
import { GuildMember, roleMention } from 'discord.js';
export function getUserRoles(target: GuildMember): string {
const roles = target.roles.cache
.filter((role) => role.id !== target.guild.id)
.sort((a, b) => b.position - a.position)
.map((role) => roleMention(role.id));
return roles.length > 0 ? roles.join(', ') : 'No role';
}