refactor!: do not store token prefixed with Bot (#2002)

This commit is contained in:
ITOH
2022-02-05 18:57:15 +01:00
committed by GitHub
parent 4d64138520
commit b70c3c8fcb
5 changed files with 6 additions and 6 deletions

View File

@@ -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 || "",

View File

@@ -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,
};

View File

@@ -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,

View File

@@ -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;

View File

@@ -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,
},