This commit is contained in:
mierenmanz 2021-04-29 13:11:53 +02:00
commit 54b0356a72
2 changed files with 14 additions and 6 deletions

View file

@ -10,11 +10,17 @@ import { RequestQueue } from './queue.ts'
import { APIRequest } from './request.ts'
function parseResponse(res: Response, raw: boolean): any {
if (raw) return res
if (res.status === 204) return undefined
if (res.headers.get('content-type')?.startsWith('application/json') === true)
return res.json()
return res.arrayBuffer().then((e) => new Uint8Array(e))
let result
if (res.status === 204) result = Promise.resolve(undefined)
else if (
res.headers.get('content-type')?.startsWith('application/json') === true
)
result = res.json()
else result = res.arrayBuffer().then((e) => new Uint8Array(e))
if (raw) {
return { response: res, body: result }
} else return result
}
function getAPIOffset(serverDate: number | string): number {
@ -197,7 +203,7 @@ export class BucketHandler {
let data
try {
data = await parseResponse(res, request.options.rawResponse ?? false)
data = await parseResponse(res, false)
} catch (err) {
throw new HTTPError(
err.message,

View file

@ -254,6 +254,8 @@ client.on('messageCreate', async (msg: Message) => {
buf += `\n${role.name === '@everyone' ? 'everyone' : role.name}`
}
msg.reply(buf)
} else if (msg.content === '!addrole') {
msg.member?.roles.add('837255383759716362')
} else if (msg.content === '!timer') {
msg.channel.send('3...').then((msg) => {
setTimeout(() => {