parent
a99229733c
commit
322fef7c3c
@ -0,0 +1,70 @@ |
||||
const Discord = require('discord.js'); |
||||
|
||||
const Chests = require("../../models/chests"); |
||||
|
||||
const ask = require('../../util/ask'); |
||||
|
||||
module.exports = { |
||||
name: "chests", |
||||
aliases: ['setupchests', 'enablechests', 'togglechests', 'tch'], |
||||
meta: { |
||||
category: 'Leveling', |
||||
description: "Enable or disable chests in your server, or set a channel for them to spawn in", |
||||
syntax: '`chests [enable|disable|toggle|channel]`', |
||||
extra: null, |
||||
guildOnly: true |
||||
}, |
||||
help: new Discord.MessageEmbed() |
||||
.setTitle("Help -> Chests") |
||||
.setDescription("Enable or disable chests in your server, or set a channel for them to spawn in") |
||||
.addField("Notice", "You must have administrator permissions to edit these settings.") |
||||
.addField("Syntax", "`chests [enable|disable|channel]`"), |
||||
async execute(message, msg, args, cmd, prefix, mention, client) { |
||||
if (!message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must have administrator permissions in order to edit these settings.");} |
||||
if (!args.length) {args[0] = 'enable';} |
||||
|
||||
if (['e', 'enable'].includes(args[0].toLowerCase())) { |
||||
if (client.misc.cache.chests.includes(message.guild.id)) {return message.channel.send("This server already has chest spawning enabled.")}; |
||||
try { |
||||
am = await message.channel.send("Would you like to have me send chests to a specific channel?"); |
||||
await am.react('👍'); |
||||
await am.react('👎'); |
||||
} catch {return message.channel.send(":thinking: hmmm... something went wrong there. I might not have permissions to add reactions to messages, and this could be the issue.");} |
||||
try { |
||||
let rc = am.createReactionCollector({filter: (r, u) => ['👍', '👎'].includes(r.emoji.name) && u.id === message.author.id, max: 1, time: 60000}); |
||||
rc.on("collect", async r => { |
||||
useCh = r.emoji.name === "👍"; |
||||
let chestCh = ''; |
||||
if (useCh) { |
||||
let chestCh = await ask(message, 'What channel would you like me to send chests to? (Ideally, people should be able to speak in it so they can claim the chests)', 60000, false, true); |
||||
if (!chestCh) {return;} |
||||
if (!message.guild.channels.cache.has(chestCh) || !message.guild.channels.cache.has(chestCh.slice(2, chestCh.length - 1))) {return message.channel.send("That doesn't seem to be a channel! Try again?");} |
||||
if (chestCh.startsWith("<")) {chestCh = chestCh.slice(2, chestCh.length - 1);} |
||||
} |
||||
let c = new Chests({gid: message.guild.id, channel: chestCh}); |
||||
c.save(); |
||||
client.misc.cache.chests.push(message.guild.id); |
||||
return message.channel.send({embeds: [new Discord.MessageEmbed() |
||||
.setTitle("Chest Spawning Enabled!") |
||||
.setThumbnail(message.guild.iconURL({size: 2048})) |
||||
.setDescription(`Your server now has its chest spawning enabled! Chests will spawn in ${chestCh.length ? `<#${chestCh}>` : 'any channel'}.`) |
||||
.setColor("c375f0") |
||||
.setFooter({text: "Natsuki", iconURL: client.user.avatarURL()}) |
||||
.setTimestamp() |
||||
]}); |
||||
}); |
||||
rc.on("end", collected => {if (!collected.size) {return message.channel.send("Looks like you ran out of time! Try again?");}}); |
||||
} catch {return message.channel.send("Hmm... there was some error problem thingy that happened when I tried to enable chest spawning for your server. If it keeps not working, then go yell at my devs!");} |
||||
} |
||||
|
||||
else if (['d', 'disable'].includes(args[0].toLowerCase())) { |
||||
|
||||
} |
||||
|
||||
else if (['c', 'ch', 'setchannel', 'setch ', 'sc', 'sch', 'enable'].includes(args[0].toLowerCase())) { |
||||
|
||||
} |
||||
|
||||
else {return message.channel.send(`Invalid arg! Syntax: \`${prefix}chests [enable|disable|channel]\``);} |
||||
} |
||||
}; |
@ -0,0 +1,8 @@ |
||||
const mongoose = require('mongoose'); |
||||
|
||||
const Chests = new mongoose.Schema({ |
||||
gid: {type: String, unique: true}, |
||||
channel: {type: String, default: ''} |
||||
}); |
||||
|
||||
module.exports = mongoose.model('chests', Chests); |
@ -0,0 +1,9 @@ |
||||
const Chests = require('../../models/chests'); |
||||
|
||||
module.exports = async client => { |
||||
client.misc.cache.chests = []; |
||||
|
||||
for await (const chest of Chests.find()) { |
||||
client.misc.cache.chests.push(chest.gid); |
||||
} |
||||
}; |
@ -0,0 +1,80 @@ |
||||
const Monners = require('../../models/monners'); |
||||
const Chests = require('../../models/chests'); |
||||
const manyitems = require('manyitems'); |
||||
const Discord = require('discord.js'); |
||||
|
||||
module.exports = async (client, member, channel, prefix) => { |
||||
if (client.misc.cache.chestsTimeout.has(member.guild.id) && new Date().getTime() - client.misc.cache.chestsTimeout.get(member.guild.id) < (1000 * 60 * 2)) {return;} |
||||
//let rand = Math.floor(Math.random() * 100);
|
||||
//if (rand !== 69) {return;} //decide if it even continues
|
||||
|
||||
let tm = await Monners.findOne({uid: member.id}); |
||||
let streak = tm && tm.daily ? tm.daily.streak : 0; //get streak for bonus later
|
||||
|
||||
let rarities = [ //decide rarity
|
||||
{ |
||||
rarity: 100, |
||||
name: 'Common', |
||||
color: '586269', |
||||
amount: 40 |
||||
}, { |
||||
rarity: 40, |
||||
name: 'Uncommon', |
||||
color: '449e77', |
||||
amount: 120 |
||||
}, { |
||||
rarity: 20, |
||||
name: 'Rare', |
||||
color: '459dcc', |
||||
amount: 300 |
||||
}, { |
||||
rarity: 10, |
||||
name: 'Legendary', |
||||
color: '7951bd', |
||||
amount: 750 |
||||
}, { |
||||
rarity: 1, |
||||
name: 'Epic', |
||||
color: 'c7a756', |
||||
amount: 1250 |
||||
}, { |
||||
rarity: 0.02, |
||||
name: 'Godly', |
||||
color: 'fa25be', |
||||
amount: 20000 |
||||
} |
||||
]; |
||||
let rareNum = (Math.ceil(Math.random() * 10000)) / 100; |
||||
let rarity; |
||||
for (let i = 0; i < Object.keys(rarities).length; i++) { //loop that reassigns to a higher rarity until the rarity value is lower than its requirement
|
||||
if (rareNum < (100 - rarities[i].rarity)) {break;} |
||||
else {rarity = rarities[i];} |
||||
} |
||||
|
||||
let ri = new manyitems.Random("bubble", undefined, { |
||||
min: rarity.amount - (rarity.amount * .10), |
||||
max: rarity.amount + (rarity.amount * .10) + (rarity.amount * .10 * 1.25 * streak) |
||||
}); |
||||
let streakBonus = streak !== 0 ? Math.floor((Math.floor(Math.random() * (rarity.amount * .10)) * 1.5 * streak)) : 0; |
||||
let amount = ri.calc_bubble() + streakBonus; //calculate the amount by allowing a 10% +/- variance, higher potential with higher streak, and adding another random bonus with streak
|
||||
|
||||
let chests = await Chests.findOne({gid: member.guild.id}); |
||||
if (!chests) {return;} |
||||
let spawnChannel = chests.channel && chests.channel.length ? chests.channel : channel; |
||||
|
||||
client.misc.cache.chestsTimeout.set(member.guild.id, new Date().getTime()); |
||||
|
||||
let chestEmbed = new Discord.MessageEmbed() |
||||
.setTitle(`${client.utils.an(rarity.name, true)} Chest has spawned!`) |
||||
.setDescription(`It has **${amount} Monners<:monners:926736756047495218>**`) |
||||
.setFooter({text: `Type \`${prefix}claim\` to claim it!`}) |
||||
.setColor(rarity.color) //create the chest message
|
||||
|
||||
if (spawnChannel === channel) {return channel.send({embeds: [chestEmbed]}).catch(() => {});} |
||||
else { |
||||
member.guild.channels.fetch(spawnChannel) |
||||
.then(ch => ch.send({embeds: [chestEmbed]}).catch(() => {})) |
||||
.catch(() => {}) |
||||
} |
||||
return spawnChannel.send({embeds: [chestEmbed]}); //spawn the chest
|
||||
}; |
Loading…
Reference in new issue