Added trigger for player.rank update

This commit is contained in:
Alec LaLonde
2021-02-11 16:02:20 -07:00
parent 4d59ac3f1b
commit 4f020fe0c3
7 changed files with 49 additions and 2 deletions

View File

@@ -19,6 +19,7 @@
"license": "ISC",
"dependencies": {
"3box": "1.22.2",
"@metafam/discord-bot": "^0.1.0",
"@metafam/utils": "1.0.0",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
@@ -26,16 +27,16 @@
"express": "4.17.1",
"express-graphql": "0.11.0",
"graphql": "15.4.0",
"graphql-request": "3.2.0",
"graphql-tag": "2.11.0",
"graphql-tools": "7.0.2",
"imgix-core-js": "2.3.2",
"node-fetch": "2.6.1",
"graphql-request": "3.2.0",
"sourcecred": "0.7.6"
},
"devDependencies": {
"@types/express": "4.17.9",
"@types/bluebird": "3.5.32",
"@types/express": "4.17.9",
"@types/node-fetch": "2.5.7",
"concurrently": "5.3.0",
"ts-node-dev": "1.1.1"

View File

@@ -3,9 +3,11 @@ import { ParamsDictionary } from 'express-serve-static-core';
import { fetchBoxVerifiedAccounts } from './fetchBoxVerifiedAccounts';
import { TriggerPayload } from './types';
import { updateDiscordRole } from './updateDiscordRole';
const TRIGGERS = {
fetchBoxVerifiedAccounts,
updateDiscordRole
};
export const triggerHandler = async (

View File

@@ -0,0 +1,24 @@
import { UpdateRole } from '@metafam/discord-bot';
import { AccountType_Enum, Player } from '../../lib/autogen/hasura-sdk';
import { TriggerPayload } from './types';
export const updateDiscordRole = async (
payload: TriggerPayload<Player>,
) => {
const {old: oldPlayer, new: newPlayer} = payload.event.data;
const discordPlayerAccount = newPlayer?.Accounts.find(a => a.type === AccountType_Enum.Discord);
if (discordPlayerAccount?.identifier == null) return;
const newRank = newPlayer?.rank;
if (newRank == null) return;
const discordPayload: UpdateRole = {
previousRole: oldPlayer?.rank?.toString(),
newRole: newRank
}
// todo call API in discord-bot repo
};

View File

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

View File

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

4
packages/discord-bot/src/types.d.ts vendored Normal file
View File

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