Fix errors with merge, fix lint errors
This commit is contained in:
parent
5da856a3ad
commit
9b37e185b0
3 changed files with 32 additions and 28 deletions
|
@ -1,12 +1,11 @@
|
||||||
import { Gateway, GatewayEventHandler } from '../index.ts'
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
import { Channel } from '../../structures/channel.ts'
|
|
||||||
import { ChannelPayload } from '../../types/channel.ts'
|
import { ChannelPayload } from '../../types/channel.ts'
|
||||||
|
|
||||||
export const channelDelete: GatewayEventHandler = async (
|
export const channelDelete: GatewayEventHandler = async (
|
||||||
gateway: Gateway,
|
gateway: Gateway,
|
||||||
d: ChannelPayload
|
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) {
|
if (channel !== undefined) {
|
||||||
await gateway.client.channels.delete(d.id)
|
await gateway.client.channels.delete(d.id)
|
||||||
gateway.client.emit('channelDelete', channel)
|
gateway.client.emit('channelDelete', channel)
|
||||||
|
|
|
@ -52,7 +52,7 @@ export class RESTManager {
|
||||||
|
|
||||||
constructor (client: Client) {
|
constructor (client: Client) {
|
||||||
this.client = client
|
this.client = client
|
||||||
setTimeout(this.processRateLimitedPaths, 1000)
|
setTimeout(() => this.processRateLimitedPaths, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
async processRateLimitedPaths (): Promise<void> {
|
async processRateLimitedPaths (): Promise<void> {
|
||||||
|
@ -158,7 +158,7 @@ export class RESTManager {
|
||||||
'User-Agent': `DiscordBot (discord.deno)`
|
'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
|
if (method === 'get') body = undefined
|
||||||
|
|
||||||
|
@ -233,9 +233,11 @@ export class RESTManager {
|
||||||
const urlToUse =
|
const urlToUse =
|
||||||
method === 'get' && query !== '' ? `${url}?${query}` : url
|
method === 'get' && query !== '' ? `${url}?${query}` : url
|
||||||
|
|
||||||
|
const requestData = this.createRequestBody(body, method)
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
urlToUse,
|
urlToUse,
|
||||||
this.createRequestBody(body, method)
|
requestData
|
||||||
)
|
)
|
||||||
const bucketIDFromHeaders = this.processHeaders(url, response.headers)
|
const bucketIDFromHeaders = this.processHeaders(url, response.headers)
|
||||||
this.handleStatusCode(response, errorStack)
|
this.handleStatusCode(response, errorStack)
|
||||||
|
@ -302,15 +304,17 @@ export class RESTManager {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
this.logErrors(response, errorStack)
|
this.logErrors(response, errorStack)
|
||||||
|
|
||||||
|
if(status === HttpResponseCode.Unauthorized) throw new Error("Request was not successful. Invalid Token.")
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case HttpResponseCode.BadRequest:
|
case HttpResponseCode.BadRequest:
|
||||||
case HttpResponseCode.Unauthorized:
|
case HttpResponseCode.Unauthorized:
|
||||||
case HttpResponseCode.Forbidden:
|
case HttpResponseCode.Forbidden:
|
||||||
case HttpResponseCode.NotFound:
|
case HttpResponseCode.NotFound:
|
||||||
case HttpResponseCode.MethodNotAllowed:
|
case HttpResponseCode.MethodNotAllowed:
|
||||||
throw new Error('Request Client Error')
|
throw new Error('Request Client Error.')
|
||||||
case HttpResponseCode.GatewayUnavailable:
|
case HttpResponseCode.GatewayUnavailable:
|
||||||
throw new Error('Request Server Error')
|
throw new Error('Request Server Error.')
|
||||||
}
|
}
|
||||||
|
|
||||||
// left are all unknown
|
// left are all unknown
|
||||||
|
|
|
@ -4,6 +4,9 @@ import { TOKEN } from './config.ts'
|
||||||
import { Message } from "../structures/message.ts"
|
import { Message } from "../structures/message.ts"
|
||||||
import { RedisCacheAdapter } from "../models/CacheAdapter.ts"
|
import { RedisCacheAdapter } from "../models/CacheAdapter.ts"
|
||||||
import { ClientPresence } from "../structures/presence.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({
|
const bot = new Client({
|
||||||
presence: new ClientPresence({
|
presence: new ClientPresence({
|
||||||
|
@ -12,7 +15,6 @@ const bot = new Client({
|
||||||
type: 'COMPETING'
|
type: 'COMPETING'
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
forceNewSession: true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.setAdapter(new RedisCacheAdapter(bot, {
|
bot.setAdapter(new RedisCacheAdapter(bot, {
|
||||||
|
@ -31,32 +33,31 @@ bot.on('ready', () => {
|
||||||
bot.on('debug', console.log)
|
bot.on('debug', console.log)
|
||||||
|
|
||||||
bot.on('messageCreate', async (msg: Message) => {
|
bot.on('messageCreate', async (msg: Message) => {
|
||||||
if (msg.author.bot) return
|
if (msg.author.bot === true) return
|
||||||
console.log(`${msg.author.tag} (${msg.channel + ""}): ${msg.content}`)
|
if (msg.content === "!ping") {
|
||||||
if (msg.content == "!ping") {
|
msg.reply(`Pong! Ping: ${bot.ping}ms`)
|
||||||
msg.reply("Pong! API Ping: " + bot.ping + "ms")
|
} else if (msg.content === "!members") {
|
||||||
} else if (msg.content == "!members") {
|
const col = await msg.guild?.members.collection()
|
||||||
let col = await msg.guild?.members.collection()
|
const data = col?.array().map((c: Member, i: number) => {
|
||||||
let data = col?.array().map((c, i) => {
|
|
||||||
return `${i + 1}. ${c.user.tag}`
|
return `${i + 1}. ${c.user.tag}`
|
||||||
}).join("\n")
|
}).join("\n") as string
|
||||||
msg.channel.send("Member List:\n" + data)
|
msg.channel.send("Member List:\n" + data)
|
||||||
} else if (msg.content == "!guilds") {
|
} else if (msg.content === "!guilds") {
|
||||||
let guilds = await msg.client.guilds.collection()
|
const guilds = await msg.client.guilds.collection()
|
||||||
msg.channel.send("Guild List:\n" + guilds.array().map((c, i) => {
|
msg.channel.send("Guild List:\n" + (guilds.array().map((c, i: number) => {
|
||||||
return `${i + 1}. ${c.name} - ${c.memberCount} members`
|
return `${i + 1}. ${c.name} - ${c.memberCount} members`
|
||||||
}).join("\n"))
|
}).join("\n") as string))
|
||||||
} else if (msg.content == "!roles") {
|
} else if (msg.content === "!roles") {
|
||||||
let col = await msg.guild?.roles.collection()
|
const col = await msg.guild?.roles.collection()
|
||||||
let data = col?.array().map((c, i) => {
|
const data = col?.array().map((c: Role, i: number) => {
|
||||||
return `${i + 1}. ${c.name}`
|
return `${i + 1}. ${c.name}`
|
||||||
}).join("\n")
|
}).join("\n") as string
|
||||||
msg.channel.send("Roles List:\n" + data)
|
msg.channel.send("Roles List:\n" + data)
|
||||||
} else if (msg.content == "!channels") {
|
} else if (msg.content === "!channels") {
|
||||||
let col = await msg.guild?.channels.array()
|
const col = await msg.guild?.channels.array()
|
||||||
let data = col?.map((c, i) => {
|
const data = col?.map((c: GuildChannel, i: number) => {
|
||||||
return `${i + 1}. ${c.name}`
|
return `${i + 1}. ${c.name}`
|
||||||
}).join("\n")
|
}).join("\n") as string
|
||||||
msg.channel.send("Channels List:\n" + data)
|
msg.channel.send("Channels List:\n" + data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue