Ported over "eco shop" and "eco buy"
This commit is contained in:
parent
8417a1ba57
commit
4f443d3e4f
|
@ -0,0 +1,73 @@
|
|||
import { Message } from 'discord.js';
|
||||
import $ from '../../../core/lib';
|
||||
|
||||
export interface ShopItem {
|
||||
cost: number;
|
||||
title: string;
|
||||
description: string;
|
||||
usage: string;
|
||||
run(message: Message, cost: number, amount: number): void;
|
||||
}
|
||||
|
||||
export const ShopItems: ShopItem[] = [
|
||||
{
|
||||
cost: 1,
|
||||
title: 'Hug',
|
||||
description: 'Hug Monika.',
|
||||
usage: 'hug',
|
||||
run(message, cost) {
|
||||
message.channel.send(
|
||||
`Transaction of ${cost} Mon completed successfully. <@394808963356688394>`,
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
cost: 2,
|
||||
title: 'Handholding',
|
||||
description: "Hold Monika's hand.",
|
||||
usage: 'handhold',
|
||||
run(message, cost) {
|
||||
message.channel.send(
|
||||
`Transaction of ${cost} Mons completed successfully. <@394808963356688394>`,
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
cost: 1,
|
||||
title: 'Cute',
|
||||
description: 'Calls Monika cute.',
|
||||
usage: 'cute',
|
||||
run(message) {
|
||||
message.channel.send('<:MoniCheeseBlushRed:637513137083383826>');
|
||||
},
|
||||
},
|
||||
{
|
||||
cost: 3,
|
||||
title: 'Laser Bridge',
|
||||
description: 'Buys what is technically a laser bridge.',
|
||||
usage: 'laser bridge',
|
||||
run(message) {
|
||||
message.channel.send($(lines).random(), {
|
||||
files: [
|
||||
{
|
||||
attachment:
|
||||
'https://raw.githubusercontent.com/keanuplayz/TravBot/dev/assets/TheUltimateLaser.gif',
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const lines = [
|
||||
"It's technically a laser bridge. No refunds.",
|
||||
'You want a laser bridge? You got one!',
|
||||
"Now what'd they say about building bridges... Oh wait, looks like I nuked the planet again. Whoops!",
|
||||
'I saw this redhead the other day who was so excited to buy what I was selling. Needless to say, she was not very happy with me afterward.',
|
||||
"Sorry, but you'll have to wait until the Laser Bridge Builder leaves early access.",
|
||||
'Thank you for your purchase! For you see, this is the legendary laser of obliteration that has been defended and preserved for countless generations!',
|
||||
'They say that a certain troll dwells under this laser bridge, waiting for an unlucky person to fall for th- I mean- Thank you for your purchase!',
|
||||
"Buy?! Hah! How about our new rental service for just under $9.99 a month? But wait, there's more! For just $99.99, you can rent this laser bridge for an entire year and save 16.67% as opposed to renting it monthly!",
|
||||
'Good choice. Owning a laser bridge is the penultimate experience that all true seekers strive for!',
|
||||
'I can already imagine the reviews...\n"9/10 needs more lasers"',
|
||||
];
|
|
@ -1,20 +1,99 @@
|
|||
import Command from '../../../core/command';
|
||||
import $ from '../../../core/lib';
|
||||
import { Storage } from '../../../core/structures';
|
||||
import { Storage, getPrefix } from '../../../core/structures';
|
||||
import { isAuthorized, getMoneyEmbed, getSendEmbed } from './eco-utils';
|
||||
|
||||
export const BuyCommand = new Command({
|
||||
description: '',
|
||||
async run({ guild, channel }) {
|
||||
if (isAuthorized(guild, channel)) {
|
||||
}
|
||||
},
|
||||
});
|
||||
import { ShopItems, ShopItem } from './eco-shop-items';
|
||||
import { EmbedField } from 'discord.js';
|
||||
|
||||
export const ShopCommand = new Command({
|
||||
description: '',
|
||||
async run({ guild, channel }) {
|
||||
description: 'Displays the list of items you can buy in the shop.',
|
||||
async run({ guild, channel, author }) {
|
||||
if (isAuthorized(guild, channel)) {
|
||||
function getShopEmbed(selection: ShopItem[], title = 'Shop') {
|
||||
const fields: EmbedField[] = [];
|
||||
|
||||
for (const item of selection)
|
||||
fields.push({
|
||||
name: `**${item.title}** (${getPrefix(guild)}eco buy ${
|
||||
item.usage
|
||||
})`,
|
||||
value: `${item.description} Costs ${$(item.cost).pluralise(
|
||||
'Mon',
|
||||
's',
|
||||
)}.`,
|
||||
inline: false,
|
||||
});
|
||||
|
||||
return {
|
||||
embed: {
|
||||
color: 0xf1c40f,
|
||||
title: title,
|
||||
fields: fields,
|
||||
footer: {
|
||||
text: 'Mon Shop | TravBot Services',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// In case there's just one page, omit unnecessary details.
|
||||
if (ShopItems.length <= 5) channel.send(getShopEmbed(ShopItems));
|
||||
else {
|
||||
const shopPages = $(ShopItems).split(5);
|
||||
const pageAmount = shopPages.length;
|
||||
const msg = await channel.send(
|
||||
getShopEmbed(shopPages[0], `Shop (Page 1 of ${pageAmount})`),
|
||||
);
|
||||
|
||||
$.paginate(msg, author.id, pageAmount, (page) => {
|
||||
msg.edit(
|
||||
getShopEmbed(
|
||||
shopPages[page],
|
||||
`Shop (Page ${page + 1} of ${pageAmount})`,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const BuyCommand = new Command({
|
||||
description: 'Buys an item from the shop.',
|
||||
usage: '<item>',
|
||||
async run({ guild, channel, args, message, author }) {
|
||||
if (isAuthorized(guild, channel)) {
|
||||
let found = false;
|
||||
|
||||
let amount = 1; // The amount the user is buying.
|
||||
|
||||
// For now, no shop items support being bought multiple times. Uncomment these 2 lines when it's supported/needed.
|
||||
//if (/\d+/g.test(args[args.length - 1]))
|
||||
//amount = parseInt(args.pop());
|
||||
|
||||
let requested = args.join(' '); // The item the user is buying.
|
||||
|
||||
for (let item of ShopItems) {
|
||||
if (item.usage === requested) {
|
||||
const user = Storage.getUser(author.id);
|
||||
const cost = item.cost * amount;
|
||||
|
||||
if (cost > user.money) {
|
||||
channel.send('Not enough Mons!');
|
||||
} else {
|
||||
user.money -= cost;
|
||||
item.run(message, cost, amount);
|
||||
}
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
channel.send(
|
||||
`There's no item in the shop that goes by \`${requested}\`!`,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -70,7 +70,8 @@ export function isAuthorized(
|
|||
guild: Guild | null,
|
||||
channel: TextChannel | DMChannel | NewsChannel,
|
||||
): boolean {
|
||||
if (guild?.id !== '637512823676600330') return true;
|
||||
if (guild?.id === '637512823676600330' || process.argv[2] === 'dev')
|
||||
return true;
|
||||
else {
|
||||
channel.send(
|
||||
"Sorry, this command can only be used in Monika's emote server.",
|
||||
|
|
Loading…
Reference in New Issue