yes
This commit is contained in:
@@ -0,0 +1,312 @@
|
||||
// cookies.js — rewritten & rebalanced
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
|
||||
const cookieSchema = require("../schemas/cookieSchema"); // expected to support findOne, findOneAndUpdate, updateOne, find
|
||||
const cooldownSchema = require("../schemas/cooldownSchema"); // expected to support findOne, findOneAndUpdate
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const URI = process.env.URI;
|
||||
if (!URI) throw new Error("Missing process.env.URI for MongoDB");
|
||||
|
||||
// single client reused
|
||||
const client = new MongoClient(URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
client.connect().catch(err => {
|
||||
console.error("Mongo connect error:", err);
|
||||
});
|
||||
|
||||
// util
|
||||
const msToTime = (duration) => {
|
||||
const ms = Math.floor((duration % 1000) / 100);
|
||||
const s = Math.floor((duration / 1000) % 60);
|
||||
const m = Math.floor((duration / (1000 * 60)) % 60);
|
||||
const h = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
const pad = n => (n < 10 ? "0" + n : "" + n);
|
||||
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
||||
};
|
||||
|
||||
const delay = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
// --- Helpers ---
|
||||
async function getCookies(userId) {
|
||||
const rec = await cookieSchema.findOne({ _id: userId });
|
||||
return rec && typeof rec.cookies === 'number' ? rec.cookies : 0;
|
||||
}
|
||||
|
||||
async function changeCookies(userId, delta, username = null) {
|
||||
// upsert and set username if provided
|
||||
const update = { $inc: { cookies: delta } };
|
||||
if (username) update.$set = { user: username };
|
||||
return cookieSchema.findOneAndUpdate(
|
||||
{ _id: userId },
|
||||
update,
|
||||
{ upsert: true, returnDocument: 'after' }
|
||||
);
|
||||
}
|
||||
|
||||
async function getCooldown(uniqueId) {
|
||||
const rec = await cooldownSchema.findOne({ _id: uniqueId });
|
||||
return rec && rec.cooldown ? rec.cooldown : 0;
|
||||
}
|
||||
|
||||
async function setCooldown(uniqueId, command, subcommand, msTimestamp) {
|
||||
await cooldownSchema.findOneAndUpdate(
|
||||
{ _id: uniqueId },
|
||||
{ _id: uniqueId, command, subcommand, cooldown: msTimestamp },
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
function cooldownId(guildId, userId, command, subcommand) {
|
||||
return `${guildId}-${userId}-${command}-${subcommand}`;
|
||||
}
|
||||
|
||||
// --- Game logic & rebalances ---
|
||||
// Notes about balancing:
|
||||
// - Collect: 1..20 cookies (consistent reward); Abra (special user id) gets 1.5x.
|
||||
// - Steal:
|
||||
// * successChance = attacker / (attacker + defender), clamped to [0.10, 0.90]
|
||||
// * steal amount: random 1..ceil(defender/4)
|
||||
// * failure penalty: attacker loses random 1..ceil(attacker/6) (transferred to defender)
|
||||
// - Cooldowns: collect = 1 hour, steal = 15 minutes
|
||||
|
||||
const ABRA_ID = "378135175059603457"; // kept from original for bonus
|
||||
|
||||
async function collect(interaction, user) {
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `The batch is still cooking, come back in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// set cooldown (1 hour)
|
||||
const cooldownUntil = now + 60 * 60 * 1000;
|
||||
await setCooldown(id, interaction.commandName, sub, cooldownUntil);
|
||||
|
||||
// balanced collect amount: 1..20
|
||||
let amount = Math.floor(Math.random() * 20) + 1;
|
||||
if (user.id === ABRA_ID) amount = Math.ceil(amount * 1.5);
|
||||
|
||||
// update DB
|
||||
await changeCookies(user.id, amount, user.username);
|
||||
|
||||
// playful responses (kept / adapted)
|
||||
const collectResponses = (amount, user) => {
|
||||
const s = amount === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`${user}, I made you **${amount}** ${s} 🍪`,
|
||||
`${user}, here's your **${amount}** ${s} 🍪 I ate the rest, sorry >.<`,
|
||||
`Only **${amount}** ${s} 🍪 for you today ${user}... Abra stole the rest :c`,
|
||||
`${user}, would you like a Glass of Milk with your **${amount}** ${s}? 🍪`,
|
||||
`**${amount}** ${s} 🍪 Careful, ${user}! They're still warm :3`,
|
||||
`**${amount}** ${s} 🍪 Best Batch yet!`,
|
||||
`**${amount}** ${s} 🍪 These, I bequeath unto thine own self upon this day. Thou must guard them safely.`,
|
||||
`${user}, your **${amount}** ${s} 🍪 are fresh out of the oven... try not to burn your tongue!`,
|
||||
`${user}, I bribed the Cookie Monster to spare these **${amount}** ${s} 🍪 just for you.`,
|
||||
`${user}, Santa came early! You got **${amount}** ${s} 🍪 (milk not included).`,
|
||||
`${user}, your **${amount}** ${s} 🍪 are artisanal, gluten-free, and slightly cursed.`,
|
||||
`A wild baker appeared! They hand you **${amount}** ${s} 🍪`,
|
||||
`${user}, Abra said these **${amount}** ${s} 🍪 are "totally not stolen"... 🤔`,
|
||||
`${user}, here’s your **${amount}** ${s} 🍪 — watch out, they may be booby-trapped.`
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
const responses = collectResponses(amount, user);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: responses[i] });
|
||||
|
||||
}
|
||||
|
||||
async function steal(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
if (!target) {
|
||||
return interaction.reply({ content: `Pick someone to steal from.`, ephemeral: true });
|
||||
}
|
||||
if (target.id === user.id) {
|
||||
return interaction.reply({
|
||||
content: `C'mon, don't embarrass yourself! We all know you couldn't do that, even if you tried.`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// pull balances
|
||||
const your = await getCookies(user.id);
|
||||
const their = await getCookies(target.id);
|
||||
|
||||
if (your <= 0) {
|
||||
return interaction.reply({ content: `You need at least 1 Cookie to attempt a Robbery`, ephemeral: true });
|
||||
}
|
||||
if (their <= 0) {
|
||||
return interaction.reply({ content: `Shame on you! ${target.username} doesn't have any Cookies D:`, ephemeral: true });
|
||||
}
|
||||
|
||||
// steal cooldown (15 minutes)
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
const chaos = true // 50% Stela Chance Mode
|
||||
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `Hold up — try stealing again in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
await setCooldown(id, interaction.commandName, sub, now + 15 * 60 * 1000);
|
||||
|
||||
// success chance and clamping
|
||||
let successChance = your / (your + their);
|
||||
if (isNaN(successChance) || !isFinite(successChance)) successChance = 0.2;
|
||||
if (chaos) {
|
||||
successChance = 0.5
|
||||
} else {
|
||||
successChance = Math.max(0.10, Math.min(0.90, successChance));
|
||||
}
|
||||
const success = Math.random() < successChance;
|
||||
|
||||
if (success) {
|
||||
const stealSuccessResponses = (amount, target) => {
|
||||
const s = amount === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`You've successfully stolen **${amount}** ${s} from **${target.username}**!`,
|
||||
`Ninja mode: activated. You snatched **${amount}** ${s} from **${target.username}** without a crumb left behind.`,
|
||||
`Abra taught you well — **${amount}** ${s} from **${target.username}** are now yours!`,
|
||||
`Like a phantom in the night, you took **${amount}** ${s} from **${target.username}**.`,
|
||||
`You just pulled the sweetest heist: **${amount}** ${s} from **${target.username}**!`,
|
||||
`Mission complete. **${target.username}** is **${amount}** ${s} poorer, you are richer.`,
|
||||
`You distracted **${target.username}** with a dance and swiped **${amount}** ${s}.`,
|
||||
`Clean getaway! **${target.username}** won’t know about the missing **${amount}** ${s} until it’s too late.`,
|
||||
`The Cookie Vault has been breached. **${amount}** ${s} taken from **${target.username}**.`,
|
||||
`You emerged from the shadows with **${amount}** ${s} from **${target.username}**.`
|
||||
];
|
||||
};
|
||||
|
||||
const maxSteal = Math.max(1, Math.ceil(their / 4)); // steal up to ~25% of victim
|
||||
let amount = Math.floor(Math.random() * maxSteal) + 1;
|
||||
amount = Math.min(amount, their);
|
||||
|
||||
// transfer
|
||||
await Promise.all([
|
||||
changeCookies(user.id, amount, user.username),
|
||||
changeCookies(target.id, -amount, target.username)
|
||||
]);
|
||||
|
||||
const responses = stealSuccessResponses(amount, target);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: `${responses[i]} (Chance: ${Math.round(successChance * 100, 2)}%)` });
|
||||
|
||||
} else {
|
||||
const stealFailResponses = (penalty, target) => {
|
||||
const s = penalty === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`You were caught red-handed by **${target.username}** and lost **${penalty}** ${s} as a penalty!`,
|
||||
`Fail! **${target.username}** caught you mid-bite — you dropped **${penalty}** ${s}.`,
|
||||
`Not your best moment... You lost **${penalty}** ${s} to **${target.username}** in the struggle.`,
|
||||
`Stealth level: 0. You handed **${penalty}** ${s} to **${target.username}** as an apology.`,
|
||||
`The cookie jar was booby-trapped! You gave **${penalty}** ${s} to **${target.username}** while running away.`,
|
||||
`Ouch. The guard dog barked, and now **${target.username}** has your **${penalty}** ${s}.`,
|
||||
`You tripped over your own shoelace — **${target.username}** reclaimed **${penalty}** ${s}.`,
|
||||
`Caught by the Cookie Police! **${penalty}** ${s} confiscated and given to **${target.username}**.`,
|
||||
`Your pockets had holes... **${target.username}** picked up **${penalty}** ${s} you dropped.`
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
// failure penalty: attacker loses a little (1..ceil(your/6)) to the victim
|
||||
const maxPenalty = Math.max(1, Math.ceil(your / 6));
|
||||
const penalty = Math.min(your, Math.floor(Math.random() * maxPenalty) + 1);
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -penalty, user.username),
|
||||
changeCookies(target.id, +penalty, target.username)
|
||||
]);
|
||||
|
||||
const responses = stealFailResponses(penalty, target);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: `${responses[i]} (Chance: ${Math.round(successChance * 100, 2)}%)` });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function check(interaction, user) {
|
||||
let target = interaction.options.getUser('target');
|
||||
if (!target) target = user;
|
||||
|
||||
const cookies = await getCookies(target.id);
|
||||
const mood = cookies === 0 ? '😔' : '😲';
|
||||
return interaction.reply({ content: `**${target.username}** has **${cookies}** Cookies! ${mood}` });
|
||||
}
|
||||
|
||||
async function give(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (!target) return interaction.reply({ content: `You need to specify a target.`, ephemeral: true });
|
||||
if (target.id === user.id) return interaction.reply({ content: 'You cannot give yourself Cookies ._."', ephemeral: true });
|
||||
if (!Number.isInteger(amount) || amount < 1) {
|
||||
return interaction.reply({ content: `**${user}** shared *checks notes* **${amount}** Cookie(s) with ${target}....wait a minute!!`, ephemeral: true });
|
||||
}
|
||||
|
||||
const your = await getCookies(user.id);
|
||||
if (your < amount) return interaction.reply({ content: `We don't run a charity here, get more Cookies!`, ephemeral: true });
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -amount, user.username),
|
||||
changeCookies(target.id, +amount, target.username)
|
||||
]);
|
||||
|
||||
// small delay to mimic previous behavior
|
||||
await delay(200);
|
||||
return interaction.reply({ content: `**${user}** shared **${amount}** Cookie(s) with ${target}` });
|
||||
}
|
||||
|
||||
async function leader(interaction) {
|
||||
const results = await cookieSchema.find().sort({ cookies: -1 }).limit(10);
|
||||
let cookieSorted = '';
|
||||
results.forEach((r, i) => {
|
||||
cookieSorted += `[${i + 1}] <@${r._id}> (${r.cookies})\n`;
|
||||
});
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setColor(0x0099FF)
|
||||
.setThumbnail(interaction.guild.iconURL())
|
||||
.setTimestamp()
|
||||
.addFields({ name: `-Cookie Leaderboard-`, value: cookieSorted || 'No cookie data yet.' });
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'collect a cookie',
|
||||
category: 'Misc',
|
||||
options: [
|
||||
{ name: "collect", description: "want some?", type: 1 },
|
||||
{ name: "steal", description: "try your luck at a lala robbery!", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }] },
|
||||
{ name: "check", description: "check your cookie stash", type: 1, options: [{ name: "target", description: "someone", type: 6 }] },
|
||||
{ name: "give", description: "share your cookies with someone", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }, { name: "amount", description: "cookies", required: true, type: 4 }] },
|
||||
{ name: "leader", description: "show Top 10 Cookie Clickers", type: 1 }
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
const sub = interaction.options._subcommand;
|
||||
switch (sub) {
|
||||
case "collect": return collect(interaction, user);
|
||||
case "steal": return steal(interaction, user);
|
||||
case "check": return check(interaction, user);
|
||||
case "give": return give(interaction, user);
|
||||
case "leader": return leader(interaction);
|
||||
default: return interaction.reply({ content: 'Unknown subcommand', ephemeral: true });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,448 @@
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
const uri = process.env.URI
|
||||
const cookieSchema = require("../schemas/cookieSchema")
|
||||
const cooldownSchema = require("../schemas/cooldownSchema")
|
||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
const Discord = require('discord.js')
|
||||
const client = new MongoClient(uri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
function msToTime(duration) {
|
||||
var milliseconds = parseInt((duration % 1000) / 100),
|
||||
seconds = Math.floor((duration / 1000) % 60),
|
||||
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
||||
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
|
||||
hours = (hours < 10) ? "0" + hours : hours;
|
||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
async function collect(interaction, user) {
|
||||
client.connect(async (err, db) => {
|
||||
var dbo = db.db('test')
|
||||
let id = `${interaction.guildId}-${interaction.user.id}-${interaction.commandName}-${interaction.options._subcommand}`
|
||||
dbo.collection('cooldowns').findOne({
|
||||
_id: id
|
||||
}, async function (err, results) {
|
||||
let now = Date.now()
|
||||
let time = now + 3600000 // plus one hour in ms
|
||||
if (results) {
|
||||
if (results.cooldown > now) {
|
||||
time = new Date(results.cooldown).toUTCString()
|
||||
return interaction.reply({
|
||||
content: `The batch is still cooking, come back in **${msToTime(results.cooldown - now)}**`,
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
}
|
||||
addCooldown(interaction.user.id, interaction.guildId, interaction.commandName, interaction.options._subcommand, time)
|
||||
|
||||
|
||||
var amount = Math.floor(Math.random() * 30)
|
||||
//random amount between 1 and 29
|
||||
if (user.id == "378135175059603457") {
|
||||
//Abra Bonus
|
||||
amount = Math.ceil(amount * 1.5)
|
||||
}
|
||||
|
||||
var responses = [
|
||||
`${user}, I made you **${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 `,
|
||||
`${user}, Here's your **${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 I ate the rest, sorry >.<`,
|
||||
`Only **${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 for you today ${user}... Abra stole the rest :c`,
|
||||
`${user}, would you like a Glass of Milk with your **${amount}** ${amount == 1?`Cookie`: `Cookies`}? 🍪 `,
|
||||
`**${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 Careful, ${user}! They're still warm :3`,
|
||||
`**${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 Best Batch yet!`,
|
||||
`**${amount}** ${amount == 1?`Cookie`: `Cookies`} 🍪 These, I bequeath unto thine own self upon this day. Thou must guard them safely.`,
|
||||
]
|
||||
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: +amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
if(amount === 0){
|
||||
interaction.reply({
|
||||
content: `${user}, someone ate all your Cookies already D:`
|
||||
})
|
||||
} else {
|
||||
var i = Math.floor(Math.random() * responses.length)
|
||||
interaction.reply({
|
||||
content: responses[i]
|
||||
})
|
||||
}
|
||||
// choose response
|
||||
})
|
||||
})
|
||||
}
|
||||
/*
|
||||
function steal(interaction, user) {
|
||||
client.connect(async (err, db) => {
|
||||
if (err) throw err;
|
||||
let target = interaction.options.getUser('target')
|
||||
let dbo = db.db("test")
|
||||
|
||||
if (target.id == user.id) {
|
||||
return interaction.reply({
|
||||
content: `C'mon, don't embarass yourself! We all know you couldn't do that, even if you tried.`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
|
||||
// get your amount of cookies
|
||||
let your = await dbo.collection('cookies').findOne({
|
||||
_id: user.id
|
||||
})
|
||||
// get their amount of cookies
|
||||
let their = await dbo.collection('cookies').findOne({
|
||||
_id: target.id
|
||||
})
|
||||
try {
|
||||
if (!your.cookies) {
|
||||
return interaction.reply({
|
||||
content: `You need at least 1 Cookie to attempt a Robbery`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
if (!their.cookies) {
|
||||
return interaction.reply({
|
||||
content: `Shame on you! They don't even have any Cookies D:`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
return interaction.reply({
|
||||
content: `How awkward...I don't know some of you!`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
let difficulty = []
|
||||
for (var i = 0; i < their.cookies; i++) {
|
||||
if (i < your.cookies) {
|
||||
difficulty.push(true)
|
||||
} else {
|
||||
difficulty.push(false)
|
||||
}
|
||||
}
|
||||
let result = Math.floor(Math.random() * their.cookies) + 1
|
||||
let response
|
||||
if (!difficulty[result]) {
|
||||
// author lost
|
||||
response = `You were unsuccessful at robbing **${target.username}** and lost your chance at **${result}** ${result == 1?`Cookie`: `Cookies`}! `
|
||||
if (your.cookies - result <= 0) {
|
||||
result = your.cookies
|
||||
response += `That's all your Cookies gone.`
|
||||
}
|
||||
result *= -1
|
||||
|
||||
} else {
|
||||
//author won
|
||||
response = `You've successfully stolen **${result<their.cookies?result:their.cookies}** ${result == 1?`Cookie`: `Cookies`} from **${target.username}**! `
|
||||
if (their.cookies - result <= 0) {
|
||||
result = their.cookies
|
||||
response += `They're completely dry now.`
|
||||
}
|
||||
}
|
||||
interaction.reply({
|
||||
content: response
|
||||
})
|
||||
|
||||
//update author's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: +result } //will decrease if it's +negativeInteger
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: target.id
|
||||
}, {
|
||||
_id: target.id,
|
||||
user: target.username,
|
||||
$inc: { cookies: -result } //will decrease if it's +negativeInteger
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
async function steal(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
|
||||
if (!target || target.id === user.id) {
|
||||
return interaction.reply({
|
||||
content: `You can't steal from yourself!`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
const dbo = client.db("test");
|
||||
|
||||
const [yourCookies, theirCookies] = await Promise.all([
|
||||
dbo.collection('cookies').findOne({ _id: user.id }) || { cookies: 0 },
|
||||
dbo.collection('cookies').findOne({ _id: target.id }) || { cookies: 0 }
|
||||
]);
|
||||
|
||||
if (yourCookies.cookies <= 0) {
|
||||
return interaction.reply({
|
||||
content: `You need at least 1 cookie to attempt a robbery.`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
if (theirCookies.cookies <= 0) {
|
||||
return interaction.reply({
|
||||
content: `${target.username} has no cookies to steal!`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// Fair success chance: attackerCookies / (attackerCookies + defenderCookies)
|
||||
const successChance = yourCookies.cookies / (yourCookies.cookies + theirCookies.cookies);
|
||||
const success = Math.random() < successChance;
|
||||
|
||||
// Random steal amount between 1 and 1/3 of victim's cookies
|
||||
const maxSteal = Math.max(1, Math.floor(theirCookies.cookies / 3));
|
||||
let stealAmount = Math.floor(Math.random() * maxSteal) + 1;
|
||||
|
||||
let message;
|
||||
if (success) {
|
||||
stealAmount = Math.min(stealAmount, theirCookies.cookies);
|
||||
await Promise.all([
|
||||
cookieSchema.updateOne({ _id: user.id }, { $inc: { cookies: stealAmount }, $set: { user: user.username } }, { upsert: true }),
|
||||
cookieSchema.updateOne({ _id: target.id }, { $inc: { cookies: -stealAmount }, $set: { user: target.username } }, { upsert: true })
|
||||
]);
|
||||
message = `You successfully stole **${stealAmount}** 🍪 from **${target.username}**!`;
|
||||
} else {
|
||||
// Penalty: lose up to half of attempted amount
|
||||
stealAmount = Math.min(stealAmount, yourCookies.cookies);
|
||||
await Promise.all([
|
||||
cookieSchema.updateOne({ _id: user.id }, { $inc: { cookies: -stealAmount }, $set: { user: user.username } }, { upsert: true }),
|
||||
cookieSchema.updateOne({ _id: target.id }, { $inc: { cookies: stealAmount }, $set: { user: target.username } }, { upsert: true })
|
||||
]);
|
||||
message = `You failed to steal from **${target.username}** and lost **${stealAmount}** 🍪 as punishment!`;
|
||||
}
|
||||
|
||||
return interaction.reply({ content: message });
|
||||
}
|
||||
|
||||
function check(interaction, user) {
|
||||
|
||||
client.connect(async function (err, db) {
|
||||
let target = interaction.options.getUser('target')
|
||||
|
||||
if (!target) {
|
||||
target = user
|
||||
}
|
||||
let response = `**${target.username}** has `
|
||||
let dbo = db.db("test")
|
||||
dbo.collection("cookies").findOne({
|
||||
_id: target.id
|
||||
}, function (err, results) {
|
||||
let cookies
|
||||
if (!results) {
|
||||
cookies = 0
|
||||
response += `**${cookies}** Cookies! 😔`
|
||||
} else {
|
||||
cookies = results.cookies
|
||||
response += `**${cookies}** Cookies! 😲`
|
||||
}
|
||||
interaction.reply({
|
||||
content: response
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
async function give(interaction, user) {
|
||||
client.connect(async function (err, db) {
|
||||
let target = interaction.options.getUser('target')
|
||||
let amount = interaction.options.getInteger('amount')
|
||||
let dbo = db.db('test')
|
||||
|
||||
//check if you have enough cookies
|
||||
let your = await dbo.collection('cookies').findOne({
|
||||
_id: user.id
|
||||
})
|
||||
|
||||
if (target.id == user.id) {
|
||||
return interaction.reply({
|
||||
content: 'You cannot give yourself Cookies ._."'
|
||||
})
|
||||
}
|
||||
if (your.cookies < amount) {
|
||||
return interaction.reply({
|
||||
content: `We don't run a charity here, get more Cookies!`
|
||||
})
|
||||
}
|
||||
if (amount < 1) {
|
||||
return interaction.reply({
|
||||
content: `**${user}** shared *checks notes* **${amount}** Cookie(s) with ${target}....wait a minute!!`,
|
||||
})
|
||||
}
|
||||
|
||||
//update user's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: -amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
//update target's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: target.id
|
||||
}, {
|
||||
_id: target.id,
|
||||
user: target.username,
|
||||
$inc: { cookies: +amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
await delay(200)
|
||||
interaction.reply({
|
||||
content: `**${user}** shared **${amount}** Cookie(s) with ${target}`
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
async function addCooldown(userId, guildId, command, subcommand, ms) {
|
||||
let id = `${guildId}-${userId}-${command}-${subcommand}`
|
||||
await cooldownSchema.findOneAndUpdate({
|
||||
_id: id
|
||||
}, {
|
||||
_id: id,
|
||||
command: command,
|
||||
subcommand: subcommand,
|
||||
cooldown: ms
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
}
|
||||
async function leader(interaction) {
|
||||
const results = await cookieSchema.find().sort({
|
||||
cookies: -1
|
||||
}).limit(10)
|
||||
let cookieSorted = ''
|
||||
let i = 0
|
||||
results.forEach((result) => {
|
||||
cookieSorted += `[${i + 1}] <@${result._id}> (${result.cookies})\n`
|
||||
i++;
|
||||
})
|
||||
|
||||
var embed = new Discord.MessageEmbed()
|
||||
.setColor(0x0099FF)
|
||||
.setThumbnail(interaction.guild.iconURL())
|
||||
.setTimestamp()
|
||||
.addFields({ name: `-Cookie Leaderboard-`, value: cookieSorted })
|
||||
|
||||
interaction.reply({
|
||||
embeds: [embed]
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'collect a cookie',
|
||||
category: 'Misc',
|
||||
options: [
|
||||
//collect
|
||||
{
|
||||
name: "collect",
|
||||
description: "want some?",
|
||||
type: 1 // SubCommand Type
|
||||
},
|
||||
//steal
|
||||
{
|
||||
name: "steal",
|
||||
description: "try your luck at a lala robbery!",
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
required: true,
|
||||
type: 6 // User Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//check
|
||||
{
|
||||
name: "check",
|
||||
description: "check your cookie stash",
|
||||
required: false,
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
type: 6 // User Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//give
|
||||
{
|
||||
name: "give",
|
||||
description: "share your cookies with someone",
|
||||
required: false,
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
required: true,
|
||||
type: 6 // User Type
|
||||
}, {
|
||||
name: "amount",
|
||||
description: "cookies",
|
||||
required: true,
|
||||
type: 4 // Integer Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//leader
|
||||
{
|
||||
name: "leader",
|
||||
description: "show Top 10 Cookie Clickers",
|
||||
type: 1, // SubCommand Type
|
||||
},
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
switch (interaction.options._subcommand) {
|
||||
case "collect":
|
||||
collect(interaction, user)
|
||||
break;
|
||||
case "steal":
|
||||
steal(interaction, user)
|
||||
break;
|
||||
case "check":
|
||||
check(interaction, user)
|
||||
break;
|
||||
case "give":
|
||||
give(interaction, user)
|
||||
break;
|
||||
case "leader":
|
||||
leader(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
// cookies.js — rewritten & rebalanced
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
|
||||
const cookieSchema = require("../schemas/cookieSchema"); // expected to support findOne, findOneAndUpdate, updateOne, find
|
||||
const cooldownSchema = require("../schemas/cooldownSchema"); // expected to support findOne, findOneAndUpdate
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const URI = process.env.URI;
|
||||
if (!URI) throw new Error("Missing process.env.URI for MongoDB");
|
||||
|
||||
// single client reused
|
||||
const client = new MongoClient(URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
client.connect().catch(err => {
|
||||
console.error("Mongo connect error:", err);
|
||||
});
|
||||
|
||||
// util
|
||||
const msToTime = (duration) => {
|
||||
const ms = Math.floor((duration % 1000) / 100);
|
||||
const s = Math.floor((duration / 1000) % 60);
|
||||
const m = Math.floor((duration / (1000 * 60)) % 60);
|
||||
const h = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
const pad = n => (n < 10 ? "0" + n : "" + n);
|
||||
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
||||
};
|
||||
|
||||
const delay = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
// --- Helpers ---
|
||||
async function getCookies(userId) {
|
||||
const rec = await cookieSchema.findOne({ _id: userId });
|
||||
return rec && typeof rec.cookies === 'number' ? rec.cookies : 0;
|
||||
}
|
||||
|
||||
async function changeCookies(userId, delta, username = null) {
|
||||
// upsert and set username if provided
|
||||
const update = { $inc: { cookies: delta } };
|
||||
if (username) update.$set = { user: username };
|
||||
return cookieSchema.findOneAndUpdate(
|
||||
{ _id: userId },
|
||||
update,
|
||||
{ upsert: true, returnDocument: 'after' }
|
||||
);
|
||||
}
|
||||
|
||||
async function getCooldown(uniqueId) {
|
||||
const rec = await cooldownSchema.findOne({ _id: uniqueId });
|
||||
return rec && rec.cooldown ? rec.cooldown : 0;
|
||||
}
|
||||
|
||||
async function setCooldown(uniqueId, command, subcommand, msTimestamp) {
|
||||
await cooldownSchema.findOneAndUpdate(
|
||||
{ _id: uniqueId },
|
||||
{ _id: uniqueId, command, subcommand, cooldown: msTimestamp },
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
function cooldownId(guildId, userId, command, subcommand) {
|
||||
return `${guildId}-${userId}-${command}-${subcommand}`;
|
||||
}
|
||||
|
||||
// --- Game logic & rebalances ---
|
||||
// Notes about balancing:
|
||||
// - Collect: 1..20 cookies (consistent reward); Abra (special user id) gets 1.5x.
|
||||
// - Steal:
|
||||
// * successChance = attacker / (attacker + defender), clamped to [0.10, 0.90]
|
||||
// * steal amount: random 1..ceil(defender/4)
|
||||
// * failure penalty: attacker loses random 1..ceil(attacker/6) (transferred to defender)
|
||||
// - Cooldowns: collect = 1 hour, steal = 15 minutes
|
||||
|
||||
const ABRA_ID = "378135175059603457"; // kept from original for bonus
|
||||
|
||||
async function collect(interaction, user) {
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `The batch is still cooking, come back in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// set cooldown (1 hour)
|
||||
const cooldownUntil = now + 60 * 60 * 1000;
|
||||
await setCooldown(id, interaction.commandName, sub, cooldownUntil);
|
||||
|
||||
// balanced collect amount: 1..20
|
||||
let amount = Math.floor(Math.random() * 20) + 1;
|
||||
if (user.id === ABRA_ID) amount = Math.ceil(amount * 1.5);
|
||||
|
||||
// update DB
|
||||
await changeCookies(user.id, amount, user.username);
|
||||
|
||||
// playful responses (kept / adapted)
|
||||
const responses = [
|
||||
`${user}, I made you **${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪`,
|
||||
`${user}, here's your **${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪 I ate the rest, sorry >.<`,
|
||||
`Only **${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪 for you today ${user}... Abra stole the rest :c`,
|
||||
`${user}, would you like a Glass of Milk with your **${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'}? 🍪`,
|
||||
`**${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪 Careful, ${user}! They're still warm :3`,
|
||||
`**${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪 Best Batch yet!`,
|
||||
`**${amount}** ${amount === 1 ? 'Cookie' : 'Cookies'} 🍪 These, I bequeath unto thine own self upon this day. Thou must guard them safely.`
|
||||
];
|
||||
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: responses[i] });
|
||||
}
|
||||
|
||||
async function steal(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
if (!target) {
|
||||
return interaction.reply({ content: `Pick someone to steal from.`, ephemeral: true });
|
||||
}
|
||||
if (target.id === user.id) {
|
||||
return interaction.reply({
|
||||
content: `C'mon, don't embarrass yourself! We all know you couldn't do that, even if you tried.`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// steal cooldown (15 minutes)
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `Hold up — try stealing again in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
await setCooldown(id, interaction.commandName, sub, now + 15 * 60 * 1000);
|
||||
|
||||
// pull balances
|
||||
const your = await getCookies(user.id);
|
||||
const their = await getCookies(target.id);
|
||||
|
||||
if (your <= 0) {
|
||||
return interaction.reply({ content: `You need at least 1 Cookie to attempt a Robbery`, ephemeral: true });
|
||||
}
|
||||
if (their <= 0) {
|
||||
return interaction.reply({ content: `Shame on you! ${target.username} doesn't have any Cookies D:`, ephemeral: true });
|
||||
}
|
||||
|
||||
// success chance and clamping
|
||||
let successChance = your / (your + their);
|
||||
if (isNaN(successChance) || !isFinite(successChance)) successChance = 0.2;
|
||||
successChance = Math.max(0.50, Math.min(0.90, successChance)); // made it 50% for chaos
|
||||
|
||||
const success = Math.random() < successChance;
|
||||
|
||||
if (success) {
|
||||
const maxSteal = Math.max(1, Math.ceil(their / 4)); // steal up to ~25% of victim
|
||||
let amount = Math.floor(Math.random() * maxSteal) + 1;
|
||||
amount = Math.min(amount, their);
|
||||
|
||||
// transfer
|
||||
await Promise.all([
|
||||
changeCookies(user.id, amount, user.username),
|
||||
changeCookies(target.id, -amount, target.username)
|
||||
]);
|
||||
|
||||
const s = amount === 1 ? 'Cookie' : 'Cookies';
|
||||
return interaction.reply({
|
||||
content: `You've successfully stolen **${amount}** ${s} from **${target.username}**!`
|
||||
});
|
||||
} else {
|
||||
// failure penalty: attacker loses a little (1..ceil(your/6)) to the victim
|
||||
const maxPenalty = Math.max(1, Math.ceil(your / 6));
|
||||
const penalty = Math.min(your, Math.floor(Math.random() * maxPenalty) + 1);
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -penalty, user.username),
|
||||
changeCookies(target.id, +penalty, target.username)
|
||||
]);
|
||||
|
||||
const s = penalty === 1 ? 'Cookie' : 'Cookies';
|
||||
return interaction.reply({
|
||||
content: `You were unsuccessful at robbing **${target.username}** and lost **${penalty}** ${s} as a penalty!`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function check(interaction, user) {
|
||||
let target = interaction.options.getUser('target');
|
||||
if (!target) target = user;
|
||||
|
||||
const cookies = await getCookies(target.id);
|
||||
const mood = cookies === 0 ? '😔' : '😲';
|
||||
return interaction.reply({ content: `**${target.username}** has **${cookies}** Cookies! ${mood}` });
|
||||
}
|
||||
|
||||
async function give(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (!target) return interaction.reply({ content: `You need to specify a target.`, ephemeral: true });
|
||||
if (target.id === user.id) return interaction.reply({ content: 'You cannot give yourself Cookies ._."', ephemeral: true });
|
||||
if (!Number.isInteger(amount) || amount < 1) {
|
||||
return interaction.reply({ content: `**${user}** shared *checks notes* **${amount}** Cookie(s) with ${target}....wait a minute!!`, ephemeral: true });
|
||||
}
|
||||
|
||||
const your = await getCookies(user.id);
|
||||
if (your < amount) return interaction.reply({ content: `We don't run a charity here, get more Cookies!`, ephemeral: true });
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -amount, user.username),
|
||||
changeCookies(target.id, +amount, target.username)
|
||||
]);
|
||||
|
||||
// small delay to mimic previous behavior
|
||||
await delay(200);
|
||||
return interaction.reply({ content: `**${user}** shared **${amount}** Cookie(s) with ${target}` });
|
||||
}
|
||||
|
||||
async function leader(interaction) {
|
||||
const results = await cookieSchema.find().sort({ cookies: -1 }).limit(10);
|
||||
let cookieSorted = '';
|
||||
results.forEach((r, i) => {
|
||||
cookieSorted += `[${i + 1}] <@${r._id}> (${r.cookies})\n`;
|
||||
});
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setColor(0x0099FF)
|
||||
.setThumbnail(interaction.guild.iconURL())
|
||||
.setTimestamp()
|
||||
.addFields({ name: `-Cookie Leaderboard-`, value: cookieSorted || 'No cookie data yet.' });
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'collect a cookie',
|
||||
category: 'Misc',
|
||||
options: [
|
||||
{ name: "collect", description: "want some?", type: 1 },
|
||||
{ name: "steal", description: "try your luck at a lala robbery!", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }] },
|
||||
{ name: "check", description: "check your cookie stash", type: 1, options: [{ name: "target", description: "someone", type: 6 }] },
|
||||
{ name: "give", description: "share your cookies with someone", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }, { name: "amount", description: "cookies", required: true, type: 4 }] },
|
||||
{ name: "leader", description: "show Top 10 Cookie Clickers", type: 1 }
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
const sub = interaction.options._subcommand;
|
||||
switch (sub) {
|
||||
case "collect": return collect(interaction, user);
|
||||
case "steal": return steal(interaction, user);
|
||||
case "check": return check(interaction, user);
|
||||
case "give": return give(interaction, user);
|
||||
case "leader": return leader(interaction);
|
||||
default: return interaction.reply({ content: 'Unknown subcommand', ephemeral: true });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,307 @@
|
||||
// cookies.js — rewritten & rebalanced
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
|
||||
const cookieSchema = require("../schemas/cookieSchema"); // expected to support findOne, findOneAndUpdate, updateOne, find
|
||||
const cooldownSchema = require("../schemas/cooldownSchema"); // expected to support findOne, findOneAndUpdate
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const URI = process.env.URI;
|
||||
if (!URI) throw new Error("Missing process.env.URI for MongoDB");
|
||||
|
||||
// single client reused
|
||||
const client = new MongoClient(URI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
client.connect().catch(err => {
|
||||
console.error("Mongo connect error:", err);
|
||||
});
|
||||
|
||||
// util
|
||||
const msToTime = (duration) => {
|
||||
const ms = Math.floor((duration % 1000) / 100);
|
||||
const s = Math.floor((duration / 1000) % 60);
|
||||
const m = Math.floor((duration / (1000 * 60)) % 60);
|
||||
const h = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
const pad = n => (n < 10 ? "0" + n : "" + n);
|
||||
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
||||
};
|
||||
|
||||
const delay = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
// --- Helpers ---
|
||||
async function getCookies(userId) {
|
||||
const rec = await cookieSchema.findOne({ _id: userId });
|
||||
return rec && typeof rec.cookies === 'number' ? rec.cookies : 0;
|
||||
}
|
||||
|
||||
async function changeCookies(userId, delta, username = null) {
|
||||
// upsert and set username if provided
|
||||
const update = { $inc: { cookies: delta } };
|
||||
if (username) update.$set = { user: username };
|
||||
return cookieSchema.findOneAndUpdate(
|
||||
{ _id: userId },
|
||||
update,
|
||||
{ upsert: true, returnDocument: 'after' }
|
||||
);
|
||||
}
|
||||
|
||||
async function getCooldown(uniqueId) {
|
||||
const rec = await cooldownSchema.findOne({ _id: uniqueId });
|
||||
return rec && rec.cooldown ? rec.cooldown : 0;
|
||||
}
|
||||
|
||||
async function setCooldown(uniqueId, command, subcommand, msTimestamp) {
|
||||
await cooldownSchema.findOneAndUpdate(
|
||||
{ _id: uniqueId },
|
||||
{ _id: uniqueId, command, subcommand, cooldown: msTimestamp },
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
function cooldownId(guildId, userId, command, subcommand) {
|
||||
return `${guildId}-${userId}-${command}-${subcommand}`;
|
||||
}
|
||||
|
||||
// --- Game logic & rebalances ---
|
||||
// Notes about balancing:
|
||||
// - Collect: 1..20 cookies (consistent reward); Abra (special user id) gets 1.5x.
|
||||
// - Steal:
|
||||
// * successChance = attacker / (attacker + defender), clamped to [0.10, 0.90]
|
||||
// * steal amount: random 1..ceil(defender/4)
|
||||
// * failure penalty: attacker loses random 1..ceil(attacker/6) (transferred to defender)
|
||||
// - Cooldowns: collect = 1 hour, steal = 15 minutes
|
||||
|
||||
const ABRA_ID = "378135175059603457"; // kept from original for bonus
|
||||
|
||||
async function collect(interaction, user) {
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `The batch is still cooking, come back in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// set cooldown (1 hour)
|
||||
const cooldownUntil = now + 60 * 60 * 1000;
|
||||
await setCooldown(id, interaction.commandName, sub, cooldownUntil);
|
||||
|
||||
// balanced collect amount: 1..20
|
||||
let amount = Math.floor(Math.random() * 20) + 1;
|
||||
if (user.id === ABRA_ID) amount = Math.ceil(amount * 1.5);
|
||||
|
||||
// update DB
|
||||
await changeCookies(user.id, amount, user.username);
|
||||
|
||||
// playful responses (kept / adapted)
|
||||
const collectResponses = (amount, user) => {
|
||||
const s = amount === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`${user}, I made you **${amount}** ${s} 🍪`,
|
||||
`${user}, here's your **${amount}** ${s} 🍪 I ate the rest, sorry >.<`,
|
||||
`Only **${amount}** ${s} 🍪 for you today ${user}... Abra stole the rest :c`,
|
||||
`${user}, would you like a Glass of Milk with your **${amount}** ${s}? 🍪`,
|
||||
`**${amount}** ${s} 🍪 Careful, ${user}! They're still warm :3`,
|
||||
`**${amount}** ${s} 🍪 Best Batch yet!`,
|
||||
`**${amount}** ${s} 🍪 These, I bequeath unto thine own self upon this day. Thou must guard them safely.`,
|
||||
`${user}, your **${amount}** ${s} 🍪 are fresh out of the oven... try not to burn your tongue!`,
|
||||
`${user}, I bribed the Cookie Monster to spare these **${amount}** ${s} 🍪 just for you.`,
|
||||
`${user}, Santa came early! You got **${amount}** ${s} 🍪 (milk not included).`,
|
||||
`${user}, your **${amount}** ${s} 🍪 are artisanal, gluten-free, and slightly cursed.`,
|
||||
`A wild baker appeared! They hand you **${amount}** ${s} 🍪`,
|
||||
`${user}, Abra said these **${amount}** ${s} 🍪 are "totally not stolen"... 🤔`,
|
||||
`${user}, here’s your **${amount}** ${s} 🍪 — watch out, they may be booby-trapped.`
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
const responses = collectResponses(amount, user);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: responses[i] });
|
||||
|
||||
}
|
||||
|
||||
async function steal(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
if (!target) {
|
||||
return interaction.reply({ content: `Pick someone to steal from.`, ephemeral: true });
|
||||
}
|
||||
if (target.id === user.id) {
|
||||
return interaction.reply({
|
||||
content: `C'mon, don't embarrass yourself! We all know you couldn't do that, even if you tried.`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
// steal cooldown (15 minutes)
|
||||
const sub = interaction.options._subcommand;
|
||||
const id = cooldownId(interaction.guildId, interaction.user.id, interaction.commandName, sub);
|
||||
const now = Date.now();
|
||||
const existing = await getCooldown(id);
|
||||
if (existing > now) {
|
||||
return interaction.reply({
|
||||
content: `Hold up — try stealing again in **${msToTime(existing - now)}**`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
await setCooldown(id, interaction.commandName, sub, now + 15 * 60 * 1000);
|
||||
|
||||
// pull balances
|
||||
const your = await getCookies(user.id);
|
||||
const their = await getCookies(target.id);
|
||||
|
||||
if (your <= 0) {
|
||||
return interaction.reply({ content: `You need at least 1 Cookie to attempt a Robbery`, ephemeral: true });
|
||||
}
|
||||
if (their <= 0) {
|
||||
return interaction.reply({ content: `Shame on you! ${target.username} doesn't have any Cookies D:`, ephemeral: true });
|
||||
}
|
||||
|
||||
// success chance and clamping
|
||||
let successChance = your / (your + their);
|
||||
if (isNaN(successChance) || !isFinite(successChance)) successChance = 0.2;
|
||||
successChance = Math.max(0.10, Math.min(0.90, successChance));
|
||||
|
||||
const success = Math.random() < successChance;
|
||||
|
||||
if (success) {
|
||||
const stealSuccessResponses = (amount, target) => {
|
||||
const s = amount === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`You've successfully stolen **${amount}** ${s} from **${target.username}**!`,
|
||||
`Ninja mode: activated. You snatched **${amount}** ${s} from **${target.username}** without a crumb left behind.`,
|
||||
`Abra taught you well — **${amount}** ${s} from **${target.username}** are now yours!`,
|
||||
`Like a phantom in the night, you took **${amount}** ${s} from **${target.username}**.`,
|
||||
`You just pulled the sweetest heist: **${amount}** ${s} from **${target.username}**!`,
|
||||
`Mission complete. **${target.username}** is **${amount}** ${s} poorer, you are richer.`,
|
||||
`You distracted **${target.username}** with a dance and swiped **${amount}** ${s}.`,
|
||||
`Clean getaway! **${target.username}** won’t know about the missing **${amount}** ${s} until it’s too late.`,
|
||||
`The Cookie Vault has been breached. **${amount}** ${s} taken from **${target.username}**.`,
|
||||
`You emerged from the shadows with **${amount}** ${s} from **${target.username}**.`
|
||||
];
|
||||
};
|
||||
|
||||
const maxSteal = Math.max(1, Math.ceil(their / 4)); // steal up to ~25% of victim
|
||||
let amount = Math.floor(Math.random() * maxSteal) + 1;
|
||||
amount = Math.min(amount, their);
|
||||
|
||||
// transfer
|
||||
await Promise.all([
|
||||
changeCookies(user.id, amount, user.username),
|
||||
changeCookies(target.id, -amount, target.username)
|
||||
]);
|
||||
|
||||
const responses = stealSuccessResponses(amount, target);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: responses[i] });
|
||||
|
||||
} else {
|
||||
const stealFailResponses = (penalty, target) => {
|
||||
const s = penalty === 1 ? 'Cookie' : 'Cookies';
|
||||
return [
|
||||
`You were caught red-handed by **${target.username}** and lost **${penalty}** ${s} as a penalty!`,
|
||||
`Fail! **${target.username}** caught you mid-bite — you dropped **${penalty}** ${s}.`,
|
||||
`Not your best moment... You lost **${penalty}** ${s} to **${target.username}** in the struggle.`,
|
||||
`Stealth level: 0. You handed **${penalty}** ${s} to **${target.username}** as an apology.`,
|
||||
`The cookie jar was booby-trapped! You gave **${penalty}** ${s} to **${target.username}** while running away.`,
|
||||
`Ouch. The guard dog barked, and now **${target.username}** has your **${penalty}** ${s}.`,
|
||||
`You tripped over your own shoelace — **${target.username}** reclaimed **${penalty}** ${s}.`,
|
||||
`Caught by the Cookie Police! **${penalty}** ${s} confiscated and given to **${target.username}**.`,
|
||||
`Your pockets had holes... **${target.username}** picked up **${penalty}** ${s} you dropped.`
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
// failure penalty: attacker loses a little (1..ceil(your/6)) to the victim
|
||||
const maxPenalty = Math.max(1, Math.ceil(your / 6));
|
||||
const penalty = Math.min(your, Math.floor(Math.random() * maxPenalty) + 1);
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -penalty, user.username),
|
||||
changeCookies(target.id, +penalty, target.username)
|
||||
]);
|
||||
|
||||
const responses = stealFailResponses(penalty, target);
|
||||
const i = Math.floor(Math.random() * responses.length);
|
||||
return interaction.reply({ content: responses[i] });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function check(interaction, user) {
|
||||
let target = interaction.options.getUser('target');
|
||||
if (!target) target = user;
|
||||
|
||||
const cookies = await getCookies(target.id);
|
||||
const mood = cookies === 0 ? '😔' : '😲';
|
||||
return interaction.reply({ content: `**${target.username}** has **${cookies}** Cookies! ${mood}` });
|
||||
}
|
||||
|
||||
async function give(interaction, user) {
|
||||
const target = interaction.options.getUser('target');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (!target) return interaction.reply({ content: `You need to specify a target.`, ephemeral: true });
|
||||
if (target.id === user.id) return interaction.reply({ content: 'You cannot give yourself Cookies ._."', ephemeral: true });
|
||||
if (!Number.isInteger(amount) || amount < 1) {
|
||||
return interaction.reply({ content: `**${user}** shared *checks notes* **${amount}** Cookie(s) with ${target}....wait a minute!!`, ephemeral: true });
|
||||
}
|
||||
|
||||
const your = await getCookies(user.id);
|
||||
if (your < amount) return interaction.reply({ content: `We don't run a charity here, get more Cookies!`, ephemeral: true });
|
||||
|
||||
await Promise.all([
|
||||
changeCookies(user.id, -amount, user.username),
|
||||
changeCookies(target.id, +amount, target.username)
|
||||
]);
|
||||
|
||||
// small delay to mimic previous behavior
|
||||
await delay(200);
|
||||
return interaction.reply({ content: `**${user}** shared **${amount}** Cookie(s) with ${target}` });
|
||||
}
|
||||
|
||||
async function leader(interaction) {
|
||||
const results = await cookieSchema.find().sort({ cookies: -1 }).limit(10);
|
||||
let cookieSorted = '';
|
||||
results.forEach((r, i) => {
|
||||
cookieSorted += `[${i + 1}] <@${r._id}> (${r.cookies})\n`;
|
||||
});
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setColor(0x0099FF)
|
||||
.setThumbnail(interaction.guild.iconURL())
|
||||
.setTimestamp()
|
||||
.addFields({ name: `-Cookie Leaderboard-`, value: cookieSorted || 'No cookie data yet.' });
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'collect a cookie',
|
||||
category: 'Misc',
|
||||
options: [
|
||||
{ name: "collect", description: "want some?", type: 1 },
|
||||
{ name: "steal", description: "try your luck at a lala robbery!", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }] },
|
||||
{ name: "check", description: "check your cookie stash", type: 1, options: [{ name: "target", description: "someone", type: 6 }] },
|
||||
{ name: "give", description: "share your cookies with someone", type: 1, options: [{ name: "target", description: "someone", required: true, type: 6 }, { name: "amount", description: "cookies", required: true, type: 4 }] },
|
||||
{ name: "leader", description: "show Top 10 Cookie Clickers", type: 1 }
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
const sub = interaction.options._subcommand;
|
||||
switch (sub) {
|
||||
case "collect": return collect(interaction, user);
|
||||
case "steal": return steal(interaction, user);
|
||||
case "check": return check(interaction, user);
|
||||
case "give": return give(interaction, user);
|
||||
case "leader": return leader(interaction);
|
||||
default: return interaction.reply({ content: 'Unknown subcommand', ephemeral: true });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,383 @@
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
const uri = process.env.URI
|
||||
const cookieSchema = require("../schemas/cookieSchema")
|
||||
const cooldownSchema = require("../schemas/cooldownSchema")
|
||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
const Discord = require('discord.js')
|
||||
|
||||
const client = new MongoClient(uri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
function msToTime(duration) {
|
||||
var milliseconds = parseInt((duration % 1000) / 100),
|
||||
seconds = Math.floor((duration / 1000) % 60),
|
||||
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
||||
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
|
||||
hours = (hours < 10) ? "0" + hours : hours;
|
||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
}
|
||||
async function collect(interaction, user) {
|
||||
client.connect(async (err, db) => {
|
||||
var dbo = db.db('test')
|
||||
let id = `${interaction.guildId}-${interaction.user.id}-${interaction.commandName}-${interaction.options._subcommand}`
|
||||
dbo.collection('cooldowns').findOne({
|
||||
_id: id
|
||||
}, async function (err, results) {
|
||||
let now = Date.now()
|
||||
let time = now + 3600000 // plus one hour in ms
|
||||
if (results) {
|
||||
if (results.cooldown > now) {
|
||||
time = new Date(results.cooldown).toUTCString()
|
||||
return interaction.reply({
|
||||
content: `The batch is still cooking, come back in **${msToTime(results.cooldown - now)}**`,
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
}
|
||||
addCooldown(interaction.user.id, interaction.guildId, interaction.commandName, interaction.options._subcommand, time)
|
||||
|
||||
|
||||
var ftext = [
|
||||
"I ate the rest, sorry >.<",
|
||||
"Blame Abra",
|
||||
"Would you like some Milk with that?",
|
||||
"Careful! They're still warm :3",
|
||||
"Best Batch yet!",
|
||||
"These, I bequeath unto thine own self upon this day. Thou must guard them safely.",
|
||||
""
|
||||
]
|
||||
var i = Math.floor(Math.random() * ftext.length)
|
||||
//funny text at the end
|
||||
|
||||
var amount = Math.floor(Math.random() * 30)
|
||||
//random amount between 1 and 29
|
||||
if (user.id == "378135175059603457") {
|
||||
//Abra Bonus
|
||||
amount *= 1.25
|
||||
}
|
||||
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: +amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
var response = `<@${user.id}>, 🍪 you collected ${amou*nt} cookies!! 🍪 ${ftext[i]}`
|
||||
|
||||
interaction.reply({
|
||||
content: response
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
function steal(interaction, user) {
|
||||
client.connect(async (err, db) => {
|
||||
if (err) throw err;
|
||||
let target = interaction.options.getUser('target')
|
||||
let dbo = db.db("test")
|
||||
|
||||
if (target.id == user.id) {
|
||||
return interaction.reply({
|
||||
content: `C'mon, don't embarass yourself! We all know you couldn't do that, even if you tried.`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
|
||||
// get your amount of cookies
|
||||
let your = await dbo.collection('cookies').findOne({
|
||||
_id: user.id
|
||||
})
|
||||
// get their amount of cookies
|
||||
let their = await dbo.collection('cookies').findOne({
|
||||
_id: target.id
|
||||
})
|
||||
try {
|
||||
if (!your.cookies) {
|
||||
return interaction.reply({
|
||||
content: `You need at least 1 Cookie to attempt a Robbery`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
if (!their.cookies) {
|
||||
return interaction.reply({
|
||||
content: `Shame on you! They don't even have any Cookies D:`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
return interaction.reply({
|
||||
content: `How awkward...I don't know some of you!`,
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
let difficulty = []
|
||||
for (var i = 0; i < their.cookies; i++) {
|
||||
if (i < your.cookies) {
|
||||
difficulty.push(false)
|
||||
} else {
|
||||
difficulty.push(true)
|
||||
}
|
||||
}
|
||||
let result = Math.floor(Math.random() * their.cookies) + 1
|
||||
let response
|
||||
if (!difficulty[result]) {
|
||||
// author lost
|
||||
response = `You were unsuccessful at robbing **${target.username}** and lost **${result}** Cookie(s)! `
|
||||
if (your.cookies - result <= 0) {
|
||||
result = your.cookies
|
||||
response += `That's all your Cookies gone.`
|
||||
}
|
||||
result *= -1
|
||||
|
||||
} else {
|
||||
//author won
|
||||
response = `You've successfully stolen **${result}** Cookie(s) from **${target.username}**! `
|
||||
if (their.cookies - result <= 0) {
|
||||
result = their.cookies
|
||||
response += `They're completely dry now.`
|
||||
}
|
||||
}
|
||||
interaction.reply({
|
||||
content: response
|
||||
})
|
||||
|
||||
//update author's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: +result } //will decrease if it's +negativeInteger
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: target.id
|
||||
}, {
|
||||
_id: target.id,
|
||||
user: target.username,
|
||||
$inc: { cookies: -result } //will decrease if it's +negativeInteger
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
function check(interaction, user) {
|
||||
|
||||
client.connect(async function (err, db) {
|
||||
let target = interaction.options.getUser('target')
|
||||
|
||||
if (!target) {
|
||||
target = user
|
||||
}
|
||||
let response = `**${target.username}** has `
|
||||
let dbo = db.db("test")
|
||||
dbo.collection("cookies").findOne({
|
||||
_id: target.id
|
||||
}, function (err, results) {
|
||||
let cookies
|
||||
if (!results) {
|
||||
cookies = 0
|
||||
response += `**${cookies}** Cookies! 😔`
|
||||
} else {
|
||||
cookies = results.cookies
|
||||
response += `**${cookies}** Cookies! 😲`
|
||||
}
|
||||
interaction.reply({
|
||||
content: response
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
async function give(interaction, user) {
|
||||
client.connect(async function (err, db) {
|
||||
let target = interaction.options.getUser('target')
|
||||
let amount = interaction.options.getInteger('amount')
|
||||
let dbo = db.db('test')
|
||||
|
||||
//check if you have enough cookies
|
||||
let your = await dbo.collection('cookies').findOne({
|
||||
_id: user.id
|
||||
})
|
||||
|
||||
if (target.id == user.id) {
|
||||
return interaction.reply({
|
||||
content: 'You cannot give yourself Cookies ._."'
|
||||
})
|
||||
}
|
||||
if (your.cookies < amount) {
|
||||
return interaction.reply({
|
||||
content: `We don't run a charity here, get more Cookies!`
|
||||
})
|
||||
}
|
||||
if (amount < 1) {
|
||||
return interaction.reply({
|
||||
content: `**${user}** shared *checks notes* **${amount}** Cookie(s) with ${target}....wait a minute!!`,
|
||||
})
|
||||
}
|
||||
|
||||
//update user's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: user.id
|
||||
}, {
|
||||
_id: user.id,
|
||||
user: user.username,
|
||||
$inc: { cookies: -amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
|
||||
//update target's cookies
|
||||
await cookieSchema.findOneAndUpdate({
|
||||
_id: target.id
|
||||
}, {
|
||||
_id: target.id,
|
||||
user: target.username,
|
||||
$inc: { cookies: +amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
await delay(200)
|
||||
interaction.reply({
|
||||
content: `**${user}** shared **${amount}** Cookie(s) with ${target}`
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
async function addCooldown(userId, guildId, command, subcommand, ms) {
|
||||
let id = `${guildId}-${userId}-${command}-${subcommand}`
|
||||
await cooldownSchema.findOneAndUpdate({
|
||||
_id: id
|
||||
}, {
|
||||
_id: id,
|
||||
command: command,
|
||||
subcommand: subcommand,
|
||||
cooldown: ms
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
}
|
||||
async function leader(interaction) {
|
||||
const results = await cookieSchema.find().sort({
|
||||
cookies: -1
|
||||
}).limit(10)
|
||||
let cookieSorted = ''
|
||||
let i = 0
|
||||
results.forEach((result) => {
|
||||
cookieSorted += `[${i + 1}] <@${result._id}> (${result.cookies})\n`
|
||||
i++;
|
||||
})
|
||||
|
||||
var embed = new Discord.MessageEmbed()
|
||||
.setColor(0x0099FF)
|
||||
.setThumbnail(interaction.guild.iconURL())
|
||||
.setTimestamp()
|
||||
.addFields({ name: `-Cookie Leaderboard-`, value: cookieSorted })
|
||||
|
||||
interaction.reply({
|
||||
embeds: [embed]
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'collect a cookie',
|
||||
category: 'Misc',
|
||||
options: [
|
||||
//collect
|
||||
{
|
||||
name: "collect",
|
||||
description: "want some?",
|
||||
type: 1 // SubCommand Type
|
||||
},
|
||||
//steal
|
||||
{
|
||||
name: "steal",
|
||||
description: "try your luck at a lala robbery!",
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
required: true,
|
||||
type: 6 // User Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//check
|
||||
{
|
||||
name: "check",
|
||||
description: "check your cookie stash",
|
||||
required: false,
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
type: 6 // User Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//give
|
||||
{
|
||||
name: "give",
|
||||
description: "share your cookies with someone",
|
||||
required: false,
|
||||
type: 1, // SubCommand Type
|
||||
options: [
|
||||
{
|
||||
name: "target",
|
||||
description: "someone",
|
||||
required: true,
|
||||
type: 6 // User Type
|
||||
}, {
|
||||
name: "amount",
|
||||
description: "cookies",
|
||||
required: true,
|
||||
type: 4 // Integer Type
|
||||
}
|
||||
]
|
||||
},
|
||||
//leader
|
||||
{
|
||||
name: "leader",
|
||||
description: "show Top 10 Cookie Clickers",
|
||||
type: 1, // SubCommand Type
|
||||
},
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
switch (interaction.options._subcommand) {
|
||||
case "collect":
|
||||
collect(interaction, user)
|
||||
break;
|
||||
case "steal":
|
||||
steal(interaction, user)
|
||||
break;
|
||||
case "check":
|
||||
check(interaction, user)
|
||||
break;
|
||||
case "give":
|
||||
give(interaction, user)
|
||||
break;
|
||||
case "leader":
|
||||
leader(interaction)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'surprise!',
|
||||
category: 'meme',
|
||||
options: [
|
||||
{
|
||||
name: 'pwned',
|
||||
description: "Told you not to click on this",
|
||||
required: true,
|
||||
type: 3,
|
||||
choices: [
|
||||
{ "name": 'never', "value": "never" },
|
||||
{ "name": 'gonna', "value": "gonna" },
|
||||
{ "name": 'give', "value": "give" },
|
||||
{ "name": 'you', "value": "you" },
|
||||
{ "name": 'up', "value": "up" },
|
||||
{ "name": 'never', "value": "never" },
|
||||
{ "name": 'gonna', "value": "gonna" },
|
||||
{ "name": 'let', "value": "let" },
|
||||
{ "name": 'you', "value": "you" },
|
||||
{ "name": 'down', "value": "down" },
|
||||
],
|
||||
},
|
||||
],
|
||||
callback: async ({ interaction }) => {
|
||||
interaction.reply({
|
||||
content: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
ephemeral: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||
require('dotenv').config();
|
||||
const uri = process.env.URI
|
||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
const client = new MongoClient(uri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverApi: ServerApiVersion.v1
|
||||
});
|
||||
const expansions = new Map([
|
||||
["ARR", { "min": 0, "max": 50 }],
|
||||
["HW", { "min": 51, "max": 60 }],
|
||||
["SB", { "min": 61, "max": 70 }],
|
||||
["ShB", { "min": 71, "max": 80 }],
|
||||
["EW", { "min": 81, "max": 90 }],
|
||||
|
||||
])
|
||||
|
||||
async function getDutyData(interaction, database, user) {
|
||||
var parameters = {
|
||||
"type": interaction.options.getString('type'),
|
||||
"min": interaction.options.getInteger('minlevel'),
|
||||
"max": interaction.options.getInteger('maxlevel'),
|
||||
"expansion": interaction.options.getString('expansion')
|
||||
}
|
||||
if (!parameters.type) {
|
||||
//no type specified, randomizing...
|
||||
database.listCollections().toArray(function (err, results) {
|
||||
if (err) throw err;
|
||||
let random = Math.floor(Math.random() * results.length)
|
||||
parameters.type = results[random].name
|
||||
})
|
||||
}
|
||||
|
||||
if (parameters.expansion) {
|
||||
//check if paramters are set correctly
|
||||
if (!parameters.min) {
|
||||
parameters.min = expansions.get(parameters.expansion).min
|
||||
}
|
||||
if (parameters.min < expansions.get(parameters.expansion).min) {
|
||||
return console.log("mismatch min level and expansion")
|
||||
}
|
||||
|
||||
if (!parameters.max) {
|
||||
parameters.max = expansions.get(parameters.expansion).max
|
||||
}
|
||||
if (parameters.max > expansions.get(parameters.expansion).max) {
|
||||
return console.log("mismatch max level and expansion")
|
||||
}
|
||||
} else {
|
||||
if (!parameters.min) { parameters.min = 0 }
|
||||
if (!parameters.max) { parameters.max = 90 }
|
||||
}
|
||||
|
||||
if (parameters.type == 'pvp') {
|
||||
parameters.expansion = 'ARR'
|
||||
parameters.min = expansions.get(parameters.expansion).min
|
||||
parameters.max = expansions.get(parameters.expansion).max
|
||||
}
|
||||
|
||||
await delay(500) //wait for updates
|
||||
database.collection(parameters.type).find({
|
||||
level: { '$gte': parameters.min, '$lte': parameters.max }
|
||||
}).toArray(async function (err, results2) {
|
||||
let random = Math.floor(Math.random() * results2.length)
|
||||
try {
|
||||
let duty = results2[random]
|
||||
let reply = `<@${user.id}>, Thou shalt playeth...${duty.name} [Level: ${duty.level}, Type: ${parameters.type}`
|
||||
if (duty.expansion) {
|
||||
reply += `, Expansion: ${duty.expansion}]`
|
||||
} else {
|
||||
reply += ']'
|
||||
}
|
||||
|
||||
interaction.reply({
|
||||
content: reply
|
||||
})
|
||||
} catch (error) {
|
||||
interaction.reply({
|
||||
content: `WAA!! (Impossible Combination found)`
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
async function getClassData(interaction, database, user) {
|
||||
var collection = interaction.options.getString('type')
|
||||
if (!collection) {
|
||||
//no type specified
|
||||
database.listCollections().toArray(function (err, cResults) {
|
||||
let rdm = Math.floor(Math.random() * cResults.length)
|
||||
collection = cResults[rdm].name
|
||||
})
|
||||
}
|
||||
|
||||
await delay(200) //wait for database.listCollections()
|
||||
|
||||
database.collection(collection).find({}).toArray(async function (err, results) {
|
||||
if (err) throw err;
|
||||
var response
|
||||
try {
|
||||
let rdm = Math.floor(Math.random() * results.length)
|
||||
response = `<@${user.id}>, Thou shalt playeth...${results[rdm].job}`
|
||||
} catch (error) {
|
||||
response = 'Invalid Type specified!'
|
||||
}
|
||||
interaction.reply({
|
||||
content: response,
|
||||
})
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
category: 'Random',
|
||||
description: 'randomized helper', // Required for slash commands
|
||||
slash: true, // Create both a slash and legacy command
|
||||
options: [
|
||||
{
|
||||
name: "duty",
|
||||
type: 1,
|
||||
description: "random duty",
|
||||
options: [
|
||||
{
|
||||
name: 'type',
|
||||
description: 'what kind of duty would you like?',
|
||||
required: false,
|
||||
type: 3,
|
||||
choices: [
|
||||
{ "name": 'Dungeons', "value": "dungeons" },
|
||||
{ "name": 'Guildhests', "value": "guildhests" },
|
||||
{ "name": 'PvP', "value": "pvp" },
|
||||
{ "name": 'Normal Raids', "value": "nraids" },
|
||||
{ "name": 'Alliance Raids', "value": "araids" },
|
||||
{ "name": 'Trials', "value": "trials" },
|
||||
{ "name": 'Extreme', "value": "extreme" },
|
||||
{ "name": 'Savage', "value": "savage" },
|
||||
{ "name": 'Ultimates', "value": "ultimates" },
|
||||
{ "name": 'Roulettes', "value": "roulettes" },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'minlevel',
|
||||
description: 'Start of Level Range, assuming 0 if not specified',
|
||||
required: false,
|
||||
type: 4,
|
||||
},
|
||||
{
|
||||
name: 'maxlevel',
|
||||
description: 'End of Level Range, assuming 90 if not specified',
|
||||
required: false,
|
||||
type: 4,
|
||||
},
|
||||
{
|
||||
name: 'expansion',
|
||||
description: 'which expansion would you like?',
|
||||
required: false,
|
||||
type: 3,
|
||||
choices: [
|
||||
{ "name": 'A Realm Reborn', "value": "ARR" },
|
||||
{ "name": 'Heavensward', "value": "HW" },
|
||||
{ "name": 'Stormblood', "value": "SB" },
|
||||
{ "name": 'Shadowbringers', "value": "ShB" },
|
||||
{ "name": 'Endwalker', "value": "EW" },
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "class",
|
||||
type: 1,
|
||||
description: "random class",
|
||||
options: [
|
||||
{
|
||||
name: 'type',
|
||||
description: 'specify class',
|
||||
required: false,
|
||||
type: 3,
|
||||
choices: [
|
||||
{ "name": 'Healer', "value": "healer" },
|
||||
{ "name": 'Tank', "value": "tank" },
|
||||
{ "name": 'Melee', "value": "melee" },
|
||||
{ "name": 'Ranged', "value": "ranged" },
|
||||
{ "name": 'Caster', "value": "caster" },
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
],
|
||||
callback: ({ interaction, user }) => {
|
||||
switch (interaction.options._subcommand) {
|
||||
case "duty":
|
||||
client.connect(function (err, db) {
|
||||
if (err) throw err;
|
||||
|
||||
var dbDuties = db.db("Duties")
|
||||
getDutyData(interaction, dbDuties, user)
|
||||
})
|
||||
break;
|
||||
case "class":
|
||||
client.connect(async function (err, db) {
|
||||
if (err) throw err;
|
||||
|
||||
var dbClasses = db.db("Classes")
|
||||
getClassData(interaction, dbClasses, user)
|
||||
})
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'sussy baka',
|
||||
category: 'meme',
|
||||
callback: async ({ interaction }) => {
|
||||
interaction.reply({
|
||||
content: "ඞ"
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: '',
|
||||
category: '',
|
||||
options: [
|
||||
{
|
||||
name: 'victim',
|
||||
description: 'pick anyone >:D',
|
||||
required: true,
|
||||
type: 9,
|
||||
options: [
|
||||
{
|
||||
name: 'type',
|
||||
description: 'what kind of duty would you like?',
|
||||
required: false,
|
||||
type: 3, //String
|
||||
choices: [
|
||||
{ "name": 'choice', "value": "value" },
|
||||
],
|
||||
autocomplete: true
|
||||
},
|
||||
],
|
||||
|
||||
},
|
||||
],
|
||||
callback: async ({ interaction }) => {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
slash: true,
|
||||
description: 'waa! at someone',
|
||||
category: 'Misc',
|
||||
cooldown: '3h',
|
||||
options: [
|
||||
{
|
||||
name: 'victim',
|
||||
description: 'pick anyone >:D',
|
||||
required: true,
|
||||
type: 9,
|
||||
},
|
||||
],
|
||||
callback: async ({ interaction, args, client }) => {
|
||||
var reply = 'waa!'
|
||||
|
||||
const member = client.users.cache.get(args[0]);
|
||||
if(args[0]){
|
||||
reply+= ` <@${member.id}>`
|
||||
}
|
||||
interaction.reply({
|
||||
content: reply,
|
||||
tts: true
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user