UNPKG

@questlabs/core

Version:
168 lines (167 loc) 5.25 kB
"use strict"; // import axios from "axios"; // import * as variables from "../../utils/config"; // import { common, discordTypes } from "../../types"; // class Discord { // private apiKey: string; // private apiSecret: string; // private config: common.config; // private baseUrl: string; // constructor(config: common.constructorConfig) { // this.apiKey = config.apiKey; // this.apiSecret = config.apiSecret; // this.baseUrl = // config?.testMode == true ? variables.serverTestUrl : variables.serverUrl; // this.config = { // headers: { apiKey: this.apiKey, apiSecret: this.apiSecret, "User-Agent": config.userAgent, }, // }; // } // async connect({ // entityId, // userId, // token, // discordRedirectCode, // redirectUri, // }: discordTypes.connectDiscord) { // try { // if (!discordRedirectCode || discordRedirectCode == "") { // throw new Error("Invalid discordRedirectCode"); // } // if (!redirectUri || redirectUri == "") { // throw new Error("Invalid redirectUri"); // } // if (!entityId || entityId == "") { // throw new Error("Invalid entityId"); // } // if (!userId || userId == "") { // throw new Error("Invalid userId"); // } // if (!token || token == "") { // throw new Error("Invalid token"); // } // const headers = { ...this.config.headers, userId, token }; // const body = { // code: discordRedirectCode, // redirectUri, // entityId, // userId, // }; // const response = await axios.post(`${this.baseUrl}/discord/login`, body, { // headers, // }); // return response.data; // } catch (error) { // throw new Error(error.message); // } // } // async disconnect({ // entityId, // userId, // token, // }: discordTypes.disconnectDiscord) { // try { // if (!entityId || entityId == "") { // throw new Error("Invalid entityId"); // } // if (!userId || userId == "") { // throw new Error("Invalid userId"); // } // if (!token || token == "") { // throw new Error("Invalid token"); // } // const headers = { ...this.config.headers, userId, token }; // const body = { userId, entityId }; // const response = await axios.post( // `${this.baseUrl}/discord/logout`, // body, // { headers } // ); // return response.data; // } catch (error) { // throw new Error(error.message); // } // } // async fetchMyGuilds({ entityId, userId, token }: discordTypes.fetchMyGuilds) { // try { // if (!entityId || entityId == "") { // throw new Error("Invalid entityId"); // } // if (!userId || userId == "") { // throw new Error("Invalid userId"); // } // if (!token || token == "") { // throw new Error("Invalid token"); // } // const headers = { ...this.config.headers, userId, token }; // const params = { entityId, userId }; // const response = await axios.get(`${this.baseUrl}/discord/my/guilds`, { // headers, // params, // }); // return response.data; // } catch (error) { // throw new Error(error.message); // } // } // private async fetchMyGuildRoles({ // entityId, // userId, // token, // guildId, // }: discordTypes.fetchMyGuildRoles) { // try { // if (!entityId || entityId == "") { // throw new Error("Invalid entityId"); // } // if (!userId || userId == "") { // throw new Error("Invalid userId"); // } // if (!token || token == "") { // throw new Error("Invalid token"); // } // if (!guildId || guildId == "") { // throw new Error("Invalid guildId"); // } // const headers = { ...this.config.headers, userId, token }; // const params = { entityId, userId }; // const response = await axios.get( // `${this.baseUrl}/discord/guilds/${guildId}/roles`, // { headers, params } // ); // return response.data; // } catch (error) { // throw new Error(error.message); // } // } // private async fetchGuildSceduledEvents({ // entityId, // userId, // token, // guildId, // }: discordTypes.fetchGuildSceduledEvents) { // try { // if (!entityId || entityId == "") { // throw new Error("Invalid entityId"); // } // if (!userId || userId == "") { // throw new Error("Invalid userId"); // } // if (!token || token == "") { // throw new Error("Invalid token"); // } // if (!guildId || guildId == "") { // throw new Error("Invalid guildId"); // } // const headers = { ...this.config.headers, userId, token }; // const params = { entityId, userId }; // const response = await axios.get( // `${this.baseUrl}/discord/guilds/${guildId}/events`, // { headers, params } // ); // return response.data; // } catch (error) { // throw new Error(error.message); // } // } // } // export default Discord;