mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-13 07:25:03 -05:00
Added trigger for player.rank update
This commit is contained in:
@@ -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 (
|
||||
|
||||
24
packages/backend/src/handlers/triggers/updateDiscordRole.ts
Normal file
24
packages/backend/src/handlers/triggers/updateDiscordRole.ts
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user