TravBot-v3/src/commands/fun/modules/eco-utils.ts

107 lines
3.3 KiB
TypeScript
Raw Normal View History

import {pluralise} from "../../../lib";
import {Storage} from "../../../structures";
2021-12-29 20:26:31 +00:00
import {User, Guild, TextChannel, DMChannel, NewsChannel, Channel, TextBasedChannel} from "discord.js";
2020-12-15 11:15:28 +00:00
export const ECO_EMBED_COLOR = 0xf1c40f;
2021-11-03 11:18:26 +00:00
export function getMoneyEmbed(user: User, inline: boolean = false): object {
2020-12-15 01:44:28 +00:00
const profile = Storage.getUser(user.id);
2021-10-31 16:59:29 +00:00
console.log(profile);
2021-11-03 11:18:26 +00:00
if (inline) {
return {
color: ECO_EMBED_COLOR,
author: {
name: user.username,
icon_url: user.displayAvatarURL({
format: "png",
dynamic: true
})
},
fields: [
{
name: "Balance",
value: pluralise(profile.money, "Mon", "s")
}
]
};
} else {
return {
embeds: [
{
color: ECO_EMBED_COLOR,
author: {
name: user.username,
icon_url: user.displayAvatarURL({
format: "png",
dynamic: true
})
},
fields: [
{
name: "Balance",
value: pluralise(profile.money, "Mon", "s")
}
]
}
]
};
}
}
export function getSendEmbed(sender: User, receiver: User, amount: number): object {
2020-12-15 01:44:28 +00:00
return {
2021-10-31 16:59:29 +00:00
embeds: [
{
color: ECO_EMBED_COLOR,
author: {
2021-11-03 11:18:26 +00:00
name: sender.username,
icon_url: sender.displayAvatarURL({
2021-10-31 16:59:29 +00:00
format: "png",
dynamic: true
})
},
2021-11-03 11:18:26 +00:00
title: "Transaction",
description: `${sender.toString()} has sent ${pluralise(
amount,
"Mon",
"s"
)} to ${receiver.toString()}!`,
2021-10-31 16:59:29 +00:00
fields: [
{
2021-11-03 11:18:26 +00:00
name: `Sender: ${sender.tag}`,
value: pluralise(Storage.getUser(sender.id).money, "Mon", "s")
},
{
name: `Receiver: ${receiver.tag}`,
value: pluralise(Storage.getUser(receiver.id).money, "Mon", "s")
2021-10-31 16:59:29 +00:00
}
2021-11-03 11:18:26 +00:00
],
footer: {
text: receiver.username,
icon_url: receiver.displayAvatarURL({
format: "png",
dynamic: true
})
2020-12-15 01:44:28 +00:00
}
}
2021-11-03 11:18:26 +00:00
]
2020-12-15 01:44:28 +00:00
};
}
2021-12-29 20:26:31 +00:00
export function isAuthorized(guild: Guild | null, channel: TextBasedChannel): boolean {
if (IS_DEV_MODE) {
return true;
}
if (guild?.id !== "637512823676600330") {
channel.send("Sorry, this command can only be used in Monika's emote server.");
return false;
} else if (channel?.id !== "669464416420364288") {
channel.send("Sorry, this command can only be used in <#669464416420364288>.");
return false;
} else {
2021-10-31 17:51:24 +00:00
return true;
2020-12-15 01:44:28 +00:00
}
}