converted ShaiBot casino to Nut Economy
This commit is contained in:
@@ -1,78 +1,224 @@
|
||||
const { EmbedBuilder } = require('discord.js')
|
||||
const { mClient } = require('../../../index')
|
||||
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
||||
require('dotenv').config()
|
||||
const {
|
||||
EmbedBuilder
|
||||
} = require("discord.js");
|
||||
|
||||
const {
|
||||
getNutBalance,
|
||||
transferNuts
|
||||
} = require(
|
||||
"../../../utils/nutEconomy"
|
||||
);
|
||||
|
||||
|
||||
function delay(ms) {
|
||||
return new Promise(
|
||||
resolve =>
|
||||
setTimeout(
|
||||
resolve,
|
||||
ms
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'givenuts',
|
||||
description: 'give nuts',
|
||||
aliases: ['gn'],
|
||||
async execute(message, args) {
|
||||
const from = message.author
|
||||
if (args[0] == `<@${message.author.id}>` || !args[0]) {
|
||||
name:
|
||||
"givenuts",
|
||||
|
||||
description:
|
||||
"give nuts",
|
||||
|
||||
aliases: [
|
||||
"gn"
|
||||
],
|
||||
|
||||
|
||||
async execute(
|
||||
message,
|
||||
args
|
||||
) {
|
||||
const from =
|
||||
message.author;
|
||||
|
||||
|
||||
if (
|
||||
args[0] ==
|
||||
`<@${message.author.id}>`
|
||||
||
|
||||
!args[0]
|
||||
) {
|
||||
return message.reply({
|
||||
content: "Du musst einen anderen User erwähnen"
|
||||
}).then(async (msg) => {
|
||||
await delay(4000)
|
||||
message.delete()
|
||||
msg.delete()
|
||||
content:
|
||||
"Du musst einen anderen User erwähnen"
|
||||
})
|
||||
.then(
|
||||
async msg => {
|
||||
await delay(
|
||||
4000
|
||||
);
|
||||
|
||||
|
||||
message.delete();
|
||||
msg.delete();
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!args[0].startsWith('<@' || !args[0].endsWith('>'))) { return message.reply('Invalid User Specification') }
|
||||
try {
|
||||
target = await message.guild.members.fetch(args[0].slice(2, -1))
|
||||
} catch (error) {
|
||||
return message.reply({
|
||||
content: `User: ${args[0]} nicht gefunden!`
|
||||
}).then(async (msg) => {
|
||||
await delay(4000)
|
||||
message.delete()
|
||||
msg.delete()
|
||||
})
|
||||
|
||||
|
||||
if (
|
||||
!args[0].startsWith("<@")
|
||||
||
|
||||
!args[0].endsWith(">")
|
||||
) {
|
||||
return message.reply(
|
||||
"Invalid User Specification"
|
||||
);
|
||||
}
|
||||
const to = target
|
||||
|
||||
|
||||
let target;
|
||||
|
||||
|
||||
try {
|
||||
var amount = Number(args[1])
|
||||
target =
|
||||
await message.guild.members.fetch(
|
||||
args[0].slice(
|
||||
2,
|
||||
-1
|
||||
)
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
return message.reply({
|
||||
content: 'Du musst eine Menge angeben!'
|
||||
}).then(async (msg) => {
|
||||
await delay(4000)
|
||||
message.delete()
|
||||
msg.delete()
|
||||
content:
|
||||
`User: ${args[0]} nicht gefunden!`
|
||||
})
|
||||
}
|
||||
if (!amount) {
|
||||
return message.reply({content : 'Danke für nichts, du Hu-'})
|
||||
.then(
|
||||
async msg => {
|
||||
await delay(
|
||||
4000
|
||||
);
|
||||
|
||||
|
||||
message.delete();
|
||||
msg.delete();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
const nutsColl = db.collection('items_nuts')
|
||||
const yourBalance = await nutsColl.findOne({ userID: from.id })
|
||||
if (amount <= 0) {
|
||||
return await message.reply({
|
||||
content: `Hier wird nicht geklaut >:(\r\nDas gibt **${yourBalance.nuts}** Abzug!`
|
||||
})
|
||||
}
|
||||
if (yourBalance.nuts < amount) {
|
||||
return await message.reply({
|
||||
content: 'Du kannst nicht mehr geben als du hast!',
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
var content = `Du sendest **${amount}** Nüsse an <@${target.id}>`
|
||||
|
||||
if (amount == 1) {
|
||||
content = `Du sendest **eine** Nuss an <@${target.id}>`
|
||||
}
|
||||
await nutsColl.findOneAndUpdate({ userID: from.id }, { $inc: { nuts: -amount } }, { upsert: true })
|
||||
await nutsColl.findOneAndUpdate({ userID: to.id }, { $inc: { nuts: +amount } }, { upsert: true })
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('Gib Nuss!')
|
||||
.setDescription(content)
|
||||
.setThumbnail(target.displayAvatarURL())
|
||||
return message.reply({ embeds: [embed] })
|
||||
const to =
|
||||
target;
|
||||
|
||||
|
||||
let amount;
|
||||
|
||||
|
||||
try {
|
||||
amount =
|
||||
Number(
|
||||
args[1]
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.log(
|
||||
error
|
||||
);
|
||||
|
||||
|
||||
return message.reply({
|
||||
content:
|
||||
"Du musst eine Menge angeben!"
|
||||
})
|
||||
.then(
|
||||
async msg => {
|
||||
await delay(
|
||||
4000
|
||||
);
|
||||
|
||||
|
||||
message.delete();
|
||||
msg.delete();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
!amount
|
||||
) {
|
||||
return message.reply({
|
||||
content:
|
||||
"Danke für nichts, du Hu-"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const yourBalance =
|
||||
await getNutBalance(
|
||||
from.id
|
||||
);
|
||||
|
||||
|
||||
if (
|
||||
amount <=
|
||||
0
|
||||
) {
|
||||
return message.reply({
|
||||
content:
|
||||
`Hier wird nicht geklaut >:(\r\nDas gibt **${yourBalance}** Abzug!`
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
yourBalance <
|
||||
amount
|
||||
) {
|
||||
return message.reply({
|
||||
content:
|
||||
"Du kannst nicht mehr geben als du hast!"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let content =
|
||||
`Du sendest **${amount}** Nüsse an <@${target.id}>`;
|
||||
|
||||
|
||||
if (
|
||||
amount ==
|
||||
1
|
||||
) {
|
||||
content =
|
||||
`Du sendest **eine** Nuss an <@${target.id}>`;
|
||||
}
|
||||
|
||||
|
||||
await transferNuts(
|
||||
from.id,
|
||||
to.id,
|
||||
amount
|
||||
);
|
||||
|
||||
|
||||
const embed =
|
||||
new EmbedBuilder()
|
||||
.setTitle(
|
||||
"Gib Nuss!"
|
||||
)
|
||||
.setDescription(
|
||||
content
|
||||
)
|
||||
.setThumbnail(
|
||||
target.displayAvatarURL()
|
||||
);
|
||||
|
||||
|
||||
return message.reply({
|
||||
embeds: [
|
||||
embed
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user