chest claiming

master
Kit Kasune 3 years ago
parent 4365bbe479
commit 4a19bff4f0
  1. 7
      bot.js
  2. 4
      commands/leveling/chests.js
  3. 29
      commands/leveling/claim.js
  4. 2
      util/cache.js
  5. 4
      util/cache/chest.js
  6. 2
      util/cache/lxp.js
  7. 14
      util/lxp/spawnchest.js

@ -36,6 +36,11 @@ client.misc = {
}, },
chests: [], chests: [],
chestsTimeout: new Map(), chestsTimeout: new Map(),
chests: {
enabled: [],
timeout: new Map(),
waiting: new Map()
},
monit: {}, monit: {},
monitEnabled: [], monitEnabled: [],
inVC: [], inVC: [],
@ -128,7 +133,7 @@ async function init() {
client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');}; client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');};
client.utils.s = num => num === 1 ? '' : 's'; client.utils.s = num => num === 1 ? '' : 's';
client.utils.as = (num, text) => `${text}${client.utils.s(num)}`; client.utils.as = (num, text) => `${text}${client.utils.s(num)}`;
client.utils.an = (text, caps) => `${caps ? 'A' : 'a'}${['a', 'e', 'i', 'o'].includes(text.toLowerCase().trim().slice(0, 1)) ? 'n' : ''} ${text}`; client.utils.an = (text, caps) => `${caps ? 'A' : 'a'}${['a', 'e', 'i', 'o', 'u'].includes(text.toLowerCase().trim().slice(0, 1)) ? 'n' : ''} ${text}`;
client.guildconfig = {}; client.guildconfig = {};
client.guildconfig.prefixes = new Map(); client.guildconfig.prefixes = new Map();

