Fix lint
This commit is contained in:
parent
30d0e8a571
commit
c9be27ff44
14 changed files with 35 additions and 35 deletions
|
@ -11,18 +11,18 @@ export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: Guild
|
||||||
if (guild !== undefined) {
|
if (guild !== undefined) {
|
||||||
// It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in
|
// It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in
|
||||||
await gateway.client.guilds.set(d.id, d)
|
await gateway.client.guilds.set(d.id, d)
|
||||||
if((d as any).members !== undefined) {
|
if ((d as any).members !== undefined) {
|
||||||
const members = new MembersManager(gateway.client, guild)
|
const members = new MembersManager(gateway.client, guild)
|
||||||
await members.fromPayload((d as any).members as MemberPayload[])
|
await members.fromPayload((d as any).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
}
|
}
|
||||||
if((d as any).channels !== undefined) {
|
if ((d as any).channels !== undefined) {
|
||||||
for (const ch of (d as any).channels as ChannelPayload[]) {
|
for (const ch of (d as any).channels as ChannelPayload[]) {
|
||||||
(ch as any).guild_id = d.id
|
(ch as any).guild_id = d.id
|
||||||
await gateway.client.channels.set(ch.id, ch)
|
await gateway.client.channels.set(ch.id, ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((d as any).roles !== undefined) {
|
if ((d as any).roles !== undefined) {
|
||||||
const roles = new RolesManager(gateway.client, guild)
|
const roles = new RolesManager(gateway.client, guild)
|
||||||
await roles.fromPayload((d as any).roles as RolePayload[])
|
await roles.fromPayload((d as any).roles as RolePayload[])
|
||||||
guild.roles = roles
|
guild.roles = roles
|
||||||
|
@ -31,18 +31,18 @@ export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: Guild
|
||||||
} else {
|
} else {
|
||||||
await gateway.client.guilds.set(d.id, d)
|
await gateway.client.guilds.set(d.id, d)
|
||||||
guild = new Guild(gateway.client, d)
|
guild = new Guild(gateway.client, d)
|
||||||
if((d as any).members !== undefined) {
|
if ((d as any).members !== undefined) {
|
||||||
const members = new MembersManager(gateway.client, guild)
|
const members = new MembersManager(gateway.client, guild)
|
||||||
await members.fromPayload((d as any).members as MemberPayload[])
|
await members.fromPayload((d as any).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
}
|
}
|
||||||
if((d as any).channels !== undefined) {
|
if ((d as any).channels !== undefined) {
|
||||||
for (const ch of (d as any).channels as ChannelPayload[]) {
|
for (const ch of (d as any).channels as ChannelPayload[]) {
|
||||||
(ch as any).guild_id = d.id
|
(ch as any).guild_id = d.id
|
||||||
await gateway.client.channels.set(ch.id, ch)
|
await gateway.client.channels.set(ch.id, ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((d as any).roles !== undefined) {
|
if ((d as any).roles !== undefined) {
|
||||||
const roles = new RolesManager(gateway.client, guild)
|
const roles = new RolesManager(gateway.client, guild)
|
||||||
await roles.fromPayload((d as any).roles as RolePayload[])
|
await roles.fromPayload((d as any).roles as RolePayload[])
|
||||||
guild.roles = roles
|
guild.roles = roles
|
||||||
|
|
|
@ -21,6 +21,6 @@ export const messageCreate: GatewayEventHandler = async (
|
||||||
}
|
}
|
||||||
const mentions = new MessageMentions()
|
const mentions = new MessageMentions()
|
||||||
const message = new Message(gateway.client, d, channel as any, user, mentions)
|
const message = new Message(gateway.client, d, channel as any, user, mentions)
|
||||||
if(guild !== undefined) message.guild = guild
|
if (guild !== undefined) message.guild = guild
|
||||||
gateway.client.emit('messageCreate', message)
|
gateway.client.emit('messageCreate', message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
export const resume: GatewayEventHandler = async (gateway: Gateway, d: any) => {
|
export const resume: GatewayEventHandler = async (gateway: Gateway, d: any) => {
|
||||||
gateway.debug(`Session Resumed!`)
|
gateway.debug(`Session Resumed!`)
|
||||||
gateway.client.emit('resume')
|
gateway.client.emit('resume')
|
||||||
if(gateway.client.user === undefined) gateway.client.user = new User(gateway.client, await gateway.client.rest.get(CLIENT_USER()) as any)
|
if (gateway.client.user === undefined) gateway.client.user = new User(gateway.client, await gateway.client.rest.get(CLIENT_USER()) as any)
|
||||||
gateway.client.emit('ready')
|
gateway.client.emit('ready')
|
||||||
}
|
}
|
|
@ -227,7 +227,7 @@ class Gateway {
|
||||||
token: this.token,
|
token: this.token,
|
||||||
properties: {
|
properties: {
|
||||||
$os: Deno.build.os,
|
$os: Deno.build.os,
|
||||||
$browser: 'discord.deno',
|
$browser: 'discord.deno', //TODO: Change lib name
|
||||||
$device: 'discord.deno'
|
$device: 'discord.deno'
|
||||||
},
|
},
|
||||||
compress: true,
|
compress: true,
|
||||||
|
|
|
@ -30,14 +30,14 @@ export class BaseManager<T, T2> {
|
||||||
return this.client.cache.delete(this.cacheName, key)
|
return this.client.cache.delete(this.cacheName, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
async array(): Promise<undefined | T2[]> {
|
async array (): Promise<undefined | T2[]> {
|
||||||
const arr = await (this.client.cache.array(this.cacheName) as T[])
|
const arr = await (this.client.cache.array(this.cacheName) as T[])
|
||||||
return arr.map(e => new this.DataType(this.client, e)) as any
|
return arr.map(e => new this.DataType(this.client, e)) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
async collection(): Promise<Collection<string, T2>> {
|
async collection (): Promise<Collection<string, T2>> {
|
||||||
const arr = await this.array()
|
const arr = await this.array()
|
||||||
if(arr === undefined) return new Collection()
|
if (arr === undefined) return new Collection()
|
||||||
const collection = new Collection()
|
const collection = new Collection()
|
||||||
for (const elem of arr) {
|
for (const elem of arr) {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|
|
@ -13,9 +13,9 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||||
// Override get method as Generic
|
// Override get method as Generic
|
||||||
async get<T = Channel>(key: string): Promise<T | undefined> {
|
async get<T = Channel>(key: string): Promise<T | undefined> {
|
||||||
const data = await this._get(key)
|
const data = await this._get(key)
|
||||||
if(data === undefined) return
|
if (data === undefined) return
|
||||||
let guild
|
let guild
|
||||||
if((data as any).guild_id !== undefined) {
|
if ((data as any).guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get((data as any).guild_id)
|
guild = await this.client.guilds.get((data as any).guild_id)
|
||||||
}
|
}
|
||||||
const res = getChannelByType(this.client, data, guild)
|
const res = getChannelByType(this.client, data, guild)
|
||||||
|
@ -27,7 +27,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||||
const result: any[] = []
|
const result: any[] = []
|
||||||
for(const elem of arr) {
|
for(const elem of arr) {
|
||||||
let guild
|
let guild
|
||||||
if((elem as any).guild_id !== undefined) {
|
if ((elem as any).guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get((elem as any).guild_id)
|
guild = await this.client.guilds.get((elem as any).guild_id)
|
||||||
}
|
}
|
||||||
result.push(getChannelByType(this.client, elem, guild))
|
result.push(getChannelByType(this.client, elem, guild))
|
||||||
|
@ -40,7 +40,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||||
this.client.rest.get(CHANNEL(id)).then(async data => {
|
this.client.rest.get(CHANNEL(id)).then(async data => {
|
||||||
this.set(id, data as ChannelPayload)
|
this.set(id, data as ChannelPayload)
|
||||||
let guild
|
let guild
|
||||||
if(data.guild_id !== undefined) {
|
if (data.guild_id !== undefined) {
|
||||||
guild = await this.client.guilds.get(data.guild_id)
|
guild = await this.client.guilds.get(data.guild_id)
|
||||||
}
|
}
|
||||||
resolve(getChannelByType(this.client, data as ChannelPayload, guild))
|
resolve(getChannelByType(this.client, data as ChannelPayload, guild))
|
||||||
|
|
|
@ -22,7 +22,7 @@ export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads,
|
||||||
|
|
||||||
async get(id: string): Promise<GuildChannel | undefined> {
|
async get(id: string): Promise<GuildChannel | undefined> {
|
||||||
const res = await this.parent.get(id)
|
const res = await this.parent.get(id)
|
||||||
if(res !== undefined && res.guild.id === this.guild.id) return res
|
if (res !== undefined && res.guild.id === this.guild.id) return res
|
||||||
else return undefined
|
else return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
|
||||||
this.client.rest.get(GUILD(id)).then(async (data: any) => {
|
this.client.rest.get(GUILD(id)).then(async (data: any) => {
|
||||||
this.set(id, data)
|
this.set(id, data)
|
||||||
const guild = new Guild(this.client, data)
|
const guild = new Guild(this.client, data)
|
||||||
if((data as GuildPayload).members !== undefined) {
|
if ((data as GuildPayload).members !== undefined) {
|
||||||
const members = new MembersManager(this.client, guild)
|
const members = new MembersManager(this.client, guild)
|
||||||
await members.fromPayload((data as GuildPayload).members as MemberPayload[])
|
await members.fromPayload((data as GuildPayload).members as MemberPayload[])
|
||||||
guild.members = members
|
guild.members = members
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class MembersManager extends BaseManager<MemberPayload, Member> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fromPayload(members: MemberPayload[]): Promise<void> {
|
async fromPayload(members: MemberPayload[]): Promise<void> {
|
||||||
for(const member of members) {
|
for (const member of members) {
|
||||||
await this.set(member.user.id, member)
|
await this.set(member.user.id, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
||||||
|
|
||||||
async get(key: string): Promise<Message | undefined> {
|
async get(key: string): Promise<Message | undefined> {
|
||||||
const raw = await this._get(key)
|
const raw = await this._get(key)
|
||||||
if(raw === undefined) return
|
if (raw === undefined) return
|
||||||
let channel = await this.client.channels.get(raw.channel_id)
|
let channel = await this.client.channels.get(raw.channel_id)
|
||||||
if(channel === undefined) channel = await this.client.channels.fetch(raw.channel_id)
|
if (channel === undefined) channel = await this.client.channels.fetch(raw.channel_id)
|
||||||
if(channel === undefined) return
|
if (channel === undefined) return
|
||||||
const author = new User(this.client, raw.author)
|
const author = new User(this.client, raw.author)
|
||||||
const mentions = new MessageMentions()
|
const mentions = new MessageMentions()
|
||||||
return new this.DataType(this.client, raw, channel, author, mentions) as any
|
return new this.DataType(this.client, raw, channel, author, mentions) as any
|
||||||
|
@ -28,7 +28,7 @@ export class MessagesManager extends BaseManager<MessagePayload, Message> {
|
||||||
this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => {
|
this.client.rest.get(CHANNEL_MESSAGE(channelID, id)).then(async data => {
|
||||||
this.set(id, data as MessagePayload)
|
this.set(id, data as MessagePayload)
|
||||||
let channel: any = await this.client.channels.get<TextChannel>(channelID)
|
let channel: any = await this.client.channels.get<TextChannel>(channelID)
|
||||||
if(channel === undefined) channel = await this.client.channels.fetch(channelID)
|
if (channel === undefined) channel = await this.client.channels.fetch(channelID)
|
||||||
const author = new User(this.client, (data as MessagePayload).author)
|
const author = new User(this.client, (data as MessagePayload).author)
|
||||||
await this.client.users.set(author.id, (data as MessagePayload).author)
|
await this.client.users.set(author.id, (data as MessagePayload).author)
|
||||||
// TODO: Make this thing work (MessageMentions)
|
// TODO: Make this thing work (MessageMentions)
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class RolesManager extends BaseManager<RolePayload, Role> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fromPayload(roles: RolePayload[]): Promise<boolean> {
|
async fromPayload(roles: RolePayload[]): Promise<boolean> {
|
||||||
for(const role of roles) {
|
for (const role of roles) {
|
||||||
await this.set(role.id, role)
|
await this.set(role.id, role)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -54,14 +54,14 @@ export class Client extends EventEmitter {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
setPresence(presence: ClientPresence | ClientActivity | ActivityGame): void {
|
setPresence (presence: ClientPresence | ClientActivity | ActivityGame): void {
|
||||||
if(presence instanceof ClientPresence) {
|
if (presence instanceof ClientPresence) {
|
||||||
this.presence = presence
|
this.presence = presence
|
||||||
} else this.presence = new ClientPresence(presence)
|
} else this.presence = new ClientPresence(presence)
|
||||||
this.gateway?.sendPresence(this.presence.create())
|
this.gateway?.sendPresence(this.presence.create())
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(tag: string, msg: string): void {
|
debug (tag: string, msg: string): void {
|
||||||
this.emit("debug", `[${tag}] ${msg}`)
|
this.emit("debug", `[${tag}] ${msg}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ export class Message extends Base {
|
||||||
|
|
||||||
async reply(text: string, options?: MessageOption): Promise<Message> {
|
async reply(text: string, options?: MessageOption): Promise<Message> {
|
||||||
// TODO: Use inline replies once they're out
|
// TODO: Use inline replies once they're out
|
||||||
if(this.channel instanceof DMChannel) return this.channel.send(text, options)
|
if (this.channel instanceof DMChannel) return this.channel.send(text, options)
|
||||||
return this.channel.send(`${this.author.mention}, ${text}`, options)
|
return this.channel.send(`${this.author.mention}, ${text}`, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,14 +38,14 @@ export class ClientPresence {
|
||||||
|
|
||||||
constructor(data?: ClientActivity | ClientActivityPayload | ActivityGame) {
|
constructor(data?: ClientActivity | ClientActivityPayload | ActivityGame) {
|
||||||
if (data !== undefined) {
|
if (data !== undefined) {
|
||||||
if((data as ClientActivity).activity !== undefined) {
|
if ((data as ClientActivity).activity !== undefined) {
|
||||||
Object.assign(this, data)
|
Object.assign(this, data)
|
||||||
} else if((data as ClientActivityPayload).activities !== undefined) {
|
} else if ((data as ClientActivityPayload).activities !== undefined) {
|
||||||
|
|
||||||
} else if((data as ActivityGame).name !== undefined) {
|
} else if ((data as ActivityGame).name !== undefined) {
|
||||||
if(this.activity === undefined) {
|
if (this.activity === undefined) {
|
||||||
this.activity = data as ActivityGame
|
this.activity = data as ActivityGame
|
||||||
} else if(this.activity instanceof Array) {
|
} else if (this.activity instanceof Array) {
|
||||||
this.activity.push(data as ActivityGame)
|
this.activity.push(data as ActivityGame)
|
||||||
} else this.activity = [ this.activity, data as ActivityGame ]
|
} else this.activity = [ this.activity, data as ActivityGame ]
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@ export class ClientPresence {
|
||||||
createActivity(): ActivityGame[] | null {
|
createActivity(): ActivityGame[] | null {
|
||||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||||
const activity = this.activity === undefined ? null : (this.activity instanceof Array ? this.activity : [this.activity]) || null
|
const activity = this.activity === undefined ? null : (this.activity instanceof Array ? this.activity : [this.activity]) || null
|
||||||
if(activity === null) return activity
|
if (activity === null) return activity
|
||||||
else {
|
else {
|
||||||
activity.map(e => {
|
activity.map(e => {
|
||||||
if(typeof e.type === "string") e.type = ActivityTypes[e.type]
|
if (typeof e.type === "string") e.type = ActivityTypes[e.type]
|
||||||
return e
|
return e
|
||||||
})
|
})
|
||||||
return activity
|
return activity
|
||||||
|
|
Loading…
Reference in a new issue