From d12751006e98ef11f3bec8f45fd50d91c2cb4a10 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Thu, 22 Dec 2022 21:15:38 -0500 Subject: add epic games connection --- src/connections/BattleNet/index.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/connections/BattleNet') diff --git a/src/connections/BattleNet/index.ts b/src/connections/BattleNet/index.ts index 5bbfefe9..f4b317cc 100644 --- a/src/connections/BattleNet/index.ts +++ b/src/connections/BattleNet/index.ts @@ -1,7 +1,12 @@ +import { + Config, + ConnectedAccount, + ConnectionCallbackSchema, + ConnectionLoader, + DiscordApiErrors, +} from "@fosscord/util"; import fetch from "node-fetch"; -import { Config, ConnectedAccount, ConnectionCallbackSchema, DiscordApiErrors } from "../../util"; import Connection from "../../util/connections/Connection"; -import { ConnectionLoader } from "../../util/connections/ConnectionLoader"; import { BattleNetSettings } from "./BattleNetSettings"; interface OAuthTokenResponse { @@ -46,7 +51,8 @@ export default class BattleNetConnection extends Connection { // TODO: probably shouldn't rely on cdn as this could be different from what we actually want. we should have an api endpoint setting. url.searchParams.append( "redirect_uri", - `${Config.get().cdn.endpointPrivate || "http://localhost:3001" + `${ + Config.get().cdn.endpointPrivate || "http://localhost:3001" }/connections/${this.id}/callback`, ); url.searchParams.append("scope", this.scopes.join(" ")); @@ -74,8 +80,9 @@ export default class BattleNetConnection extends Connection { code: code, client_id: this.settings.clientId!, client_secret: this.settings.clientSecret!, - redirect_uri: `${Config.get().cdn.endpointPrivate || "http://localhost:3001" - }/connections/${this.id}/callback`, + redirect_uri: `${ + Config.get().cdn.endpointPrivate || "http://localhost:3001" + }/connections/${this.id}/callback`, }), }) .then((res) => res.json()) @@ -106,7 +113,9 @@ export default class BattleNetConnection extends Connection { }); } - async handleCallback(params: ConnectionCallbackSchema): Promise { + async handleCallback( + params: ConnectionCallbackSchema, + ): Promise { const userId = this.getUserId(params.state); const token = await this.exchangeCode(params.state, params.code!); const userInfo = await this.getUser(token); @@ -114,7 +123,7 @@ export default class BattleNetConnection extends Connection { const exists = await this.hasConnection(userId, userInfo.id.toString()); if (exists) return null; - + return await this.createConnection({ user_id: userId, external_id: userInfo.id.toString(), -- cgit 1.5.1