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