fix(lint) & fix(code)

This commit is contained in:
DjDeveloperr 2020-12-03 10:58:20 +05:30
parent a8935fc403
commit 174d3cb58c
21 changed files with 35 additions and 34 deletions

View file

@ -6,18 +6,20 @@ export const channelPinsUpdate: GatewayEventHandler = async (
gateway: Gateway, gateway: Gateway,
d: ChannelPinsUpdatePayload d: ChannelPinsUpdatePayload
) => { ) => {
const after: const before:
| TextChannel | TextChannel
| undefined = await gateway.client.channels.get<TextChannel>(d.channel_id) | undefined = await gateway.client.channels.get<TextChannel>(d.channel_id)
if (after !== undefined) {
const before = after.refreshFromData({ if (before !== undefined) {
last_pin_timestamp: d.last_pin_timestamp
})
const raw = await gateway.client.channels._get(d.channel_id) const raw = await gateway.client.channels._get(d.channel_id)
if (raw === undefined) return
await gateway.client.channels.set( await gateway.client.channels.set(
after.id, raw.id,
Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp }) Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp })
) )
const after = ((await gateway.client.channels.get(
d.channel_id
)) as unknown) as TextChannel
gateway.client.emit('channelPinsUpdate', before, after) gateway.client.emit('channelPinsUpdate', before, after)
} }
} }

View file

