This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
64 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,5 @@ | ||
import { Embed, EmbedDataSchema, MessageContent, EmbedData } from "../"; | ||
import { EmbedBuilder } from "discord.js"; | ||
import { safeParse } from "valibot"; | ||
import { MessageContent } from "../"; | ||
|
||
export function messageRebuild(content: MessageContent) { | ||
if (typeof content == "string") return content; | ||
|
||
if (!content) | ||
return console.warn( | ||
"Type Error: Embed data is invalid and has been blocked", | ||
); | ||
|
||
if ((content as { baseU64: string }).baseU64) | ||
return console.log("Message content of non-string is not yet supported"); | ||
|
||
// is embed | ||
let embedParsed = safeParse(EmbedDataSchema, content); | ||
if (!embedParsed.success) | ||
return console.warn( | ||
"Type Error: Embed data is invalid and has been blocked by Valibot", | ||
); | ||
return { embeds: [embedRebuild(embedParsed.output)] }; | ||
} | ||
|
||
export function embedRebuild(embedData: EmbedData) { | ||
let embed = new Embed(embedData); | ||
let discordEmbed = new EmbedBuilder({ | ||
title: embed.title, | ||
url: embed.link, | ||
description: embed.description, | ||
thumbnail: embed.thumbnail, | ||
fields: embed.contents?.map((val) => { | ||
return { | ||
name: val.key ?? "", | ||
value: val.value, | ||
inline: !!val.inline, | ||
}; | ||
}), | ||
image: embed.image, | ||
timestamp: embed.timestamp?.toString(), | ||
color: embed.color, | ||
}); | ||
|
||
if (embed.author) | ||
discordEmbed.setAuthor({ | ||
name: embed.author.name, | ||
iconURL: embed.author.icon, | ||
url: embed.author.link, | ||
}); | ||
|
||
if (embed.footer) | ||
discordEmbed.setFooter({ | ||
text: embed.footer.text, | ||
iconURL: embed.footer.icon, | ||
}); | ||
|
||
return discordEmbed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,5 @@ | ||
import { MessageContent, Embed, EmbedDataSchema, EmbedData } from "../"; | ||
import { Embed as GuildedEmbed } from "guilded.js"; | ||
import { safeParse } from "valibot"; | ||
import {} from "discord.js"; | ||
import { MessageContent } from "../"; | ||
|
||
export function messageRebuild(content: MessageContent) { | ||
if (typeof content == "string") return content; | ||
|
||
if (!content) | ||
return console.warn( | ||
"Type Error: Embed data is invalid and has been blocked", | ||
); | ||
|
||
if ((content as { baseU64: string }).baseU64) | ||
return console.log("Message content of non-string is not yet supported"); | ||
|
||
// is embed | ||
let embedParsed = safeParse(EmbedDataSchema, content); | ||
if (!embedParsed.success) | ||
return console.warn( | ||
"Type Error: Embed data is invalid and has been blocked by Valibot", | ||
); | ||
return { embeds: [embedRebuild(embedParsed.output)] }; | ||
} | ||
|
||
export function embedRebuild(embedData: EmbedData) { | ||
let embed = new Embed(embedData); | ||
let guildedEmbed = new GuildedEmbed({ | ||
title: embed.title, | ||
url: embed.link, | ||
description: embed.description, | ||
thumbnail: embed.thumbnail, | ||
fields: embed.contents?.map((val) => { | ||
return { | ||
name: val.key ?? "", | ||
value: val.value, | ||
inline: !!val.inline, | ||
}; | ||
}), | ||
image: embed.image, | ||
timestamp: embed.timestamp?.toString(), | ||
color: embed.color, | ||
}); | ||
|
||
if (embed.author) | ||
guildedEmbed.setAuthor( | ||
embed.author.name, | ||
embed.author.icon, | ||
embed.author.link, | ||
); | ||
if (embed.footer) | ||
guildedEmbed.setFooter(embed.footer.text, embed.footer.icon); | ||
|
||
return guildedEmbed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters