From b70c3c8fcbfba81b064765a68df564e178bd7e44 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 5 Feb 2022 18:57:15 +0100 Subject: [PATCH] refactor!: do not store token prefixed with `Bot` (#2002) --- src/bot.ts | 4 ++-- src/rest/createRequestBody.ts | 2 +- src/ws/identify.ts | 2 +- src/ws/resharder.ts | 2 +- src/ws/resume.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index e02dd6442..c88efddb7 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -98,7 +98,7 @@ export function createBot(options: CreateBotOptions): Bot { const bot = { id: options.botId, applicationId: options.applicationId || options.botId, - token: `Bot ${options.token}`, + token: options.token, events: createEventHandlers(options.events), intents: options.intents.reduce((bits, next) => (bits |= GatewayIntents[next]), 0), botGatewayData: options.botGatewayData, @@ -242,7 +242,7 @@ export function createRestManager(options: CreateRestManagerOptions) { invalidRequestFrozenAt: 0, invalidRequestErrorStatuses: [401, 403, 429], version, - token: `${options.token.startsWith("Bot ") ? "" : "Bot "}${options.token}`, + token: options.token, maxRetryCount: options.maxRetryCount || 10, secretKey: options.secretKey || "discordeno_best_lib_ever", customUrl: options.customUrl || "", diff --git a/src/rest/createRequestBody.ts b/src/rest/createRequestBody.ts index 3e3b2c622..ea2681a99 100644 --- a/src/rest/createRequestBody.ts +++ b/src/rest/createRequestBody.ts @@ -6,7 +6,7 @@ import { RestPayload, RestRequest } from "./rest.ts"; /** Creates the request body and headers that are necessary to send a request. Will handle different types of methods and everything necessary for discord. */ export function createRequestBody(rest: RestManager, queuedRequest: { request: RestRequest; payload: RestPayload }) { const headers: { [key: string]: string } = { - Authorization: rest.token, + Authorization: `Bot ${rest.token}`, "User-Agent": USER_AGENT, }; diff --git a/src/ws/identify.ts b/src/ws/identify.ts index 0778c5f05..7b35e835c 100644 --- a/src/ws/identify.ts +++ b/src/ws/identify.ts @@ -45,7 +45,7 @@ export function identify(gateway: GatewayManager, shardId: number, maxShards: nu { op: GatewayOpcodes.Identify, d: { - token: gateway.token, + token: `Bot ${gateway.token}`, compress: gateway.compress, properties: { $os: gateway.$os, diff --git a/src/ws/resharder.ts b/src/ws/resharder.ts index 9f1007ec5..b242401bb 100644 --- a/src/ws/resharder.ts +++ b/src/ws/resharder.ts @@ -5,7 +5,7 @@ import { GetGatewayBot } from "../types/gateway/getGatewayBot.ts"; export async function resharder(gateway: GatewayManager) { // TODO: is it possible to route this to REST? const results = (await fetch(`https://discord.com/api/gateway/bot`, { - headers: { Authorization: gateway.token }, + headers: { Authorization: `Bot ${gateway.token}` }, }).then((res) => res.json())) as GetGatewayBot; const percentage = ((results.shards - gateway.maxShards) / gateway.maxShards) * 100; diff --git a/src/ws/resume.ts b/src/ws/resume.ts index 3a3b37628..1b1cf842b 100644 --- a/src/ws/resume.ts +++ b/src/ws/resume.ts @@ -53,7 +53,7 @@ export function resume(gateway: GatewayManager, shardId: number) { { op: GatewayOpcodes.Resume, d: { - token: gateway.token, + token: `Bot ${gateway.token}`, session_id: sessionId, seq: previousSequenceNumber, },