Spot/model/messages.ts
spiral 56091a6df7
rewrite
this is a rewrite of the bot in typescript. detritus is used as a discord library instead of discord.js
2022-10-21 17:22:01 +00:00

58 lines
1.3 KiB
TypeScript

import { restClient } from "../bot";
interface Message {
names: string[];
description: string;
title: string;
text: string;
friendlyName: string;
category: string;
}
export const messages: Record<string, Message> = {};
let avatarUrl = "";
const load = async () =>
{
const messagesList = require('../messages.json')["faq"];
messagesList.forEach((msg: any) => {
messages[msg["title"]] = msg
})
const userInfo = await restClient.fetchMe();
avatarUrl = `https://cdn.discordapp.com/avatars/${userInfo.id}/${userInfo.avatar}.png`;
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;
Object.keys(messages).forEach((msgKey) =>
{
if (foundMsg) return;
const msg = messages[msgKey]
if (msg.names.includes(name))
{
foundMsg = msg;
return;
}
});
if (foundMsg == null) return;
return {
color: 0xA95B44,
author: {
name: foundMsg.title,
iconUrl: avatarUrl,
},
description: foundMsg.text,
}
}