mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
refactor: modularize into core/events/formatters/drivers
This commit is contained in:
parent
7b341ff9f4
commit
0af6b9a4b8
62 changed files with 2430 additions and 2015 deletions
48
src/drivers/discord/render.ts
Normal file
48
src/drivers/discord/render.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import type { FormattedMessage, NeutralActionStyle, NeutralMessage } from "../../types";
|
||||
|
||||
function toStyle(style: NeutralActionStyle): number {
|
||||
switch (style) {
|
||||
case "primary":
|
||||
return 3;
|
||||
case "danger":
|
||||
return 4;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
export function renderNeutralMessage(message: NeutralMessage): FormattedMessage {
|
||||
return {
|
||||
embeds: [
|
||||
{
|
||||
title: message.title,
|
||||
url: message.url,
|
||||
color: message.color,
|
||||
description: message.description,
|
||||
author: message.author
|
||||
? {
|
||||
name: message.author.name,
|
||||
icon_url: message.author.iconUrl,
|
||||
url: message.author.url,
|
||||
}
|
||||
: undefined,
|
||||
fields: message.fields,
|
||||
footer: message.footer ? { text: message.footer } : undefined,
|
||||
timestamp: message.timestamp,
|
||||
},
|
||||
],
|
||||
components: message.actions?.length
|
||||
? [
|
||||
{
|
||||
type: 1,
|
||||
components: message.actions.map((action) => ({
|
||||
type: 2,
|
||||
style: toStyle(action.style),
|
||||
label: action.label,
|
||||
custom_id: action.id,
|
||||
})),
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue