Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SiebeBaree committed Nov 3, 2022
1 parent dbf8f0a commit 591816d
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/assets/crypto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"crypto": [
"BTC",
"ETH",
"BNB",
"XRP",
"ADA",
"SOL",
"DOGE",
"DOT",
"SHIB",
"MATIC",
"AVAX",
"TRX",
"LTC",
"AXS",
"ENJ",
"BAT",
"ATOM",
"XLM",
"ALGO",
"APE",
"SAND",
"EGLD",
"ANKR",
"CHZ",
"MIOTA",
"MKR",
"LUNA"
]
}
28 changes: 28 additions & 0 deletions src/assets/lootTables/rewards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"carrot": 6,
"tomato": 4,
"lettuce": 3,
"shovel": 1,
"fishing_rod": 1,
"hunting_rifle": 1,
"cookie": 30,
"apple": 18,
"rubber_duck": 20,
"money1": 50,
"money2": 100,
"money3": 200,
"book": 10,
"doll": 2,
"lamp": 2,
"computer_mouse": 3,
"fidget_spinner": 8,
"pocket_watch": 1,
"tv": 1,
"earbuds": 1,
"damaged_airdrop": 2,
"cupcake": 15,
"axe": 1,
"bag": 1,
"alcohol": 4,
"wallet": 2
}
22 changes: 22 additions & 0 deletions src/assets/lootboxes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": {
"emoteId": "987800268223709254",
"animated": false,
"description": "Hmm",
"price": 25,
"loot": [
{
"itemId": "potato",
"chance": 10
},
{
"itemId": "carrot",
"chance": 50
},
{
"itemId": "shovel",
"chance": 35
}
]
}
}
4 changes: 4 additions & 0 deletions src/assets/stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"members": 0,
"guilds": 0
}
48 changes: 48 additions & 0 deletions src/assets/stocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"stocks": [
"AAPL",
"MSFT",
"AMZN",
"TSLA",
"GOOG",
"NVDA",
"META",
"V",
"HD",
"MA",
"PFE",
"KO",
"DIS",
"ADBE",
"WMT",
"INTC",
"MCD",
"NKE",
"DHR",
"NFLX",
"BA",
"BLK",
"GM",
"FDX",
"QCOM",
"AMD",
"ORCL",
"PYPL",
"SBUX",
"GE"
],
"marketCloseDays": [
17,
52,
105,
130,
171,
185,
248,
328,
329,
360
],
"openingTime": "9:30",
"closeTime": "16:00"
}
162 changes: 162 additions & 0 deletions src/commands/economy/lootbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
const Command = require('../../structures/Command.js');
const { EmbedBuilder, ApplicationCommandOptionType } = require('discord.js');
const lootboxes = require("../../assets/lootboxes.json");

