68 lines
1.3 KiB
TypeScript
68 lines
1.3 KiB
TypeScript
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<SectionComponent> {
|
|
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;
|
|
}
|