mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-11 22:45:04 -05:00
Call discord REST API directly from backend instead
This commit is contained in:
@@ -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, ''),
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"types": "src/types.d.ts",
|
||||
"dependencies": {
|
||||
"@typeit/discord": "4.0.9",
|
||||
"discord.js": "12.5.1",
|
||||
|
||||
@@ -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 };
|
||||
|
||||
4
packages/discord-bot/src/types.d.ts
vendored
4
packages/discord-bot/src/types.d.ts
vendored
@@ -1,4 +0,0 @@
|
||||
export interface UpdateRole {
|
||||
previousRole: string | undefined;
|
||||
newRole: string;
|
||||
}
|
||||
Reference in New Issue
Block a user