fix(roles): Member#roles now uses MemberRolesManager instead of Role[]
This commit is contained in:
parent
7ba8978276
commit
72f0b91643
6 changed files with 18 additions and 23 deletions
|
@ -20,7 +20,7 @@ export class MemberRolesManager extends BaseChildManager<
|
|||
|
||||
async get (id: string): Promise<Role | undefined> {
|
||||
const res = await this.parent.get(id)
|
||||
const mem = await (this.parent as any).guild.members.get(this.member.id) as MemberPayload
|
||||
const mem = await (this.parent as any).guild.members._get(this.member.id) as MemberPayload
|
||||
if (res !== undefined && mem.roles.includes(res.id) === true) return res
|
||||
else return undefined
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ export class MemberRolesManager extends BaseChildManager<
|
|||
|
||||
async array (): Promise<Role[]> {
|
||||
const arr = (await this.parent.array()) as Role[]
|
||||
const mem = await (this.parent as any).guild.members.get(this.member.id) as MemberPayload
|
||||
const mem = await (this.parent as any).guild.members._get(this.member.id) as MemberPayload
|
||||
return arr.filter(
|
||||
(c: any) => mem.roles.includes(c.id)
|
||||
) as any
|
||||
|
|
|
@ -18,11 +18,7 @@ export class MembersManager extends BaseManager<MemberPayload, Member> {
|
|||
const raw = await this._get(key)
|
||||
if (raw === undefined) return
|
||||
const user = new User(this.client, raw.user)
|
||||
const res = new this.DataType(this.client, raw, user)
|
||||
for (const roleid of res.roleIDs as string[]) {
|
||||
const role = await this.guild.roles.get(roleid)
|
||||
if (role !== undefined) res.roles.push(role)
|
||||
}
|
||||
const res = new this.DataType(this.client, raw, user, this.guild)
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -31,11 +27,7 @@ export class MembersManager extends BaseManager<MemberPayload, Member> {
|
|||
this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(async data => {
|
||||
await this.set(id, data as MemberPayload)
|
||||
const user: User = new User(this.client, data.user)
|
||||
const res = new Member(this.client, data as MemberPayload, user)
|
||||
for (const roleid of res.roleIDs as string[]) {
|
||||
const role = await this.guild.roles.get(roleid)
|
||||
if (role !== undefined) res.roles.push(role)
|
||||
}
|
||||
const res = new Member(this.client, data as MemberPayload, user, this.guild)
|
||||
resolve(res)
|
||||
}).catch(e => reject(e))
|
||||
})
|
||||
|
|
|
@ -208,7 +208,7 @@ export class CommandClient extends Client implements CommandClientOptions {
|
|||
command.afterExecute(ctx, result)
|
||||
} catch (e) {
|
||||
if (this.texts.ERROR !== undefined)
|
||||
return this.sendProcessedText(
|
||||
this.sendProcessedText(
|
||||
msg,
|
||||
this.texts.ERROR,
|
||||
Object.assign(baseReplaces, { error: e.message })
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
import { MemberRolesManager } from "../managers/memberRoles.ts"
|
||||
import { Client } from '../models/client.ts'
|
||||
import { MemberPayload } from '../types/guild.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { Role } from './role.ts'
|
||||
import { Guild } from "./guild.ts"
|
||||
import { User } from './user.ts'
|
||||
|
||||
export class Member extends Base {
|
||||
id: string
|
||||
user: User
|
||||
nick?: string
|
||||
roleIDs: string[]
|
||||
roles: Role[] = []
|
||||
roles: MemberRolesManager
|
||||
joinedAt: string
|
||||
premiumSince?: string
|
||||
deaf: boolean
|
||||
mute: boolean
|
||||
guild: Guild
|
||||
|
||||
constructor (client: Client, data: MemberPayload, user: User) {
|
||||
constructor (client: Client, data: MemberPayload, user: User, guild: Guild) {
|
||||
super(client)
|
||||
this.id = data.user.id
|
||||
this.user = user
|
||||
// this.user =
|
||||
// cache.get('user', data.user.id) ?? new User(this.client, data.user)
|
||||
this.nick = data.nick
|
||||
this.roleIDs = data.roles
|
||||
this.guild = guild
|
||||
this.roles = new MemberRolesManager(this.client, this.guild.roles, this)
|
||||
this.joinedAt = data.joined_at
|
||||
this.premiumSince = data.premium_since
|
||||
this.deaf = data.deaf
|
||||
|
@ -34,7 +36,6 @@ export class Member extends Base {
|
|||
protected readFromData (data: MemberPayload): void {
|
||||
super.readFromData(data.user)
|
||||
this.nick = data.nick ?? this.nick
|
||||
this.roleIDs = data.roles ?? this.roles.map(r => r.id)
|
||||
this.joinedAt = data.joined_at ?? this.joinedAt
|
||||
this.premiumSince = data.premium_since ?? this.premiumSince
|
||||
this.deaf = data.deaf ?? this.deaf
|
||||
|
|
|
@ -11,10 +11,9 @@ client.on('debug', console.log)
|
|||
|
||||
client.on('ready', () => {
|
||||
console.log(`[Login] Logged in as ${client.user?.tag}!`)
|
||||
client.rest.get('https://discord.com/api/v8/users/123')
|
||||
})
|
||||
|
||||
client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
|
||||
// client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
|
||||
|
||||
client.on("commandError", console.error)
|
||||
|
||||
|
|
|
@ -3,14 +3,17 @@ import { Command, Member, CommandContext, Embed } from '../../../mod.ts'
|
|||
export default class UserinfoCommand extends Command {
|
||||
name = "userinfo"
|
||||
guildOnly = true
|
||||
aliases = [ 'u', 'user' ]
|
||||
|
||||
execute(ctx: CommandContext): void {
|
||||
async execute(ctx: CommandContext): Promise<void> {
|
||||
const member: Member = ctx.message.member as any
|
||||
const roles = await member.roles.array()
|
||||
const embed = new Embed()
|
||||
.setTitle(`User Info`)
|
||||
.setAuthor({ name: member.user.tag })
|
||||
.addField("ID", member.id)
|
||||
.addField("Roles", member.roles.map(r => r.name).join(", "))
|
||||
.addField("Roles", roles.map(r => r.name).join(", "))
|
||||
.setColor(0xff00ff)
|
||||
ctx.channel.send(embed)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue