mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Fixed guild discord_invite_url reference, persist guild icon url from discord
This commit is contained in:
committed by
Alec LaLonde
parent
6e3fe89744
commit
c7eee3c4df
@@ -1,9 +1,10 @@
|
||||
/* eslint-disable no-console */
|
||||
import { exchangeCodeForAccessToken, GuildDiscordMetadata, OAuth2CodeExchangeResponse, PartialGuild } from '@metafam/discord-bot';
|
||||
import { DiscordUtil } from '@metafam/utils';
|
||||
import { Request, Response } from 'express';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { DiscordGuildAuthResponse, GuildStatus_Enum, GuildType_Enum } from '../../../../lib/autogen/hasura-sdk';
|
||||
import { DiscordGuildAuthResponse, Guild_Insert_Input,GuildStatus_Enum, GuildType_Enum } from '../../../../lib/autogen/hasura-sdk';
|
||||
import { client } from '../../../../lib/hasuraClient';
|
||||
|
||||
export const handleOAuthCallback = async (
|
||||
@@ -97,7 +98,7 @@ const parseDiscordMetadata = (oauthResponse: OAuth2CodeExchangeResponse): GuildD
|
||||
}
|
||||
|
||||
const createNewGuild = async (discordGuild: PartialGuild, discordMetadata: GuildDiscordMetadata): Promise<DiscordGuildAuthResponse> => {
|
||||
const newGuildPayload = {
|
||||
let newGuildPayload: Guild_Insert_Input = {
|
||||
type: GuildType_Enum.Project,
|
||||
name: discordGuild.name,
|
||||
guildname: discordGuild.name.toLowerCase().replace(/[^a-z0-9]/g, ''),
|
||||
@@ -105,6 +106,13 @@ const createNewGuild = async (discordGuild: PartialGuild, discordMetadata: Guild
|
||||
status: GuildStatus_Enum.Pending,
|
||||
discord_metadata: discordMetadata,
|
||||
};
|
||||
|
||||
if (discordMetadata.logoHash != null) {
|
||||
newGuildPayload = {
|
||||
...newGuildPayload,
|
||||
logo: DiscordUtil.guildIconUrl(discordGuild.id, discordMetadata.logoHash),
|
||||
};
|
||||
}
|
||||
|
||||
const createGuildResponse = await client.CreateGuild({ objects: newGuildPayload });
|
||||
if (createGuildResponse.insert_guild != null && createGuildResponse.insert_guild.returning.length > 0 ) {
|
||||
|
||||
11
packages/utils/src/discordHelpers.ts
Normal file
11
packages/utils/src/discordHelpers.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
export const enum SupportedImageFormat {
|
||||
PNG = 'png',
|
||||
JPEG = 'jpg',
|
||||
GIF = 'gif',
|
||||
}
|
||||
|
||||
// see https://discord.com/developers/docs/reference#image-formatting
|
||||
export const guildIconUrl = (guildId: string, iconHash: string, type: SupportedImageFormat = SupportedImageFormat.PNG): string => {
|
||||
return `https://cdn.discordapp.com/icons/${guildId}/${iconHash}.${type}`;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './arrayHelpers';
|
||||
export * as Constants from './constants';
|
||||
export * as did from './did';
|
||||
export * as DiscordUtil from './discordHelpers';
|
||||
export * as numbers from './numbers';
|
||||
export * from './promiseHelpers';
|
||||
|
||||
@@ -24,11 +24,11 @@ export const GuildLinks: React.FC<Props> = ({ guild }) => {
|
||||
</Button>
|
||||
</WrapItem>
|
||||
) : null}
|
||||
{guild.discord_metadata?.inviteUrl ? (
|
||||
{guild.discord_invite_url ? (
|
||||
<WrapItem>
|
||||
<Button
|
||||
as="a"
|
||||
href={guild.discord_metadata.inviteUrl}
|
||||
href={guild.discord_invite_url}
|
||||
target="_blank"
|
||||
size="xs"
|
||||
bgColor="discord"
|
||||
|
||||
@@ -67,7 +67,7 @@ export const GuildFragment = gql`
|
||||
id
|
||||
guildname
|
||||
description
|
||||
discord_metadata
|
||||
discord_invite_url
|
||||
join_button_url
|
||||
logo
|
||||
moloch_address
|
||||
|
||||
Reference in New Issue
Block a user