diff --git a/src/cv2.ts b/src/cv2.ts new file mode 100644 index 0000000..5fe62c9 --- /dev/null +++ b/src/cv2.ts @@ -0,0 +1,68 @@ +import { + AnyMessageComponent, + Component, + ComponentTypes, + FileComponent, + MediaGalleryComponent, + MessageActionRow, + SectionComponent, + SeparatorComponent, + TextDisplayComponent +} from "oceanic.js"; +import { client } from "."; + +export const Divider: SeparatorComponent = { + type: ComponentTypes.SEPARATOR, + divider: true +}; +export const Header = ( + title: string, + level: 1 | 2 | 3 +): TextDisplayComponent => { + return { + type: ComponentTypes.TEXT_DISPLAY, + content: `${"#".repeat(level)} ${title}` + }; +}; + +export async function generateUserComponent( + id: string +): Promise { + const user = await client.rest.users.get(id); + return { + type: ComponentTypes.SECTION, + components: [ + Header("User", 3), + { + type: ComponentTypes.TEXT_DISPLAY, + content: `${user.globalName || user.username}\n-# @${ + user.username + }` + } + ], + accessory: { + type: ComponentTypes.THUMBNAIL, + media: { + url: user.avatarURL("png", 128) + } + } + }; +} +export function generateList( + elements: { + [key: string]: string; + }, + title?: string +): TextDisplayComponent[] { + let working: TextDisplayComponent[] = []; + + if (title) working.push(Header(title, 3)); + for (const key of Object.keys(elements)) { + working.push({ + type: ComponentTypes.TEXT_DISPLAY, + content: `**${key}**\n-# ${elements[key].replaceAll("\n", "\n-# ")}` + }); + } + + return working; +}