Spot/model/messages.ts

59 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-11-30 21:17:29 +01:00
import { client } from "../bot";
interface Message {
names: string[];
description: string;
title: string;
text: string;
friendlyName: string;
category: string;
}
export const messages: Record<string, Message> = {};
let avatarUrl = "";
2023-11-30 21:17:29 +01:00
const load = async () => {
const messagesList = require('../messages.json')["faq"];
messagesList.forEach((msg: any) => {
messages[msg["title"]] = msg
})
2023-11-30 21:17:29 +01:00
const userInfo = await client.user;
const avatar = userInfo?.avatarURL() ?? '';
avatarUrl = avatar;
console.log(avatarUrl);
}
load();
export const get = (name: string) => messages[name];
export const getList = () => Object.keys(messages).map(msg => ({ name: messages[msg].names[0], value: messages[msg].description }));
export const getEmbed = (name: string) => {
let foundMsg: Message | undefined;
2023-11-30 21:17:29 +01:00
Object.keys(messages).forEach((msgKey) => {
if (foundMsg) return;
const msg = messages[msgKey]
2023-11-30 21:17:29 +01:00
if (msg.names.includes(name)) {
foundMsg = msg;
return;
}
});
if (foundMsg == null) return;
return {
color: 0xA95B44,
author: {
name: foundMsg.title,
iconUrl: avatarUrl,
},
description: foundMsg.text,
}
}