Merge branch 'main' of https://github.com/ChrisChrome/cactus-coin
This commit is contained in:
commit
7c22d63b34
|
@ -85,7 +85,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "transfer",
|
"name": "transfer",
|
||||||
"description": "Transfer coins to another user (2:1 ratio)",
|
"description": "Transfer coins to another user with a 25% tax",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
|
@ -218,6 +218,20 @@
|
||||||
{
|
{
|
||||||
"name": "wordscramble",
|
"name": "wordscramble",
|
||||||
"description": "Trigger a word scramble (admin only)",
|
"description": "Trigger a word scramble (admin only)",
|
||||||
"type": 1
|
"type": 1,
|
||||||
|
"options":[
|
||||||
|
{
|
||||||
|
"name": "override",
|
||||||
|
"description": "Force the specified string/word instead of the random option",
|
||||||
|
"type": 3,
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount",
|
||||||
|
"description": "The amount to pay for this forced scramble",
|
||||||
|
"type": 10,
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
96
index.js
96
index.js
|
@ -1,4 +1,5 @@
|
||||||
const config = require("./config.json");
|
const config = require("./config.json");
|
||||||
|
if (!config.debug) config.debug = false;
|
||||||
const Discord = require("discord.js");
|
const Discord = require("discord.js");
|
||||||
const rest = new Discord.REST({
|
const rest = new Discord.REST({
|
||||||
version: '10'
|
version: '10'
|
||||||
|
@ -148,6 +149,8 @@ setCooldown = (user, type, cooldown) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var slotResults = {};
|
||||||
|
|
||||||
client.on("interactionCreate", async interaction => {
|
client.on("interactionCreate", async interaction => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
switch (interaction.commandName) {
|
switch (interaction.commandName) {
|
||||||
|
@ -407,14 +410,14 @@ client.on("interactionCreate", async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
// Now check if they have enough for the tax
|
// Now check if they have enough for the tax
|
||||||
if (balance < amount) return interaction.reply({
|
if (balance < amount * 1.25) return interaction.reply({
|
||||||
content: `You do not have enough coins to pay the tax of ${config.discord.coin}${amount * 0.25}. You only have ${config.discord.coin}${balance}.`,
|
content: `You do not have enough coins to pay the tax of ${config.discord.coin}${amount * 0.25}. You only have ${config.discord.coin}${balance}.`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
// At this point we know they have enough coins, so we can take them away, make sure to take the tax away too
|
// At this point we know they have enough coins, so we can take them away, make sure to take the tax away too
|
||||||
checkAndModifyPoints(interaction.user, -amount);
|
checkAndModifyPoints(interaction.user, -amount * 1.25);
|
||||||
// Now we can give the other user the coins
|
// Now we can give the other user the coins
|
||||||
checkAndModifyPoints(interaction.options.getMember("user").user, amount * 0.75);
|
checkAndModifyPoints(interaction.options.getMember("user").user, amount);
|
||||||
// Now we can tell the user that it worked
|
// Now we can tell the user that it worked
|
||||||
// get the amount sent with 2 decimal places if it has a decimal
|
// get the amount sent with 2 decimal places if it has a decimal
|
||||||
if (amount % 1 != 0) {
|
if (amount % 1 != 0) {
|
||||||
|
@ -439,7 +442,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Transfer Receipt",
|
title: "Transfer Receipt",
|
||||||
color: 0xffff00,
|
color: 0xffff00,
|
||||||
description: `You sent ${config.discord.coin}${amount} to ${interaction.options.getMember("user").user}.\nYou paid a tax of ${config.discord.coin}${amount}.`
|
description: `You sent ${config.discord.coin}${amount} to ${interaction.options.getMember("user").user}.\nYou paid a tax of ${config.discord.coin}${amount * 0.25}.`
|
||||||
}]
|
}]
|
||||||
}).catch(err => { });
|
}).catch(err => { });
|
||||||
|
|
||||||
|
@ -514,10 +517,10 @@ client.on("interactionCreate", async interaction => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the slot results, yes it's pre-defined, but it's not like it matters
|
// Get the slot results, yes it's pre-defined, but it's not like it matters
|
||||||
slotResults = playSlotMachine();
|
slotResults[interaction.user.id] = playSlotMachine();
|
||||||
// If there is a slotResults.cooldownOverride use that instead
|
// If there is a slotResults[interaction.user.id].cooldownOverride use that instead
|
||||||
if (slotResults.cooldownOverride) {
|
if (slotResults[interaction.user.id].cooldownOverride) {
|
||||||
setCooldown(interaction.user, "slots", slotResults.cooldownOverride * 60 * 1000)
|
setCooldown(interaction.user, "slots", slotResults[interaction.user.id].cooldownOverride * 60 * 1000)
|
||||||
} else {
|
} else {
|
||||||
setCooldown(interaction.user, "slots", config.games.slots.cooldown * 60 * 1000)
|
setCooldown(interaction.user, "slots", config.games.slots.cooldown * 60 * 1000)
|
||||||
}
|
}
|
||||||
|
@ -530,7 +533,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if they won or lost, if they won, give them the prize
|
// Check if they won or lost, if they won, give them the prize
|
||||||
difference = await new Number(slotResults.coinDifference);
|
difference = await new Number(slotResults[interaction.user.id].coinDifference);
|
||||||
// If they lost subtract 3 coins from the difference
|
// If they lost subtract 3 coins from the difference
|
||||||
if (difference <= 0) difference -= 3;
|
if (difference <= 0) difference -= 3;
|
||||||
// Wait 4 seconds, then one at a time change the slots, 1 second apart
|
// Wait 4 seconds, then one at a time change the slots, 1 second apart
|
||||||
|
@ -538,7 +541,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Slots",
|
title: "Slots",
|
||||||
description: `[${slotResults.spinResult[0]}][${config.games.slots.spinning}][${config.games.slots.spinning}]`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${config.games.slots.spinning}][${config.games.slots.spinning}]`,
|
||||||
color: 0xffff00
|
color: 0xffff00
|
||||||
}]
|
}]
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -546,7 +549,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Slots",
|
title: "Slots",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${config.games.slots.spinning}]`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${config.games.slots.spinning}]`,
|
||||||
color: 0xffff00
|
color: 0xffff00
|
||||||
}]
|
}]
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -554,24 +557,24 @@ client.on("interactionCreate", async interaction => {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Slots",
|
title: "Slots",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}]`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}]`,
|
||||||
color: 0xffff00
|
color: 0xffff00
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
if (difference > 0) {
|
if (difference > 0) {
|
||||||
if (slotResults.jackpot) {
|
if (slotResults[interaction.user.id].jackpot) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Jackpot!",
|
title: "Jackpot!",
|
||||||
description: `:rotating_light: [${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}] :rotating_light:\nYou won the jackpot! (${difference} coins)`,
|
description: `:rotating_light: [${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}] :rotating_light:\nYou won the jackpot! (${difference} coins)`,
|
||||||
color: 0xffffff
|
color: 0xffffff
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
} else if (slotResults.triple) {
|
} else if (slotResults[interaction.user.id].triple) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Triple!",
|
title: "Triple!",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}]\nYou won ${difference} coins!`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}]\nYou won ${difference} coins!`,
|
||||||
color: 0x00ffff
|
color: 0x00ffff
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
@ -579,19 +582,19 @@ client.on("interactionCreate", async interaction => {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Slots",
|
title: "Slots",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}]\nYou won ${difference} coins! (You get your play fee back)`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}]\nYou won ${difference} coins! (You get your play fee back)`,
|
||||||
color: 0x00ff00
|
color: 0x00ff00
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// They lost, sad
|
// They lost, sad
|
||||||
if (slotResults.bombs) {
|
if (slotResults[interaction.user.id].bombs) {
|
||||||
// Triple bombs, very sad
|
// Triple bombs, very sad
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Bombs!",
|
title: "Bombs!",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}]\nYou lost ${Math.abs(difference)} coins!`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}]\nYou lost ${Math.abs(difference)} coins!`,
|
||||||
color: 0xff0000
|
color: 0xff0000
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
@ -599,7 +602,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Slots",
|
title: "Slots",
|
||||||
description: `[${slotResults.spinResult[0]}][${slotResults.spinResult[1]}][${slotResults.spinResult[2]}]\nYou lost ${Math.abs(difference)} coins!`,
|
description: `[${slotResults[interaction.user.id].spinResult[0]}][${slotResults[interaction.user.id].spinResult[1]}][${slotResults[interaction.user.id].spinResult[2]}]\nYou lost ${Math.abs(difference)} coins!`,
|
||||||
color: 0xff0000
|
color: 0xff0000
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
@ -624,8 +627,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setCooldown(interaction.user, "coinflip", config.games.coinflip.cooldown * 60 * 1000)
|
|
||||||
|
|
||||||
bet = parseInt(interaction.options.get("amount").value);
|
bet = parseInt(interaction.options.get("amount").value);
|
||||||
if (bet < 1 || bet > 10) return interaction.reply({
|
if (bet < 1 || bet > 10) return interaction.reply({
|
||||||
content: "You can only bet between 1 and 10 coins.",
|
content: "You can only bet between 1 and 10 coins.",
|
||||||
|
@ -640,7 +642,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Flip the coin
|
// Flip the coin
|
||||||
coin = Math.random() < 0.5 ? "heads" : "tails";
|
coin = Math.random() < 0.6 ? "heads" : "tails";
|
||||||
before = await checkPoints(interaction.user);
|
before = await checkPoints(interaction.user);
|
||||||
side = interaction.options.getString("side");
|
side = interaction.options.getString("side");
|
||||||
outcome = coin == side ? true : false;
|
outcome = coin == side ? true : false;
|
||||||
|
@ -648,6 +650,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
// if they lose inverse the bet
|
// if they lose inverse the bet
|
||||||
if (!outcome) bet = -bet;
|
if (!outcome) bet = -bet;
|
||||||
await checkAndModifyPoints(interaction.user, bet);
|
await checkAndModifyPoints(interaction.user, bet);
|
||||||
|
setCooldown(interaction.user, "coinflip", config.games.coinflip.cooldown * 60 * 1000)
|
||||||
if (coin == "heads") return interaction.reply({
|
if (coin == "heads") return interaction.reply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Coinflip",
|
title: "Coinflip",
|
||||||
|
@ -686,7 +689,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setCooldown(interaction.user, "snakeeyes", config.games.snakeeyes.cooldown * 60 * 1000)
|
|
||||||
|
|
||||||
bet = parseInt(interaction.options.get("amount").value);
|
bet = parseInt(interaction.options.get("amount").value);
|
||||||
if (bet < 1 || bet > 10) return interaction.reply({
|
if (bet < 1 || bet > 10) return interaction.reply({
|
||||||
|
@ -700,7 +703,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
content: "You do not have enough coins to play snakeeyes.",
|
content: "You do not have enough coins to play snakeeyes.",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
setCooldown(interaction.user, "snakeeyes", config.games.snakeeyes.cooldown * 60 * 1000)
|
||||||
// Roll the dice
|
// Roll the dice
|
||||||
dice = Math.floor(Math.random() * 6) + 1;
|
dice = Math.floor(Math.random() * 6) + 1;
|
||||||
before = points;
|
before = points;
|
||||||
|
@ -781,10 +784,23 @@ client.on("interactionCreate", async interaction => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a word scramble
|
// Start a word scramble and check if we specified a word
|
||||||
gameData = wordScramble();
|
if (interaction.options.get("override")) {
|
||||||
|
override = interaction.options.get("override").value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
override = false;
|
||||||
|
}
|
||||||
|
if (interaction.options.get("amount")) {
|
||||||
|
coinamount = interaction.options.getNumber("amount");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
coinamount = 2;
|
||||||
|
}
|
||||||
|
gameData = wordScramble(override);
|
||||||
wordScrambles[interaction.channel.id] = {
|
wordScrambles[interaction.channel.id] = {
|
||||||
word: gameData.word,
|
word: gameData.word,
|
||||||
|
amount: coinamount,
|
||||||
scrambledWord: gameData.scrambledWord,
|
scrambledWord: gameData.scrambledWord,
|
||||||
badGuesses: []
|
badGuesses: []
|
||||||
}
|
}
|
||||||
|
@ -820,19 +836,18 @@ client.on('messageCreate', async message => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if (!message.guild) return;
|
if (!message.guild) return;
|
||||||
if (message.channel.type == "dm") return;
|
if (message.channel.type == "dm") return;
|
||||||
if (config.games.wordscramble.blacklist.includes(message.channel.id)) return;
|
|
||||||
// Check if the channel already has a word scramble going
|
// Check if the channel already has a word scramble going
|
||||||
if (wordScrambles[message.channel.id]) {
|
if (wordScrambles[message.channel.id]) {
|
||||||
if (wordScrambles[message.channel.id].badGuesses.includes(message.author.id)) return;
|
if (wordScrambles[message.channel.id].badGuesses.includes(message.author.id)) return;
|
||||||
// Check if the message is the correct answer
|
// Check if the message is the correct answer
|
||||||
if (message.content.toLowerCase() == wordScrambles[message.channel.id].word.toLowerCase()) {
|
if (message.content.toLowerCase() == wordScrambles[message.channel.id].word.toLowerCase()) {
|
||||||
// Give the user a point
|
// Give the user a point
|
||||||
await checkAndModifyPoints(message.author, 2);
|
await checkAndModifyPoints(message.author, wordScrambles[message.channel.id].amount);
|
||||||
// Send the message
|
// Send the message
|
||||||
message.channel.send({
|
message.channel.send({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: "Word Scramble",
|
title: "Word Scramble",
|
||||||
description: `**${message.author}** got the word **${wordScrambles[message.channel.id].word}**!\nYou got 2 coins!`,
|
description: `**${message.author}** got the word **${wordScrambles[message.channel.id].word}**!\nYou got ${wordScrambles[message.channel.id].amount} coins!`,
|
||||||
color: 0x00ff00
|
color: 0x00ff00
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
@ -843,18 +858,22 @@ client.on('messageCreate', async message => {
|
||||||
wordScrambles[message.channel.id].badGuesses.push(message.author.id);
|
wordScrambles[message.channel.id].badGuesses.push(message.author.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
curCooldown = await checkCooldown({id: 0}, "wordscramble")
|
if (!config.games.wordscramble.whitelist.includes(message.channel.id) && !config.games.wordscramble.whitelist.includes(message.channel.parentId)) return;
|
||||||
|
curCooldown = await checkCooldown({ id: 0 }, "wordscramble")
|
||||||
if (curCooldown) {
|
if (curCooldown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 1 in 50 chance to start a word scramble
|
// 1 in 50 chance to start a word scramble
|
||||||
if (Math.floor(Math.random() * 10) == 0) {
|
if (Math.floor(Math.random() * 25) == 0) {
|
||||||
// Start a word scramble
|
// Start a word scramble
|
||||||
setCooldown({id: 0}, "wordscramble", 5 * 60 * 1000)
|
setCooldown({ id: 0 }, "wordscramble", 5 * 60 * 1000)
|
||||||
gameData = wordScramble();
|
override = false
|
||||||
|
coinamount = 2
|
||||||
|
gameData = wordScramble(override);
|
||||||
wordScrambles[message.channel.id] = {
|
wordScrambles[message.channel.id] = {
|
||||||
word: gameData.word,
|
word: gameData.word,
|
||||||
scrambledWord: gameData.scrambledWord,
|
scrambledWord: gameData.scrambledWord,
|
||||||
|
amount: 2,
|
||||||
badGuesses: []
|
badGuesses: []
|
||||||
}
|
}
|
||||||
message.channel.send({
|
message.channel.send({
|
||||||
|
@ -877,12 +896,17 @@ client.on('messageCreate', async message => {
|
||||||
}, 30 * 1000);
|
}, 30 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCooldown({id: 0}, "wordscramble", 1 * 60 * 1000)
|
setCooldown({ id: 0 }, "wordscramble", 1 * 60 * 1000)
|
||||||
});
|
});
|
||||||
|
|
||||||
function wordScramble() {
|
function wordScramble() {
|
||||||
// Get a random word from config.games.wordscramble.words then scramble it
|
// Get a random word from config.games.wordscramble.words then scramble it
|
||||||
word = config.games.wordscramble.words[Math.floor(Math.random() * config.games.wordscramble.words.length)];
|
if (!override) {
|
||||||
|
word = config.games.wordscramble.words[Math.floor(Math.random() * config.games.wordscramble.words.length)];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
word = override;
|
||||||
|
}
|
||||||
scrambledWord = word.split('').sort(function () {
|
scrambledWord = word.split('').sort(function () {
|
||||||
// Fully scramble the word 3 times to be safe
|
// Fully scramble the word 3 times to be safe
|
||||||
return 0.5 - Math.random();
|
return 0.5 - Math.random();
|
||||||
|
|
Loading…
Reference in a new issue