Fix lint & Added reconnect handler
This commit is contained in:
parent
c9be27ff44
commit
c4fb67c07e
6 changed files with 17 additions and 10 deletions
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
|
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
|
||||||
|
|
||||||
An easy to use Discord API Library for Deno
|
**An easy to use Discord API Library for Deno**
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Docs](#docs)
|
- [Docs](#docs)
|
||||||
- [Maintainers](#maintainers)
|
- [Maintainer](#maintainer)
|
||||||
- [Contributing](#contributing)
|
- [Contributing](#contributing)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ bot.connect(TOKEN, [GatewayIntents.GUILD_MESSAGES])
|
||||||
|
|
||||||
Not made yet
|
Not made yet
|
||||||
|
|
||||||
## Maintainers
|
## Maintainer
|
||||||
|
|
||||||
[@Helloyunho](https://github.com/Helloyunho)
|
[@Helloyunho](https://github.com/Helloyunho)
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,13 @@ import { ready } from './ready.ts'
|
||||||
import { guildBanRemove } from './guildBanRemove.ts'
|
import { guildBanRemove } from './guildBanRemove.ts'
|
||||||
import { messageCreate } from "./messageCreate.ts"
|
import { messageCreate } from "./messageCreate.ts"
|
||||||
import { resume } from "./resume.ts"
|
import { resume } from "./resume.ts"
|
||||||
|
import { reconnect } from './reconnect.ts'
|
||||||
|
|
||||||
export const gatewayHandlers: {
|
export const gatewayHandlers: {
|
||||||
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
||||||
} = {
|
} = {
|
||||||
READY: ready,
|
READY: ready,
|
||||||
RECONNECT: undefined,
|
RECONNECT: reconnect,
|
||||||
RESUMED: resume,
|
RESUMED: resume,
|
||||||
CHANNEL_CREATE: channelCreate,
|
CHANNEL_CREATE: channelCreate,
|
||||||
CHANNEL_DELETE: channelDelete,
|
CHANNEL_DELETE: channelDelete,
|
||||||
|
|
6
src/gateway/handlers/reconnect.ts
Normal file
6
src/gateway/handlers/reconnect.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { Gateway } from "../index.ts"
|
||||||
|
import { GatewayEventHandler } from "../index.ts"
|
||||||
|
|
||||||
|
export const reconnect: GatewayEventHandler = async (gateway: Gateway, d: any) => {
|
||||||
|
gateway.reconnect()
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ export class BaseChildManager<T, T2> {
|
||||||
|
|
||||||
async collection(): Promise<Collection<string, T2>> {
|
async collection(): Promise<Collection<string, T2>> {
|
||||||
const arr = await this.array() as undefined | T2[]
|
const arr = await this.array() as undefined | T2[]
|
||||||
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
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
|
||||||
async array(): Promise<undefined | Channel[]> {
|
async array(): Promise<undefined | Channel[]> {
|
||||||
const arr = await (this.client.cache.array(this.cacheName) as ChannelPayload[])
|
const arr = await (this.client.cache.array(this.cacheName) as ChannelPayload[])
|
||||||
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)
|
||||||
|
|
|
@ -39,16 +39,16 @@ const getChannelByType = (
|
||||||
| undefined => {
|
| undefined => {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case ChannelTypes.GUILD_CATEGORY:
|
case ChannelTypes.GUILD_CATEGORY:
|
||||||
if(guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||||
return new CategoryChannel(client, data as GuildChannelCategoryPayload, guild)
|
return new CategoryChannel(client, data as GuildChannelCategoryPayload, guild)
|
||||||
case ChannelTypes.GUILD_NEWS:
|
case ChannelTypes.GUILD_NEWS:
|
||||||
if(guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||||
return new NewsChannel(client, data as GuildNewsChannelPayload, guild)
|
return new NewsChannel(client, data as GuildNewsChannelPayload, guild)
|
||||||
case ChannelTypes.GUILD_TEXT:
|
case ChannelTypes.GUILD_TEXT:
|
||||||
if(guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||||
return new GuildTextChannel(client, data as GuildTextChannelPayload, guild)
|
return new GuildTextChannel(client, data as GuildTextChannelPayload, guild)
|
||||||
case ChannelTypes.GUILD_VOICE:
|
case ChannelTypes.GUILD_VOICE:
|
||||||
if(guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
if (guild === undefined) throw new Error("No Guild was provided to construct Channel")
|
||||||
return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild)
|
return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild)
|
||||||
case ChannelTypes.DM:
|
case ChannelTypes.DM:
|
||||||
return new DMChannel(client, data as DMChannelPayload)
|
return new DMChannel(client, data as DMChannelPayload)
|
||||||
|
|
Loading…
Reference in a new issue