feat(lib): adding the getUserRoles function in lib
- Needed by other modules so terminated on the lib
This commit is contained in:
parent
16f2236dd9
commit
d447937c1b
2 changed files with 11 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ import {
|
||||||
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
import { User as UserPrisma } from '@prisma/client';
|
import { User as UserPrisma } from '@prisma/client';
|
||||||
import { Guild as GuildPrisma } from '@prisma/client';
|
import { Guild as GuildPrisma } from '@prisma/client';
|
||||||
|
import { getUserRoles } from '@lib/roles';
|
||||||
import { log } from '@lib/log';
|
import { log } from '@lib/log';
|
||||||
|
|
||||||
function getGuildRoles(guild: Guild): string {
|
function getGuildRoles(guild: Guild): string {
|
||||||
|
|
@ -23,15 +24,6 @@ function getGuildRoles(guild: Guild): string {
|
||||||
return roles.length > 0 ? roles.join(', ') : 'No role';
|
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: {
|
function getUserBadges(userData: {
|
||||||
isDev?: boolean;
|
isDev?: boolean;
|
||||||
isEnium?: boolean;
|
isEnium?: boolean;
|
||||||
|
|
|
||||||
10
src/lib/roles.ts
Normal file
10
src/lib/roles.ts
Normal 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';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue