Skip to content

Commit

Permalink
🐛Bet Command (#2)
Browse files Browse the repository at this point in the history
* Social Bug Fixes:
- Allow consecutive bets using updates
- Replaced Discord delayFor (DATABASE_ERR bug)
- Updated README for MacOS setup
- Added linting commands to package json
- Added missing env variables in the env_example
- Corrected bank register message
- Allow nullity of bears guild members
  • Loading branch information
mkomaiha authored and BearTs committed Apr 20, 2022
1 parent ac40770 commit 7d3819c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ DISCORD_TOKEN=
# API_URL=https://api.tamako.tech
API_URL=

MONGODB_URI=
LAVALINK_URL=
LAVALINK_PASSWORD=
FACEPLUSPLUS_KEY=
FACEPLUSPLUS_SECRET=
GOOGLE_KEY+
GOOGLE_KEY=
APOD_KEY=
WEBSTER_KEY=
FLICKR_KEY=
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Check the docs at <a href="https://tamako.tech/">Tamako Tech</a>
Tamako is now open source and this is a rewrite of Code of Tamako and This repository will NOT INCLUDE all the features
that are present in Tamako Bot.


## MacOS Setup
- If `npm install` does not work use `brew install pkg-config cairo pango libpng jpeg giflib librsvg` first

## Contribution
Create a fork, make changes there and make a pull requrest.
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./src/index.js"
"start": "node ./src/index.js",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
},
"repository": "git+https://github.com/Tamako-Tech/Tamako.git",
"keywords": [
Expand All @@ -27,7 +29,7 @@
"packageManager": "[email protected]",
"dependencies": {
"animequotes": "^2.0.0",
"canvas": "^2.9.0",
"canvas": "^2.9.1",
"chalk": "^4.1.2",
"cheerio": "^1.0.0-rc.10",
"child_process": "^1.0.2",
Expand Down
41 changes: 41 additions & 0 deletions src/Commands/MessageCommands/to-do/social/adj-bal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { join } = require('path');
const profile = require(join(__dirname, '..', '..', '..', '..', 'Models', 'Profile.js'));

module.exports = {
name: 'adj-bal',
aliases: [ ],
description: 'Manually adjust balance',
ownerOnly: true,
cooldown: 0,
userPermissions: ['SEND_MESSAGES'],
clientPermissions: [ 'EMBED_LINKS' ],
category: 'Social',
usage: '[wallet|-] [bank|-]',
run: async (client, message, args, container) => profile.findById(message.author.id, (err, doc) => {
if (err){
return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`);
} else if (!doc || doc.data.economy.wallet === null){
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a *wallet* yet! To create one, type \`${container.Config.prefix[0]}register\`.`);
}
if (args.length < 2) {
args.push('-');
}
const [wallet, bank] = args;
if (!isNaN(wallet)){
doc.data.economy.wallet = wallet;
}
if (!isNaN(bank)){
doc.data.economy.bank = bank;
}
return doc.save()
.then(() => message.channel.send(`\\✔️ **${message.author.tag}**, Your wallet has been set to ${wallet === '-' ? doc.data.economy.wallet : wallet} and bank to ${bank === '-' ? doc.data.economy.bank : bank}`))
.catch(() => message.channel.send('`❌ [DATABASE_ERR]:` Unable to save the document to the database, please try again later!'));
})
};
/**
* @INFO
* Bot Coded by Bear#3437 | https://github.com/bearts
* @INFO
* Tamako Tech | https://tamako.tech/
* @INFO
*/
2 changes: 1 addition & 1 deletion src/Commands/MessageCommands/to-do/social/bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
} else if (doc.data.economy.bank !== null){
return message.channel.send(`\\❌ **${message.author.tag}**, You already have a bank account.\n`);
} else if (doc.data.economy.wallet < 2500){
return message.channel.send(`\\❌ **${message.author.tag}**, it seems like you don't have enough coins to register in a bank ((***${text.commatize(2500 - doc.data.economy.wallet)}** more coins are needed*).`);
return message.channel.send(`\\❌ **${message.author.tag}**, it seems like you don't have enough coins to register in a bank (***${text.commatize(2500 - doc.data.economy.wallet)}** more coins are needed*).`);
} else {
doc.data.economy.wallet = doc.data.economy.wallet - 2500;
doc.data.economy.bank = 2500;
Expand Down
36 changes: 18 additions & 18 deletions src/Commands/MessageCommands/to-do/social/bet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { join } = require('path');
const { setTimeout: delayFor } = require('timers/promises');
const profile = require(join(__dirname, '..', '..', '..', '..', 'Models', 'Profile.js'));
const text = require(join(__dirname, '..', '..', '..', '..', 'Utils', 'utilities.js'));

Expand All @@ -11,42 +12,41 @@ module.exports = {
userPermissions: ['SEND_MESSAGES'],
clientPermissions: [ 'EMBED_LINKS' ],
category: 'Social',
usage: '[amoun]',
usage: '[amount]',
run: async (client, message, [ amount ], container) => profile.findById(message.author.id, (err, doc) => {

if (err){
return message.channel.send(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`);
return message.reply(`\`❌ [DATABASE_ERR]:\` The database responded with error: ${err.name}`);
} else if (!doc || doc.data.economy.wallet === null){
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a *wallet* yet! To create one, type \`${container.Config.prefix[0]}register\`.`);
return message.reply(`\\❌ **${message.author.tag}**, You don't have a *wallet* yet! To create one, type \`${container.Config.prefix[0]}register\`.`);
} else if (!doc.data.economy.bank === null){
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have a **bank** yet! Won bets might be higher than wallet capacity depending on your bet amount.\nGet a bank first by typing \`${container.Config.prefix[0]}bank\`. You must have at least **2,500** coins to register to a bank!`);
return message.reply(`\\❌ **${message.author.tag}**, You don't have a **bank** yet! Won bets might be higher than wallet capacity depending on your bet amount.\nGet a bank first by typing \`${container.Config.prefix[0]}bank\`. You must have at least **2,500** coins to register to a bank!`);
} else if (isNaN(amount)){
return message.channel.send(`\\❌ **${message.author.tag}**, Please enter a valid amount.\nBets must be greater than **499** coins but less than **5,001**`);
return message.reply(`\\❌ **${message.author.tag}**, Please enter a valid amount.\nBets must be greater than **499** coins but less than **5,001**`);
} else if (amount < 500 || amount > 5000){
return message.channel.send(`\\❌ **${message.author.tag}**, Amount is out of range. \nBets must be greater than **499** coins but less than **5,001**`);
return message.reply(`\\❌ **${message.author.tag}**, Amount is out of range. \nBets must be greater than **499** coins but less than **5,001**`);
} else if (amount > doc.data.economy.wallet){
return message.channel.send(`\\❌ **${message.author.tag}**, You don't have enough coins in your wallet to proceed with that bet.\nGet more coins from your bank by typing \`${container.Config.prefix[0]}withdraw\`.`);
return message.reply(`\\❌ **${message.author.tag}**, You don't have enough coins in your wallet to proceed with that bet.\nGet more coins from your bank by typing \`${container.Config.prefix[0]}withdraw\`.`);
} else {

doc.data.economy.wallet = doc.data.economy.wallet - Math.floor(amount);

return doc.save()
.then(() => message.channel.send(`\\✔️ **${message.author.tag}**, Your **${Math.floor(amount)}** has been placed in a bet. Please wait 1 minute for the result.\nOdds for winning the bet is 1/3, and amount won are twice as large up to 10x as large as the original bet!`))
.then(() => message.reply(`\\✔️ **${message.author.tag}**, Your **${Math.floor(amount)}** has been placed in a bet. Please wait 1 minute for the result.\nOdds for winning the bet is 1/3, and amount won are twice as large up to 10x as large as the original bet!`))
.then(async () => {
await container.Discord.Util.delayFor(60000);
await delayFor(60000);

const won = Math.floor(Math.random() * 4) === 2 ? true : false;
const multiplier = Math.floor(Math.random() * 9) + 2;
const prize = amount * multiplier;

if (!won){
return message.channel.send(`\\❌ **${message.author.tag}**, You lost **${text.commatize(amount)}** coins from your previous bet!\nYou can get more reliable coins without using the bet command!`);
return message.reply(`\\❌ **${message.author.tag}**, You lost **${text.commatize(amount)}** coins from your previous bet!\nYou can get more reliable coins without using the bet command!`);
}

doc.data.economy.bank = doc.data.economy.bank + prize;
return doc.save()
.then(() => message.channel.send(`\\✔️ **${message.author.tag}**, You won **${text.commatize(amount)}** coins from your previous bet!\nYour bet **${Math.floor(amount)}** coins have multiplied by **${multiplier}**.\nYou'll receive **${text.commatize(prize)}** coins as the prize. Your winnings has been transferred to your bank!`))
.catch(() => message.channel.send(`\`❌ Oh no! ${message.author.tag}, The betting machine just broke! You lost **${text.commatize(amount)}** coins from your previous bet.\nThis doesn't usually happen. Please contact my developer if you receive this message.`));

return profile.findByIdAndUpdate(message.author.id, {$inc: { 'data.economy.bank': prize }}, {useFindAndModify: false})
.then(() => message.reply(`\\✔️ **${message.author.tag}**, You won **${text.commatize(amount)}** coins from your previous bet!\nYour bet **${Math.floor(amount)}** coins have multiplied by **${multiplier}**.\nYou'll receive **${text.commatize(prize)}** coins as the prize. Your winnings has been transferred to your bank!`))
.catch(() => message.reply(`\`❌ Oh no! ${message.author.tag}, The betting machine just broke! You lost **${text.commatize(amount)}** coins from your previous bet.\nThis doesn't usually happen. Please contact my developer if you receive this message.`));
}).catch(() => message.channel.send('`❌ [DATABASE_ERR]:` Unable to save the document to the database, please try again later!'));
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MessageCommands/to-do/social/daily.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
const now = Date.now();
const baseamount = 500;
const rewardables = market.filter(x => ![1,2].includes(x.id));
const supporter = await client.guilds.cache.get('744871453060759682').members.fetch(message.author.id).then(() => true).catch(() => false);
const supporter = await client.guilds.cache.get('744871453060759682')?.members.fetch(message.author.id).then(() => true).catch(() => false);
const item = rewardables[Math.floor(Math.random() * rewardables.length)];
let overflow = false, excess = null, streakreset = false, itemreward = false;

Expand Down
6 changes: 3 additions & 3 deletions src/Models/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = model('user_profiles', Schema({
inventory : {type: Array , default: [] }
},
economy: {
credits: { type: Number, default: 0 },
bank : { type: Number, default: 0 },
wallet : { type: Number, default: 0 },
credits: { type: Number, default: 0 }, // Not in use
bank : { type: Number, default: 0 }, // potentially should be default null
wallet : { type: Number, default: 0 }, // potentially should be default null
streak : {
alltime : { type: Number, default: 0 },
current : { type: Number, default: 0 },
Expand Down

0 comments on commit 7d3819c

Please sign in to comment.