class Lootbox extends Command {
info = {
name: "lootbox",
description: "Open or buy a lootbox to get awesome rewards.",
options: [
{
name: 'list',
type: ApplicationCommandOptionType.Subcommand,
description: 'Get a list of all available lootboxes.',
options: [
{
name: 'lootbox-id',
type: ApplicationCommandOptionType.String,
description: 'The name of the lootbox you want to open.',
required: false
}
]
},
{
name: 'open',
type: ApplicationCommandOptionType.Subcommand,
description: 'Spin the lucky wheel!',
options: [
{
name: 'lootbox-id',
type: ApplicationCommandOptionType.String,
description: 'The name of the lootbox you want to open.',
required: true
}
]
},
{
name: 'buy',
type: ApplicationCommandOptionType.Subcommand,
description: 'Buy a new lootbox.',
options: [
{
name: 'lootbox-id',
type: ApplicationCommandOptionType.String,
description: 'The name of the lootbox you want to buy.',
required: true
},
{
name: 'amount',
type: ApplicationCommandOptionType.Integer,
description: 'The amount of lootboxes you want to buy. | default: 1.',
required: false,
min_value: 1,
max_value: 10
}
]
},
],
category: "economy",
extraFields: [],
cooldown: 0,
enabled: true,
memberRequired: true,
deferReply: false
};

constructor(...args) {
super(...args);
}

async run(interaction, data) {
if (interaction.options.getSubcommand() === "list") return await this.execList(interaction, data);
if (interaction.options.getSubcommand() === "open") return await this.execOpen(interaction, data);
if (interaction.options.getSubcommand() === "buy") return await this.execBuy(interaction, data);
return await interaction.reply({ content: `Sorry, invalid arguments. Please try again.\nIf you don't know how to use this command use \`/help ${this.info.name}\`.`, ephemeral: true });
}

async execList(interaction, data) {
const name = interaction.options.getString('lootbox-id');

if (name === null) {
await interaction.deferReply();
let lootboxStr = "";

for (const lootboxIndex in this.lootboxIds) {
const lootbox = this.lootboxIds[lootboxIndex];
let icon = `<:${lootbox}:${lootboxes[lootbox].emoteId}>`;
lootboxStr += `${icon} **${lootbox}** ― :tickets: ${lootboxes[lootbox].price}\n> ${lootboxes[lootbox].description}\n\n`;
}

if (lootboxStr !== "") lootboxStr = "\n\n" + lootboxStr;
const embed = new EmbedBuilder()
.setTitle('List of Lootboxes')
.setColor(bot.config.embed.color)
.setDescription(`Lootboxes are bought using tickets. Use </premium:0> to get more information..${lootboxStr}`)
.setFooter({ text: "Get more info using /lootbox list <lootbox-id>" });

return await interaction.editReply({ embeds: [embed] });
} else {
const lootbox = lootboxes[name.toLowerCase()];
if (!lootbox) return await interaction.reply({ content: 'This lootbox doesn\'t exist! Use </lootbox list:0> to get a list with all lootboxes.', ephemeral: true });

await interaction.deferReply();
const promises = lootbox.loot.map(async ({ itemId, chance }) => {
const item = await bot.database.fetchItem(itemId);
return `<:${itemId}:${item.emoteId}> **${item.name}** - ${chance}% chance`;
});

Promise.all(promises)
.then(results => {
const embed = new EmbedBuilder()
.setTitle(`Lootbox: ${name.toLowerCase()}`)
.setColor(bot.config.embed.color)
.setThumbnail(`https://cdn.discordapp.com/emojis/${lootbox.emoteId}.${lootbox.animated ? "gif" : "png"}`)
.setDescription(`> ${lootbox.description}`)
.addFields(
{ name: 'Price', value: `:tickets: ${lootbox.price}`, inline: false },
{ name: 'Possible Loot', value: results.join("\n"), inline: false }
)

return interaction.editReply({ embeds: [embed] });
}).catch();
}
}

async execOpen(interaction, data) {
const name = interaction.options.getString('lootbox-id');
const lootbox = lootboxes[name.toLowerCase()];
if (!lootbox) return await interaction.reply({ content: 'This lootbox doesn\'t exist! Use </lootbox list:0> to get a list with all lootboxes.', ephemeral: true });

if (data.user.lootboxes === undefined) data.user.lootboxes = [];
const lootboxUser = data.user.lootboxes.find(l => l.itemId === name.toLowerCase());
if (lootboxUser === null) return await interaction.reply({ content: `You don't own this lootbox. Please buy this lootbox using \`/lootbox buy ${name.toLowerCase()} [amount]\``, ephemeral: true });

await interaction.deferReply();
const item = await getRandomItem(lootbox.loot);
}

async execBuy(interaction, data) {

}

async getRandomItem(loot) {
let item;

for (let i = 0; i < loot.length; i++) {
const random = bot.tools.randomNumber(1, 1000);
if (random <= loot[i].chance) {
item = loot[i];
break;
}
}

if (item === undefined) item = loot[0];
const shopItem = await bot.database.fetchItem(item.itemId);
return {
...shopItem,
amount: item.amount || 1
};
}
}

module.exports = Lootbox;
Loading

0 comments on commit 591816d

Please sign in to comment.