Call discord REST API directly from backend instead

This commit is contained in:
Alec LaLonde
2021-02-11 17:16:04 -07:00
parent 4f020fe0c3
commit 7003f50dbb
6 changed files with 25 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ interface IConfig {
infuraId: string;
pSEEDAddress: string;
brightIdAppUrl: string;
discordBotToken: string;
}
function parseEnv<T extends string | number>(
@@ -55,4 +56,5 @@ export const CONFIG: IConfig = {
process.env.NEXT_BRIGHTID_APP_URL,
'https://app.brightid.org',
),
discordBotToken: parseEnv(process.env.DISCORD_BOT_TOKEN, ''),
};

View File

@@ -1,8 +1,14 @@
import { UpdateRole } from '@metafam/discord-bot';
import fetch from 'node-fetch';
import { AccountType_Enum, Player } from '../../lib/autogen/hasura-sdk';
import { TriggerPayload } from './types';
export interface UpdateRole {
playerId: string;
previousRole: string | undefined;
newRole: string;
}
export const updateDiscordRole = async (
payload: TriggerPayload<Player>,
) => {
@@ -17,8 +23,21 @@ export const updateDiscordRole = async (
if (newRank == null) return;
const discordPayload: UpdateRole = {
playerId: newPlayer?.id,
previousRole: oldPlayer?.rank?.toString(),
newRole: newRank
}
// todo call API in discord-bot repo
// look up guild by guildname = 'metagame' (for now),
// then look up guild_account for DISCORD type
// will need to create new graphql queries for these (can they be joined into one?)
// call discord API. for each query we'll need serverId, playerId, and roleId
// since we don't have roleIds, we'll need to look up the roles in the server
// and just match by strings for the time being.
// https://discord.com/developers/docs/resources/guild#get-guild-roles
// if there's an oldRank, delete it.
// if there's a new rank, add it
fetch()
};

View File

@@ -15,7 +15,6 @@
},
"author": "",
"license": "ISC",
"types": "src/types.d.ts",
"dependencies": {
"@typeit/discord": "4.0.9",
"discord.js": "12.5.1",

View File

@@ -2,7 +2,6 @@
import { Client } from '@typeit/discord';
import { CONFIG } from './config';
import * as types from './types';
async function start() {
const client = new Client({
@@ -18,6 +17,3 @@ async function start() {
}
start();
export { types };

View File

@@ -1,4 +0,0 @@
export interface UpdateRole {
previousRole: string | undefined;
newRole: string;
}