Fix errors with merge, fix lint errors

This commit is contained in:
DjDeveloper 2020-11-03 12:42:22 +05:30
parent 5da856a3ad
commit 9b37e185b0
3 changed files with 32 additions and 28 deletions

View file

@ -1,12 +1,11 @@
import { Gateway, GatewayEventHandler } from '../index.ts'
import { Channel } from '../../structures/channel.ts'
import { ChannelPayload } from '../../types/channel.ts'
export const channelDelete: GatewayEventHandler = async (
gateway: Gateway,
d: ChannelPayload
) => {
const channel: Channel | void = await gateway.client.channels.get(d.id)
const channel = await gateway.client.channels.get(d.id)
if (channel !== undefined) {
await gateway.client.channels.delete(d.id)
gateway.client.emit('channelDelete', channel)

View file

@ -52,7 +52,7 @@ export class RESTManager {
constructor (client: Client) {
this.client = client
setTimeout(this.processRateLimitedPaths, 1000)
setTimeout(() => this.processRateLimitedPaths, 1000)
}
async processRateLimitedPaths (): Promise<void> {
@ -158,7 +158,7 @@ export class RESTManager {
'User-Agent': `DiscordBot (discord.deno)`
}
if (this.client.token !== undefined) delete headers.Authorization
if (this.client.token === undefined) delete headers.Authorization
if (method === 'get') body = undefined
@ -233,9 +233,11 @@ export class RESTManager {
const urlToUse =
method === 'get' && query !== '' ? `${url}?${query}` : url
const requestData = this.createRequestBody(body, method)
const response = await fetch(
urlToUse,
this.createRequestBody(body, method)
requestData
)
const bucketIDFromHeaders = this.processHeaders(url, response.headers)
this.handleStatusCode(response, errorStack)
@ -302,15 +304,17 @@ export class RESTManager {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.logErrors(response, errorStack)
if(status === HttpResponseCode.Unauthorized) throw new Error("Request was not successful. Invalid Token.")
switch (status) {
case HttpResponseCode.BadRequest:
case HttpResponseCode.Unauthorized:
case HttpResponseCode.Forbidden:
case HttpResponseCode.NotFound:
case HttpResponseCode.MethodNotAllowed:
throw new Error('Request Client Error')
throw new Error('Request Client Error.')
case HttpResponseCode.GatewayUnavailable:
throw new Error('Request Server Error')
throw new Error('Request Server Error.')
}
// left are all unknown

View file

@ -4,6 +4,9 @@ import { TOKEN } from './config.ts'
import { Message } from "../structures/message.ts"
import { RedisCacheAdapter } from "../models/CacheAdapter.ts"
import { ClientPresence } from "../structures/presence.ts"
import { Member } from "../structures/member.ts"
import { Role } from "../structures/role.ts"
import { GuildChannel } from "../managers/GuildChannelsManager.ts"
const bot = new Client({
presence: new ClientPresence({
@ -12,7 +15,6 @@ const bot = new Client({
type: 'COMPETING'
}
}),
forceNewSession: true
})
bot.setAdapter(new RedisCacheAdapter(bot, {
@ -31,32 +33,31 @@ bot.on('ready', () => {
bot.on('debug', console.log)
bot.on('messageCreate', async (msg: Message) => {
if (msg.author.bot) return
console.log(`${msg.author.tag} (${msg.channel + ""}): ${msg.content}`)
if (msg.content == "!ping") {
msg.reply("Pong! API Ping: " + bot.ping + "ms")
} else if (msg.content == "!members") {
let col = await msg.guild?.members.collection()
let data = col?.array().map((c, i) => {
if (msg.author.bot === true) return
if (msg.content === "!ping") {
msg.reply(`Pong! Ping: ${bot.ping}ms`)
} else if (msg.content === "!members") {
const col = await msg.guild?.members.collection()
const data = col?.array().map((c: Member, i: number) => {
return `${i + 1}. ${c.user.tag}`
}).join("\n")
}).join("\n") as string
msg.channel.send("Member List:\n" + data)
} else if (msg.content == "!guilds") {
let guilds = await msg.client.guilds.collection()
msg.channel.send("Guild List:\n" + guilds.array().map((c, i) => {
} else if (msg.content === "!guilds") {
const guilds = await msg.client.guilds.collection()
msg.channel.send("Guild List:\n" + (guilds.array().map((c, i: number) => {
return `${i + 1}. ${c.name} - ${c.memberCount} members`
}).join("\n"))
} else if (msg.content == "!roles") {
let col = await msg.guild?.roles.collection()
let data = col?.array().map((c, i) => {
}).join("\n") as string))
} else if (msg.content === "!roles") {
const col = await msg.guild?.roles.collection()
const data = col?.array().map((c: Role, i: number) => {
return `${i + 1}. ${c.name}`
}).join("\n")
}).join("\n") as string
msg.channel.send("Roles List:\n" + data)
} else if (msg.content == "!channels") {
let col = await msg.guild?.channels.array()
let data = col?.map((c, i) => {
} else if (msg.content === "!channels") {
const col = await msg.guild?.channels.array()
const data = col?.map((c: GuildChannel, i: number) => {
return `${i + 1}. ${c.name}`
}).join("\n")
}).join("\n") as string
msg.channel.send("Channels List:\n" + data)
}
})