@ -2,15 +2,13 @@ import { Guild } from '../../structures/guild.ts'
import { GuildPayload } from '../../types/guild.ts' import { GuildPayload } from '../../types/guild.ts'
import { Gateway, GatewayEventHandler } from '../index.ts' import { Gateway, GatewayEventHandler } from '../index.ts'
export const guildDelte: GatewayEventHandler = async ( export const guildDelete: GatewayEventHandler = async (
gateway: Gateway, gateway: Gateway,
d: GuildPayload d: GuildPayload
) => { ) => {
const guild: Guild | undefined = await gateway.client.guilds.get(d.id) const guild: Guild | undefined = await gateway.client.guilds.get(d.id)
if (guild !== undefined) { if (guild !== undefined) {
guild.refreshFromData(d)
await guild.members.flush() await guild.members.flush()
await guild.channels.flush() await guild.channels.flush()
await guild.roles.flush() await guild.roles.flush()

View file

@ -6,9 +6,9 @@ export const guildUpdate: GatewayEventHandler = async (
gateway: Gateway, gateway: Gateway,
d: GuildPayload d: GuildPayload
) => { ) => {
const after: Guild | undefined = await gateway.client.guilds.get(d.id) const before: Guild | undefined = await gateway.client.guilds.get(d.id)
if (after === undefined) return if (before === undefined) return
const before = after.refreshFromData(d)
await gateway.client.guilds.set(d.id, d) await gateway.client.guilds.set(d.id, d)
const after = ((await gateway.client.guilds.get(d.id)) as unknown) as Guild
gateway.client.emit('guildUpdate', before, after) gateway.client.emit('guildUpdate', before, after)
} }

View file

@ -5,7 +5,7 @@ import { channelDelete } from './channelDelete.ts'
import { channelUpdate } from './channelUpdate.ts' import { channelUpdate } from './channelUpdate.ts'
import { channelPinsUpdate } from './channelPinsUpdate.ts' import { channelPinsUpdate } from './channelPinsUpdate.ts'
import { guildCreate } from './guildCreate.ts' import { guildCreate } from './guildCreate.ts'
import { guildDelte as guildDelete } from './guildDelete.ts' import { guildDelete } from './guildDelete.ts'
import { guildUpdate } from './guildUpdate.ts' import { guildUpdate } from './guildUpdate.ts'
import { guildBanAdd } from './guildBanAdd.ts' import { guildBanAdd } from './guildBanAdd.ts'
import { ready } from './ready.ts' import { ready } from './ready.ts'

View file

@ -75,10 +75,13 @@ export class Client extends EventEmitter {
/** Client's presence. Startup one if set before connecting */ /** Client's presence. Startup one if set before connecting */
presence: ClientPresence = new ClientPresence() presence: ClientPresence = new ClientPresence()
private _untypedOn = this.on private readonly _untypedOn = this.on
private _untypedEmit = this.emit
private readonly _untypedEmit = this.emit
public on = <K extends string>(event: K, listener: ClientEvents[K]): this => public on = <K extends string>(event: K, listener: ClientEvents[K]): this =>
this._untypedOn(event, listener) this._untypedOn(event, listener)
public emit = <K extends string>( public emit = <K extends string>(
event: K, event: K,
...args: Parameters<ClientEvents[K]> ...args: Parameters<ClientEvents[K]>

View file

@ -16,7 +16,7 @@ export class Channel extends Base {
this.id = data.id this.id = data.id
} }
protected readFromData(data: ChannelPayload): void { readFromData(data: ChannelPayload): void {
this.type = data.type ?? this.type this.type = data.type ?? this.type
this.id = data.id ?? this.id this.id = data.id ?? this.id
} }

View file

@ -11,7 +11,7 @@ export class DMChannel extends TextChannel {
this.recipients = data.recipients this.recipients = data.recipients
} }
protected readFromData(data: DMChannelPayload): void { readFromData(data: DMChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.recipients = data.recipients ?? this.recipients this.recipients = data.recipients ?? this.recipients
} }

View file

@ -1,6 +1,5 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { EmojiPayload } from '../types/emoji.ts' import { EmojiPayload } from '../types/emoji.ts'
import { USER } from '../types/endpoint.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { Guild } from './guild.ts' import { Guild } from './guild.ts'
import { User } from './user.ts' import { User } from './user.ts'
@ -38,7 +37,7 @@ export class Emoji extends Base {
this.available = data.available this.available = data.available
} }
protected readFromData(data: EmojiPayload): void { readFromData(data: EmojiPayload): void {
this.id = data.id ?? this.id this.id = data.id ?? this.id
this.name = data.name ?? this.name this.name = data.name ?? this.name
this.roles = data.roles ?? this.roles this.roles = data.roles ?? this.roles

View file

@ -17,7 +17,7 @@ export class GroupDMChannel extends Channel {
// cache.set('groupchannel', this.id, this) // cache.set('groupchannel', this.id, this)
} }
protected readFromData(data: GroupDMChannelPayload): void { readFromData(data: GroupDMChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.name = data.name ?? this.name this.name = data.name ?? this.name
this.icon = data.icon ?? this.icon this.icon = data.icon ?? this.icon

View file

@ -219,7 +219,7 @@ export class Guild extends Base {
} }
} }
protected readFromData(data: GuildPayload): void { readFromData(data: GuildPayload): void {
this.id = data.id ?? this.id this.id = data.id ?? this.id
this.unavailable = data.unavailable ?? this.unavailable this.unavailable = data.unavailable ?? this.unavailable

View file

@ -25,7 +25,7 @@ export class CategoryChannel extends Channel {
// cache.set('guildcategorychannel', this.id, this) // cache.set('guildcategorychannel', this.id, this)
} }
protected readFromData(data: GuildChannelCategoryPayload): void { readFromData(data: GuildChannelCategoryPayload): void {
super.readFromData(data) super.readFromData(data)
this.guildID = data.guild_id ?? this.guildID this.guildID = data.guild_id ?? this.guildID
this.name = data.name ?? this.name this.name = data.name ?? this.name

View file

@ -25,7 +25,7 @@ export class NewsChannel extends TextChannel {
this.topic = data.topic this.topic = data.topic
} }
protected readFromData(data: GuildNewsChannelPayload): void { readFromData(data: GuildNewsChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.guildID = data.guild_id ?? this.guildID this.guildID = data.guild_id ?? this.guildID
this.name = data.name ?? this.name this.name = data.name ?? this.name

View file

@ -29,7 +29,7 @@ export class VoiceChannel extends Channel {
// cache.set('guildvoicechannel', this.id, this) // cache.set('guildvoicechannel', this.id, this)
} }
protected readFromData(data: GuildVoiceChannelPayload): void { readFromData(data: GuildVoiceChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.bitrate = data.bitrate ?? this.bitrate this.bitrate = data.bitrate ?? this.bitrate
this.userLimit = data.user_limit ?? this.userLimit this.userLimit = data.user_limit ?? this.userLimit

View file

@ -31,7 +31,7 @@ export class Invite extends Base {
this.approximatePresenceCount = data.approximate_presence_count this.approximatePresenceCount = data.approximate_presence_count
} }
protected readFromData(data: InvitePayload): void { readFromData(data: InvitePayload): void {
this.code = data.code ?? this.code this.code = data.code ?? this.code
this.guild = data.guild ?? this.guild this.guild = data.guild ?? this.guild
this.channel = data.channel ?? this.channel this.channel = data.channel ?? this.channel

View file

@ -56,7 +56,7 @@ export class Member extends Base {
return this.user.nickMention return this.user.nickMention
} }
protected readFromData(data: MemberPayload): void { readFromData(data: MemberPayload): void {
this.nick = data.nick ?? this.nick this.nick = data.nick ?? this.nick
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

View file

@ -81,7 +81,7 @@ export class Message extends Base {
this.channel = channel this.channel = channel
} }
protected readFromData(data: MessagePayload): void { readFromData(data: MessagePayload): void {
this.channelID = data.channel_id ?? this.channelID this.channelID = data.channel_id ?? this.channelID
this.guildID = data.guild_id ?? this.guildID this.guildID = data.guild_id ?? this.guildID
this.content = data.content ?? this.content this.content = data.content ?? this.content

View file

@ -33,7 +33,7 @@ export class Role extends Base {
this.mentionable = data.mentionable this.mentionable = data.mentionable
} }
protected readFromData(data: RolePayload): void { readFromData(data: RolePayload): void {
this.name = data.name ?? this.name this.name = data.name ?? this.name
this.color = data.color ?? this.color this.color = data.color ?? this.color
this.hoist = data.hoist ?? this.hoist this.hoist = data.hoist ?? this.hoist

View file

@ -27,7 +27,7 @@ export class TextChannel extends Channel {
this.lastPinTimestamp = data.last_pin_timestamp this.lastPinTimestamp = data.last_pin_timestamp
} }
protected readFromData(data: TextChannelPayload): void { readFromData(data: TextChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.lastMessageID = data.last_message_id ?? this.lastMessageID this.lastMessageID = data.last_message_id ?? this.lastMessageID
this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp
@ -152,7 +152,7 @@ export class GuildTextChannel extends TextChannel {
this.rateLimit = data.rate_limit_per_user this.rateLimit = data.rate_limit_per_user
} }
protected readFromData(data: GuildTextChannelPayload): void { readFromData(data: GuildTextChannelPayload): void {
super.readFromData(data) super.readFromData(data)
this.guildID = data.guild_id ?? this.guildID this.guildID = data.guild_id ?? this.guildID
this.name = data.name ?? this.name this.name = data.name ?? this.name

View file

@ -54,8 +54,7 @@ export class User extends Base {
this.publicFlags = new UserFlagsManager(data.public_flags) this.publicFlags = new UserFlagsManager(data.public_flags)
} }
protected readFromData(data: UserPayload): void { readFromData(data: UserPayload): void {
super.readFromData(data)
this.username = data.username ?? this.username this.username = data.username ?? this.username
this.discriminator = data.discriminator ?? this.discriminator this.discriminator = data.discriminator ?? this.discriminator
this.avatar = data.avatar ?? this.avatar this.avatar = data.avatar ?? this.avatar

View file

@ -43,8 +43,7 @@ export class VoiceState extends Base {
this.suppress = data.suppress this.suppress = data.suppress
} }
protected readFromData(data: VoiceStatePayload): void { readFromData(data: VoiceStatePayload): void {
super.readFromData(data)
this.sessionID = data.session_id ?? this.sessionID this.sessionID = data.session_id ?? this.sessionID
this.deaf = data.deaf ?? this.deaf this.deaf = data.deaf ?? this.deaf
this.mute = data.mute ?? this.mute this.mute = data.mute ?? this.mute

View file

@ -2,6 +2,7 @@ import { GatewayIntents } from '../types/gateway.ts'
export type PriviligedIntents = 'GUILD_MEMBERS' | 'GUILD_PRESENCES' export type PriviligedIntents = 'GUILD_MEMBERS' | 'GUILD_PRESENCES'
/* eslint-disable @typescript-eslint/no-extraneous-class */
/** Utility class for handling Gateway Intents */ /** Utility class for handling Gateway Intents */
export class Intents { export class Intents {
static NonPriviliged: number[] = [ static NonPriviliged: number[] = [