@ -24,7 +24,7 @@ module.exports = {
if (!args.length) {args[0] = 'enable';} if (!args.length) {args[0] = 'enable';}
if (['e', 'enable'].includes(args[0].toLowerCase())) { 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.")}; if (client.misc.cache.chests.enabled.includes(message.guild.id)) {return message.channel.send("This server already has chest spawning enabled.")};
try { try {
am = await message.channel.send("Would you like to have me send chests to a specific channel?"); am = await message.channel.send("Would you like to have me send chests to a specific channel?");
await am.react('👍'); await am.react('👍');
@ -43,7 +43,7 @@ module.exports = {
} }
let c = new Chests({gid: message.guild.id, channel: chestCh}); let c = new Chests({gid: message.guild.id, channel: chestCh});
c.save(); c.save();
client.misc.cache.chests.push(message.guild.id); client.misc.cache.chests.enabled.push(message.guild.id);
return message.channel.send({embeds: [new Discord.MessageEmbed() return message.channel.send({embeds: [new Discord.MessageEmbed()
.setTitle("Chest Spawning Enabled!") .setTitle("Chest Spawning Enabled!")
.setThumbnail(message.guild.iconURL({size: 2048})) .setThumbnail(message.guild.iconURL({size: 2048}))

@ -0,0 +1,29 @@
const Discord = require('discord.js');
module.exports = {
name: "claim",
aliases: [],
meta: {
category: 'Leveling',
description: "Claim a chest that has spawned in the channel",
syntax: '`claim [specialText]`',
extra: null,
guildOnly: true
},
help: "Claim a chest that has spawned in the channel. You must be in the same channel as the chest in order to claim it.",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!client.misc.cache.chests.enabled.includes(message.guild.id)) {return message.channel.send("Chests aren't enabled in this server!");}
if (!client.misc.cache.chests.waiting.has(message.channel.id)) {return message.channel.send("There are no chests to claim in this channel.");}
if (!client.misc.cache.monners[message.author.id]) {return message.channel.send("There was an issue on my side with claiming your chest. This happened because I don't have your Monners info cached, so send a message anywhere and then try again. Sorry!");}
let chest = client.misc.cache.chests.waiting.get(message.channel.id);
client.misc.cache.monners[message.author.id] += chest.amount;
client.misc.cache.chests.waiting.delete(message.channel.id);
chest.message.delete().catch(() => {});
return message.channel.send({embeds: [new Discord.MessageEmbed()
.setAuthor({name: message.member.displayName, iconURL: message.member.displayAvatarURL()})
.setDescription(`You've claimed ${client.utils.an(chest.rarity.name, true)} Chest with **${chest.amount} Monners<:monners:926736756047495218>**`)
.setColor(chest.rarity.color)
]}).catch(() => {});
}
};

@ -42,5 +42,5 @@ module.exports = async (client) => {
let ora_ctCache = ora("Caching Chests...").start(); let ora_ctCache = ora("Caching Chests...").start();
await require('./cache/chest')(client); await require('./cache/chest')(client);
ora_ctCache.stop(); ora_ctCache.clear(); ora_ctCache.stop(); ora_ctCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chests.length}`)} ${chalk.blueBright("guilds that spawn chests.")}`); console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.chests.enabled.length}`)} ${chalk.blueBright("guilds that spawn chests.")}`);
}; };

@ -1,9 +1,9 @@
const Chests = require('../../models/chests'); const Chests = require('../../models/chests');
module.exports = async client => { module.exports = async client => {
client.misc.cache.chests = []; client.misc.cache.chests.enabled = [];
for await (const chest of Chests.find()) { for await (const chest of Chests.find()) {
client.misc.cache.chests.push(chest.gid); client.misc.cache.chests.enabled.push(chest.gid);
} }
}; };

2
util/cache/lxp.js vendored

@ -3,7 +3,7 @@ const LXP = require('../../models/localxp');
module.exports = async client => { module.exports = async client => {
client.misc.cache.lxp.enabled = []; client.misc.cache.lxp.enabled = [];
client.misc.cache.lxp.disabledChannels = new Map(); client.misc.cache.lxp.disabledChannels = new Map();
client.misc.cache.chests = new Map(); client.misc.cache.chests.enabled = new Map();
for await (const xp of LXP.find()) { for await (const xp of LXP.find()) {
client.misc.cache.lxp.enabled.push(xp.gid); client.misc.cache.lxp.enabled.push(xp.gid);

@ -4,7 +4,7 @@ const manyitems = require('manyitems');
const Discord = require('discord.js'); const Discord = require('discord.js');
module.exports = async (client, member, channel, prefix) => { 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;} if (client.misc.cache.chests.timeout.has(member.guild.id) && new Date().getTime() - client.misc.cache.chests.timeout.get(member.guild.id) < (1000 * 60 * 2)) {return;}
//let rand = Math.floor(Math.random() * 100); //let rand = Math.floor(Math.random() * 100);
//if (rand !== 69) {return;} //decide if it even continues //if (rand !== 69) {return;} //decide if it even continues
@ -62,7 +62,7 @@ module.exports = async (client, member, channel, prefix) => {
if (!chests) {return;} if (!chests) {return;}
let spawnChannel = chests.channel && chests.channel.length ? chests.channel : channel; let spawnChannel = chests.channel && chests.channel.length ? chests.channel : channel;
client.misc.cache.chestsTimeout.set(member.guild.id, new Date().getTime()); client.misc.cache.chests.timeout.set(member.guild.id, new Date().getTime());
let chestEmbed = new Discord.MessageEmbed() let chestEmbed = new Discord.MessageEmbed()
.setTitle(`${client.utils.an(rarity.name, true)} Chest has spawned!`) .setTitle(`${client.utils.an(rarity.name, true)} Chest has spawned!`)
@ -70,10 +70,16 @@ module.exports = async (client, member, channel, prefix) => {
.setFooter({text: `Type \`${prefix}claim\` to claim it!`}) .setFooter({text: `Type \`${prefix}claim\` to claim it!`})
.setColor(rarity.color) //create the chest message .setColor(rarity.color) //create the chest message
if (spawnChannel === channel) {return channel.send({embeds: [chestEmbed]}).catch(() => {});} if (spawnChannel === channel) {
return channel.send({embeds: [chestEmbed]})
.then(m => {client.misc.cache.chests.waiting.set(m.channel.id, {amount: amount, rarity: rarity, message: m});})
.catch(() => {});
}
else { else {
member.guild.channels.fetch(spawnChannel) member.guild.channels.fetch(spawnChannel)
.then(ch => ch.send({embeds: [chestEmbed]}).catch(() => {})) .then(ch => ch.send({embeds: [chestEmbed]})
.then(m => {client.misc.cache.chests.waiting.set(m.channel.id, {amount: amount, rarity: rarity, message: m});})
.catch(() => {}))
.catch(() => {}) .catch(() => {})
} }
return spawnChannel.send({embeds: [chestEmbed]}); //spawn the chest return spawnChannel.send({embeds: [chestEmbed]}); //spawn the chest

Loading…
Cancel
Save