├── .gitignore ├── v13-ExampleBot ├── .gitignore ├── src │ ├── commands │ │ ├── module.json │ │ ├── setitems.js │ │ ├── daily.js │ │ ├── beg.js │ │ ├── hafly.js │ │ ├── hourly.js │ │ ├── monthly.js │ │ ├── weekly.js │ │ ├── yearly.js │ │ ├── quaterly.js │ │ ├── shop.js │ │ ├── globalLb.js │ │ ├── leaderboard.js │ │ ├── work.js │ │ ├── balance.js │ │ ├── info.js │ │ ├── inventory.js │ │ ├── removeitem.js │ │ ├── suggest.js │ │ ├── setBankSpace.js │ │ ├── sell.js │ │ ├── buy.js │ │ ├── bulkAddMoney.js │ │ ├── bulkremovemoney.js │ │ ├── banknote.js │ │ ├── removeMoney.js │ │ ├── transfermoney.js │ │ ├── withdraw.js │ │ ├── addmoney.js │ │ ├── use.js │ │ ├── deposite.js │ │ ├── rob.js │ │ ├── gamble.js │ │ ├── additem.js │ │ └── slot.js │ ├── config.example.json │ ├── events │ │ └── interactionCreate.js │ └── index.js ├── readme.md └── package.json ├── v14-ExampleBot ├── .gitignore ├── src │ ├── commands │ │ ├── module.json │ │ ├── setitems.js │ │ ├── beg.js │ │ ├── hafly.js │ │ ├── hourly.js │ │ ├── monthly.js │ │ ├── weekly.js │ │ ├── daily.js │ │ ├── yearly.js │ │ ├── quaterly.js │ │ ├── work.js │ │ ├── balance.js │ │ ├── globalLb.js │ │ ├── leaderboard.js │ │ ├── info.js │ │ ├── inventory.js │ │ ├── removeitem.js │ │ ├── suggest.js │ │ ├── coinflip.js │ │ ├── setBankSpace.js │ │ ├── bulkAddMoney.js │ │ ├── bulkremovemoney.js │ │ ├── banknote.js │ │ ├── addmoney.js │ │ ├── removeMoney.js │ │ ├── buy.js │ │ ├── sell.js │ │ ├── transfermoney.js │ │ ├── withdraw.js │ │ ├── deposite.js │ │ ├── use.js │ │ ├── rob.js │ │ ├── gamble.js │ │ ├── crime.js │ │ ├── additem.js │ │ ├── transferItem.js │ │ ├── slot.js │ │ └── shop.js │ ├── config.example.json │ └── index.js └── package.json ├── .npmignore ├── .gitattributes ├── src ├── models │ ├── inventory.js │ └── currency.js ├── functions │ ├── informative.js │ ├── global.js │ ├── moneyMaking.js │ └── management.js └── index.js ├── .github └── workflows │ └── npm-publish.yml ├── README.md ├── package.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /v13-ExampleBot/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config.json -------------------------------------------------------------------------------- /v14-ExampleBot/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config.json -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "hide": false 3 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "hide": false 3 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *-ExampleBot 2 | package-lock.json 3 | .github 4 | node_modules -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /v13-ExampleBot/readme.md: -------------------------------------------------------------------------------- 1 | # This Example Bot is NO LONGER MAINTAINED 2 | ## Refer to V14 Example Bot. -------------------------------------------------------------------------------- /v14-ExampleBot/src/config.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "token": "BOT_TOKEN_HERE", 3 | "mongourl": "MONGO_DB_URL" 4 | } 5 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/config.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "token": "BOT_TOKEN_HERE", 3 | "mongourl": "MONGO_DB_URL", 4 | "guildID":"GUILD_ID_HERE_WHERE_SLASH_COMMANDS_ARE_SENT" 5 | } -------------------------------------------------------------------------------- /src/models/inventory.js: -------------------------------------------------------------------------------- 1 | const { 2 | Schema, 3 | model 4 | } = require("mongoose"); 5 | 6 | module.exports = model('Inventory-currency', new Schema({ 7 | guildID: { type: String, default: null }, 8 | inventory: { type: Array }, 9 | lastUpdated: { type: Date, default: new Date() }, 10 | })); -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | 3 | jobs: 4 | publish: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v1 8 | - uses: actions/setup-node@v1 9 | with: 10 | node-version: 14 11 | - run: npm install 12 | - uses: JS-DevTools/npm-publish@v1 13 | with: 14 | token: ${{ secrets.NPM_AUTH_TOKEN }} 15 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/events/interactionCreate.js: -------------------------------------------------------------------------------- 1 | const c = require('../index').client; 2 | module.exports = async inter => { 3 | if(inter.isCommand()) { 4 | console.log(`Interaction Created: ${inter.commandName}`); 5 | let slashCmds = c.SlashCmds.get(inter.commandName) 6 | if(slashCmds) return slashCmds.run(c, inter) 7 | else return inter.reply({ephemeral: true, text: `Command not found: ${inter.commandName}`}) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /v13-ExampleBot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplebot", 3 | "version": "1.0.0", 4 | "description": "This is a example bot on how to use the CurrencySystem package", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "npm i ../ && node src/index.js" 8 | }, 9 | "author": "BIntelligent", 10 | "license": "ISC", 11 | "dependencies": { 12 | "currency-system": "file:..", 13 | "discord.js": "^13.3.1", 14 | "mongoose": "^6.0.12" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v14-ExampleBot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examplebot", 3 | "version": "1.0.0", 4 | "description": "This is a example bot on how to use the CurrencySystem package", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "npm i ../ && node src/index.js" 8 | }, 9 | "author": "BIntelligent", 10 | "license": "ISC", 11 | "dependencies": { 12 | "currency-system": "file:..", 13 | "discord.js": "^14.7.1", 14 | "mongoose": "^6.8.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Templates 2 | This will go through all functions with example's 3 | See https://github.com/BIntelligent/currency-system/tree/main/v14-ExampleBot for a Example bot. 4 | # NEW! 5 | + Added `transferItems()`. 6 | # Bug reports 7 | Join our [Support Server](https://discord.gg/stERZwjA9m): 8 | Package Made by: `Be Intelligent#1715`. 9 | # Docs 10 | 📚 https://currency-system.js.org ( Outdated ik, please use github repo, its always maintained ) 11 | # For Global Economy 12 | To make it global, remove following line from every command 13 | ```js 14 | guild: interaction.guild, 15 | ``` 16 | and add 17 | ```js 18 | guild: { id : null } 19 | ``` -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/setitems.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | 6 | cs.setItems({ 7 | guild: interaction.guild, 8 | shop: [{ 9 | name: 'Watch', 10 | price: 20 11 | }, { 12 | name: 'Rolex', 13 | price: 1230 14 | }] 15 | }); 16 | return interaction.reply('Success!!') 17 | 18 | } 19 | 20 | module.exports.help = { 21 | name: "setitems", 22 | data: { 23 | name: "setitems", 24 | description: "A way to setItems", 25 | options: [] 26 | } 27 | }; 28 | 29 | module.exports.conf = { 30 | aliases: [], 31 | cooldown: 5 // This number is a seconds, not a milliseconds. 32 | // 1 = 1 seconds. 33 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/setitems.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | 6 | cs.setItems({ 7 | guild: interaction.guild, 8 | shop: [{ 9 | name: 'Watch', 10 | price: 20 11 | }, { 12 | name: 'Rolex', 13 | price: 1230 14 | }] 15 | }); 16 | return interaction.reply('Success!!') 17 | 18 | } 19 | 20 | module.exports.help = { 21 | name: "setitems", 22 | data: { 23 | name: "setitems", 24 | description: "A way to setItems", 25 | options: [] 26 | } 27 | }; 28 | 29 | module.exports.conf = { 30 | aliases: [], 31 | cooldown: 5 // This number is a seconds, not a milliseconds. 32 | // 1 = 1 seconds. 33 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/daily.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.daily({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used daily recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.daily}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "daily", 17 | data: { 18 | name: 'daily', 19 | description: "A way to Earn Money!", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/beg.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.beg({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | minAmount: 100, 9 | maxAmount: 400, 10 | cooldown: 10 // 60 seconds 11 | 12 | }); 13 | if (result.error) return interaction.reply(`You have begged recently Try again in ${result.time}`); 14 | else interaction.reply(`You have earned $${result.amount}.`) 15 | } 16 | 17 | module.exports.help = { 18 | name: "beg", 19 | data: { 20 | name: "beg", 21 | description: "a way to earn money, beg", 22 | options: [] 23 | } 24 | }; 25 | 26 | module.exports.conf = { 27 | aliases: [], 28 | cooldown: 5 // This number is a seconds, not a milliseconds. 29 | // 1 = 1 seconds. 30 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/hafly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.hafly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used hafly recently Try again in ${result.time}`); 12 | else return interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.hafly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "hafly", 17 | data: { 18 | name: 'hafly', 19 | description: "a way to earn money, hafly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/hourly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.hourly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | }); 10 | if (result.error) return interaction.reply(`You have used hourly recently Try again in ${result.time}`); 11 | else return interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.hourly}`); 12 | } 13 | 14 | module.exports.help = { 15 | name: "hourly", 16 | data: { 17 | name: 'hourly', 18 | description: "a way to earn money, hourly", 19 | options: [] 20 | } 21 | }; 22 | 23 | module.exports.conf = { 24 | aliases: [], 25 | cooldown: 5 // This number is a seconds, not a milliseconds. 26 | // 1 = 1 seconds. 27 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/monthly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.monthly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 6000, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used monthly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.monthly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "monthly", 17 | data: { 18 | name: 'monthly', 19 | description: "a way to earn money, monthly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/weekly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.weekly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used weekly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.weekly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "weekly", 17 | data: { 18 | name: 'weekly', 19 | description: "a way to earn money, weekly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/beg.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.beg({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | minAmount: 100, 9 | maxAmount: 400, 10 | cooldown: 10 // 60 seconds 11 | 12 | }); 13 | if (result.error) return interaction.reply(`You have begged recently Try again in ${result.time}`); 14 | else interaction.reply(`You have earned $${result.amount}.`) 15 | } 16 | 17 | module.exports.help = { 18 | name: "beg", 19 | data: { 20 | name: "beg", 21 | description: "a way to earn money, beg", 22 | options: [] 23 | } 24 | }; 25 | 26 | module.exports.conf = { 27 | aliases: [], 28 | cooldown: 5 // This number is a seconds, not a milliseconds. 29 | // 1 = 1 seconds. 30 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/hafly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.hafly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used hafly recently Try again in ${result.time}`); 12 | else return interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.hafly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "hafly", 17 | data: { 18 | name: 'hafly', 19 | description: "a way to earn money, hafly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/hourly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.hourly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | }); 10 | if (result.error) return interaction.reply(`You have used hourly recently Try again in ${result.time}`); 11 | else return interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.hourly}`); 12 | } 13 | 14 | module.exports.help = { 15 | name: "hourly", 16 | data: { 17 | name: 'hourly', 18 | description: "a way to earn money, hourly", 19 | options: [] 20 | } 21 | }; 22 | 23 | module.exports.conf = { 24 | aliases: [], 25 | cooldown: 5 // This number is a seconds, not a milliseconds. 26 | // 1 = 1 seconds. 27 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/monthly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.monthly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 6000, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used monthly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.monthly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "monthly", 17 | data: { 18 | name: 'monthly', 19 | description: "a way to earn money, monthly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/weekly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.weekly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used weekly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.weekly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "weekly", 17 | data: { 18 | name: 'weekly', 19 | description: "a way to earn money, weekly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/yearly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.yearly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 27000, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used yearly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.yearly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "yearly", 17 | data: { 18 | name: 'yearly', 19 | description: "a way to earn money, yearly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/daily.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | let result = await cs.daily({ 5 | user: interaction.user, 6 | guild: interaction.guild, 7 | amount: 100, 8 | }); 9 | if (result.error) 10 | return interaction.reply( 11 | `You have used daily recently Try again in ${result.time}` 12 | ); 13 | else 14 | interaction.reply( 15 | `You have earned $${result.amount}. Your streak is now ${result.rawData.streak.daily}` 16 | ); 17 | }; 18 | 19 | module.exports.help = { 20 | name: "daily", 21 | data: { 22 | name: "daily", 23 | description: "A way to Earn Money!", 24 | options: [], 25 | }, 26 | }; 27 | 28 | module.exports.conf = { 29 | aliases: [], 30 | cooldown: 5, // This number is a seconds, not a milliseconds. 31 | // 1 = 1 seconds. 32 | }; 33 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/yearly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.yearly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 27000, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used yearly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.yearly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "yearly", 17 | data: { 18 | name: 'yearly', 19 | description: "a way to earn money, yearly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/quaterly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.quaterly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used quaterly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.quaterly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "quaterly", 17 | data: { 18 | name: 'quaterly', 19 | description: "a way to earn money, quaterly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/quaterly.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.quaterly({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | amount: 100, 9 | 10 | }); 11 | if (result.error) return interaction.reply(`You have used quaterly recently Try again in ${result.time}`); 12 | else interaction.reply(`You have earned $${result.amount}. Your streak is now ${result.rawData.streak.quaterly}`); 13 | } 14 | 15 | module.exports.help = { 16 | name: "quaterly", 17 | data: { 18 | name: 'quaterly', 19 | description: "a way to earn money, quaterly", 20 | options: [] 21 | } 22 | }; 23 | 24 | module.exports.conf = { 25 | aliases: [], 26 | cooldown: 5 // This number is a seconds, not a milliseconds. 27 | // 1 = 1 seconds. 28 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "currency-system", 3 | "version": "2.8.9", 4 | "description": "An easy to use Currency System using Mongo DB.", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "doc": "jsdoc -c jsdoc.json", 8 | "start": "cd ./v14-ExampleBot && npm test" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/BIntelligent/currency-system.git", 13 | "homepage": "https://github.com/BIntelligent/currency-system/#README.md" 14 | }, 15 | "keywords": [ 16 | "currency", 17 | "level", 18 | "up", 19 | "system", 20 | "inventory", 21 | "money", 22 | "discord", 23 | "js", 24 | "discordjs", 25 | "currency-system", 26 | "economy", 27 | "eco", 28 | "ultrax", 29 | "mongoose", 30 | "mongodb" 31 | ], 32 | "author": "silent-coder", 33 | "license": "ISC", 34 | "dependencies": { 35 | "mongoose": "^5.13.15", 36 | "node-fetch": "^2.6.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/models/currency.js: -------------------------------------------------------------------------------- 1 | const { 2 | Schema, 3 | model 4 | } = require("mongoose"); 5 | const def = { 6 | type: Number, 7 | default: 0 8 | }; 9 | const def2 = { 10 | type: Number, 11 | default: 1 12 | }; 13 | module.exports = model('currency', new Schema({ 14 | userID: String, 15 | guildID: String, 16 | inventory: Array, 17 | wallet: def, 18 | bank: def, 19 | networth: def, 20 | lastUpdated: { 21 | type: Date, 22 | default: new Date() 23 | }, 24 | lastGamble: def, 25 | lastHourly: def, 26 | lastQuaterly: def, 27 | lastHafly: def, 28 | lastRob: def, 29 | lastDaily: def, 30 | lastWeekly: def, 31 | lastMonthly: def, 32 | lastYearly: def, 33 | lastBegged: def, 34 | lastWork: def, 35 | bankSpace: def, 36 | begTimeout: { 37 | type: Number, 38 | default: 240 39 | }, 40 | streak: { 41 | hourly: def2, 42 | daily: def2, 43 | weekly: def2, 44 | monthly: def2, 45 | yearly: def2, 46 | hafly: def2, 47 | quaterly: def2, 48 | } 49 | })); -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/shop.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | let result = await cs.getShopItems({ 6 | guild: interaction.guild 7 | }); 8 | let inv = result.inventory; 9 | const embed = new Discord.interactionEmbed() 10 | .setDescription('Shop!') 11 | for (let key in inv) { 12 | embed.addField(`${parseInt(key) + 1} - **${inv[key].name}:** for $${inv[key].price}`, 'Description: ' + inv[key].description) 13 | } 14 | interaction.reply({ 15 | embeds: [embed] 16 | }); 17 | } 18 | 19 | module.exports.help = { 20 | name: "shop", 21 | data: { 22 | name: 'shop', 23 | description: "A way to see shop", 24 | options: [] 25 | } 26 | }; 27 | 28 | module.exports.conf = { 29 | aliases: [], 30 | cooldown: 5 // This number is a seconds, not a milliseconds. 31 | // 1 = 1 seconds. 32 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/globalLb.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const Discord = require("discord.js"); 3 | const cs = new CurrencySystem; 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | let data = await cs.globalLeaderboard(); 7 | if (data.length < 1) return interaction.reply("Nobody's in Global leaderboard yet."); 8 | const msg = new Discord.interactionEmbed(); 9 | let pos = 0; 10 | // This is to get First 10 Users ) 11 | data.slice(0, 10).map(e => { 12 | if (!client.users.cache.get(e.userID)) return; 13 | pos++ 14 | msg.addField(`${pos} - **${client.users.cache.get(e.userID).username}**`, `Wallet: **${e.wallet}** - Bank: **${e.bank}**`, true); 15 | }); 16 | 17 | interaction.reply({ 18 | embeds: [msg] 19 | }).catch(); 20 | 21 | } 22 | 23 | module.exports.help = { 24 | name: "globallb", 25 | data: { 26 | name: 'globallb', 27 | description: "show's Global leaderboard.", 28 | options: [] 29 | } 30 | } 31 | 32 | module.exports.conf = { 33 | aliases: ["glb"], 34 | cooldown: 5 35 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/work.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.work({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | maxAmount: 100, 9 | replies: ['Programmer', 'Builder', 'Waiter', 'Busboy', 'Chief', 'Mechanic'], 10 | cooldown: 25 //25 seconds, 11 | 12 | }); 13 | if (result.error) return interaction.reply(`You have already worked recently Try again in ${result.time}`); 14 | else interaction.reply(`You worked as a ${result.workType} and earned $${result.amount}.`) 15 | } 16 | 17 | module.exports.help = { 18 | name: "work", 19 | data: { 20 | name: 'work', 21 | description: "A way to earn money", 22 | options: [] 23 | } 24 | }; 25 | 26 | module.exports.conf = { 27 | aliases: ["wk", "wr"], 28 | cooldown: 5 // This number is a seconds, not a milliseconds. 29 | // 1 = 1 seconds. 30 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/leaderboard.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const Discord = require("discord.js"); 3 | const cs = new CurrencySystem; 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | 7 | let data = await cs.leaderboard(interaction.guild.id); 8 | if (data.length < 1) return interaction.reply("Nobody's in leaderboard yet."); 9 | const msg = new Discord.interactionEmbed(); 10 | let pos = 0; 11 | // This is to get First 10 Users ) 12 | data.slice(0, 10).map(e => { 13 | if (!client.users.cache.get(e.userID)) return; 14 | pos++ 15 | msg.addField(`${pos} - **${client.users.cache.get(e.userID).username}**`, `Wallet: **${e.wallet}** - Bank: **${e.bank}**`, true); 16 | }); 17 | 18 | interaction.reply({ 19 | embeds: [msg] 20 | }).catch(); 21 | } 22 | 23 | module.exports.help = { 24 | name: "leaderboard", 25 | data: { 26 | name: 'leaderboard', 27 | description: "show's guild leaderboard.", 28 | options: [] 29 | } 30 | } 31 | 32 | module.exports.conf = { 33 | aliases: ["lb"], 34 | cooldown: 5 35 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/work.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let result = await cs.work({ 6 | user: interaction.user, 7 | guild: interaction.guild, 8 | maxAmount: 100, 9 | replies: ['Programmer', 'Builder', 'Waiter', 'Busboy', 'Chief', 'Mechanic'], 10 | cooldown: 25 //25 seconds, 11 | 12 | }); 13 | if (result.error) return interaction.reply(`You have already worked recently Try again in ${result.time}`); 14 | else interaction.reply(`You worked as a ${result.workType} and earned $${result.amount}. your streak is ${result.rawData.streak.weekly}`) 15 | } 16 | 17 | module.exports.help = { 18 | name: "work", 19 | data: { 20 | name: 'work', 21 | description: "A way to earn money", 22 | options: [] 23 | } 24 | }; 25 | 26 | module.exports.conf = { 27 | aliases: ["wk", "wr"], 28 | cooldown: 5 // This number is a seconds, not a milliseconds. 29 | // 1 = 1 seconds. 30 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/balance.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | const user = interaction.options.getUser('user') || interaction.user; 5 | let result = await cs.balance({ 6 | user: user, 7 | guild: interaction.guild.id 8 | }); 9 | return interaction.reply(`${user.tag}, has $${(result.wallet).toLocaleString()} in there wallet and $${(result.bank).toLocaleString()} in there bank. There Max bank has been set to $${(result.rawData.bankSpace.toLocaleString())}`); 10 | } 11 | 12 | module.exports.help = { 13 | name: "balance", 14 | data: { 15 | name: 'balance', 16 | description: "A way to know the amount of money in your bank.", 17 | options: [{ 18 | name: 'user', 19 | type: 6, 20 | description: 'The user you want to check balance of..', 21 | required: false, 22 | }] 23 | } 24 | } 25 | 26 | module.exports.conf = { 27 | aliases: ["bal"], 28 | cooldown: 5 29 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/balance.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | const user = interaction.options.getUser('user') || interaction.user; 5 | let result = await cs.balance({ 6 | user: user, 7 | guild: interaction.guild.id 8 | }); 9 | return interaction.reply(`${user.tag}, has $${(result.wallet).toLocaleString()} in there wallet and $${(result.bank).toLocaleString()} in there bank. There Max bank has been set to $${(result.rawData.bankSpace.toLocaleString())}`); 10 | } 11 | 12 | module.exports.help = { 13 | name: "balance", 14 | data: { 15 | name: 'balance', 16 | description: "A way to know the amount of money in your bank.", 17 | options: [{ 18 | name: 'user', 19 | type: 'USER', 20 | description: 'The user you want to check balance of..', 21 | required: false, 22 | }] 23 | } 24 | } 25 | 26 | module.exports.conf = { 27 | aliases: ["bal"], 28 | cooldown: 5 29 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/globalLb.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const Discord = require("discord.js"); 3 | const cs = new CurrencySystem(); 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | let data = await cs.globalLeaderboard(); 7 | if (data.length < 1) 8 | return interaction.reply("Nobody's in Global leaderboard yet."); 9 | const msg = new Discord.EmbedBuilder(); 10 | let pos = 0; 11 | // This is to get First 10 Users ) 12 | let arr = []; 13 | data.slice(0, 10).map((e) => { 14 | if (!client.users.cache.get(e.userID)) return; 15 | pos++; 16 | arr.push({ 17 | name: `${pos} - **${client.users.cache.get(e.userID).username}**`, 18 | value: `Wallet: **${e.wallet}** - Bank: **${e.bank}**`, 19 | inline: true, 20 | }); 21 | msg.addFields(arr); 22 | }); 23 | 24 | interaction 25 | .reply({ 26 | embeds: [msg], 27 | }) 28 | .catch(); 29 | }; 30 | 31 | module.exports.help = { 32 | name: "globallb", 33 | data: { 34 | name: "globallb", 35 | description: "show's Global leaderboard.", 36 | options: [], 37 | }, 38 | }; 39 | 40 | module.exports.conf = { 41 | aliases: ["glb"], 42 | cooldown: 5, 43 | }; 44 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/leaderboard.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const Discord = require("discord.js"); 3 | const cs = new CurrencySystem(); 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | let data = await cs.leaderboard(interaction.guild.id); 7 | if (data.length < 1) return interaction.reply("Nobody's in leaderboard yet."); 8 | const msg = new Discord.EmbedBuilder(); 9 | let pos = 0; 10 | // This is to get First 10 Users ) 11 | let arr = []; 12 | data.slice(0, 10).map((e) => { 13 | if (!client.users.cache.get(e.userID)) return; 14 | pos++; 15 | arr.push({ 16 | name: `${pos} - **${client.users.cache.get(e.userID).username}**`, 17 | value: `Wallet: **${e.wallet}** - Bank: **${e.bank}**`, 18 | inline: true, 19 | }); 20 | }); 21 | msg.addFields(arr); 22 | interaction 23 | .reply({ 24 | embeds: [msg], 25 | }) 26 | .catch(); 27 | }; 28 | 29 | module.exports.help = { 30 | name: "leaderboard", 31 | data: { 32 | name: "leaderboard", 33 | description: "show's guild leaderboard.", 34 | options: [], 35 | }, 36 | }; 37 | 38 | module.exports.conf = { 39 | aliases: ["lb"], 40 | cooldown: 5, 41 | }; 42 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/info.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | // Command Start's here 6 | let result = await cs.info(interaction.user.id, interaction.guild.id); 7 | const embed = new Discord.interactionEmbed() 8 | .setDescription('Info about ' + interaction.user.tag); 9 | let unUsed = ''; 10 | let cantBeUsed = ''; 11 | for (const [key, value] of result.info) { 12 | if (value.used) unUsed += `- ${key}\n`; 13 | else cantBeUsed += `- ${key} ( ${value.timeLeft} )\n`; 14 | } 15 | embed.addField('Commands That you can use:', unUsed || 'None'); 16 | embed.addField('Commands That you can\'t use:', cantBeUsed || 'None'); 17 | interaction.reply({ 18 | embeds: [embed] 19 | }) 20 | // Commands Stop's here. 21 | } 22 | 23 | module.exports.help = { 24 | name: "info", 25 | data: { 26 | name: 'info', 27 | description: "A way to info to shop", 28 | options: [] 29 | } 30 | }; 31 | 32 | module.exports.conf = { 33 | aliases: ['i'], 34 | cooldown: 5 // This number is a seconds, not a milliseconds. 35 | // 1 = 1 seconds. 36 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/info.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | // Command Start's here 6 | let result = await cs.info(interaction.user.id, interaction.guild.id); 7 | const embed = new Discord.EmbedBuilder() 8 | .setDescription('Info about ' + interaction.user.tag); 9 | let unUsed = ''; 10 | let cantBeUsed = ''; 11 | for (const [key, value] of result.info) { 12 | if (value.used) unUsed += `- ${key}\n`; 13 | else cantBeUsed += `- ${key} ( ${value.timeLeft} )\n`; 14 | } 15 | embed.addFields([ 16 | { name: 'Commands that you can use:', value: unUsed || 'None' }, 17 | { name: 'Commands that you can\'t use:', value: cantBeUsed || 'None' }, 18 | ]) 19 | interaction.reply({ 20 | embeds: [embed] 21 | }) 22 | // Commands Stop's here. 23 | } 24 | 25 | module.exports.help = { 26 | name: "info", 27 | data: { 28 | name: 'info', 29 | description: "A way to info to shop", 30 | options: [] 31 | } 32 | }; 33 | 34 | module.exports.conf = { 35 | aliases: ['i'], 36 | cooldown: 5 // This number is a seconds, not a milliseconds. 37 | // 1 = 1 seconds. 38 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/inventory.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | const user = interaction.options.getUser('user') || interaction.user; 6 | let result = await cs.getUserItems({ 7 | user: user, 8 | guild: interaction.guild, 9 | }); 10 | let inv = result.inventory.slice(0, 10) 11 | const embed = new Discord.interactionEmbed() 12 | .setDescription('Your Inventory in Empty!') 13 | for (key of inv) { 14 | embed.addField(`**${key.name}:**`, `Amount: ${key.amount}`); 15 | embed.setDescription('Your Inventory!') 16 | 17 | } 18 | return interaction.reply({ 19 | embeds: [embed] 20 | }) 21 | } 22 | 23 | module.exports.help = { 24 | name: "inventory", 25 | data: { 26 | name: 'inventory', 27 | description: "A way to see inventory", 28 | options: [{ 29 | name: 'user', 30 | type: 'USER', 31 | description: 'The user you want to check inventory of..', 32 | required: false, 33 | }] 34 | } 35 | }; 36 | 37 | module.exports.conf = { 38 | aliases: ['inv'], 39 | cooldown: 5 // This number is a seconds, not a milliseconds. 40 | // 1 = 1 seconds. 41 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/inventory.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem(); 4 | module.exports.run = async (client, interaction, args) => { 5 | const user = interaction.options.getUser("user") || interaction.user; 6 | let result = await cs.getUserItems({ 7 | user: user, 8 | guild: interaction.guild, 9 | }); 10 | let inv = result.inventory.slice(0, 10); 11 | const embed = new Discord.EmbedBuilder().setDescription( 12 | "Your Inventory in Empty!" 13 | ); 14 | let arr = []; 15 | for (key of inv) { 16 | arr.push({ name: `**${key.name}:**`, value: `Amount: ${key.amount}` }); 17 | embed.setDescription("Your Inventory!"); 18 | } 19 | embed.addFields(arr); 20 | return interaction.reply({ 21 | embeds: [embed], 22 | }); 23 | }; 24 | 25 | module.exports.help = { 26 | name: "inventory", 27 | data: { 28 | name: "inventory", 29 | description: "A way to see inventory", 30 | options: [ 31 | { 32 | name: "user", 33 | type: 6, 34 | description: "The user you want to check inventory of..", 35 | required: false, 36 | }, 37 | ], 38 | }, 39 | }; 40 | 41 | module.exports.conf = { 42 | aliases: ["inv"], 43 | cooldown: 5, // This number is a seconds, not a milliseconds. 44 | // 1 = 1 seconds. 45 | }; 46 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/removeitem.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | if (!args[0].value) return interaction.reply('Which item to remove?') 6 | let result = await cs.removeItem({ 7 | guild: interaction.guild, 8 | item: parseInt(args[0].value) 9 | }); 10 | if (result.error) { 11 | if (result.type == 'Invalid-Item-Number') return interaction.reply('There was a error, Please enter item number to remove.!') 12 | if (result.type == 'Unknown-Item') return interaction.reply('There was a error, The Item Does not exist!') 13 | } else interaction.reply('Done! Successfully removed the `' + result.inventory.name + '` from shop!') 14 | 15 | 16 | 17 | } 18 | 19 | module.exports.help = { 20 | name: "removeitem", 21 | data: { 22 | name: 'removeitem', 23 | description: "A way to removeItem to shop", 24 | options: [{ 25 | name: 'item', 26 | type: 4, 27 | description: 'Item number you want to remove', 28 | required: false, 29 | }] 30 | } 31 | }; 32 | 33 | module.exports.conf = { 34 | aliases: [], 35 | cooldown: 5 // This number is a seconds, not a milliseconds. 36 | // 1 = 1 seconds. 37 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/suggest.js: -------------------------------------------------------------------------------- 1 | const { 2 | interactionActionRow, 3 | interactionButton, 4 | EmbedBuilder, 5 | interactionAttachment 6 | } = require('discord.js'); 7 | module.exports.run = async (client, interaction, args) => { 8 | //const channel = interaction.options.getChannel('channel'); 9 | // const query = interaction.options.getString('suggestion'); 10 | // console.log(args) 11 | const channel = args[0].channel; 12 | const query = args[1].value; 13 | const embed = new EmbedBuilder() 14 | .setTitle('Suggestion') 15 | .setDescription(query) 16 | .setColor(0x00AE86) 17 | .setTimestamp(); 18 | 19 | await channel.send({ 20 | embeds: [embed] 21 | }); 22 | interaction.reply({ 23 | content: 'Suggestion sent!', 24 | ephemeral: true 25 | }); 26 | } 27 | 28 | module.exports.help = { 29 | name: "suggest", 30 | data: { 31 | name: 'suggest', 32 | description: "suggest stuff here", 33 | options: [{ 34 | name: 'channel', 35 | type: 7, 36 | description: 'Channel you want to send suggestion in', 37 | required: true, 38 | }, { 39 | name: 'suggestion', 40 | type: 3, 41 | description: 'Suggestion itself', 42 | required: true, 43 | }] 44 | } 45 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/removeitem.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | if (!args[0].value) return interaction.reply('Which item to remove?') 6 | let result = await cs.removeItem({ 7 | guild: interaction.guild, 8 | item: parseInt(args[0].value) 9 | }); 10 | if (result.error) { 11 | if (result.type == 'Invalid-Item-Number') return interaction.reply('There was a error, Please enter item number to remove.!') 12 | if (result.type == 'Unknown-Item') return interaction.reply('There was a error, The Item Does not exist!') 13 | } else interaction.reply('Done! Successfully removed the `' + result.inventory.name + '` from shop!') 14 | 15 | 16 | 17 | } 18 | 19 | module.exports.help = { 20 | name: "removeitem", 21 | data: { 22 | name: 'removeitem', 23 | description: "A way to removeItem to shop", 24 | options: [{ 25 | name: 'item', 26 | type: 'INTEGER', 27 | description: 'Item number you want to remove', 28 | required: false, 29 | }] 30 | } 31 | }; 32 | 33 | module.exports.conf = { 34 | aliases: [], 35 | cooldown: 5 // This number is a seconds, not a milliseconds. 36 | // 1 = 1 seconds. 37 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/coinflip.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | await interaction.reply("Flipping the coin..."); 5 | let UChoice = args.get("choice"); 6 | if (Math.floor(Math.random() * 10) > 5) { 7 | // 50 -50 chance 8 | // lets say 6-10 is heads 9 | if (UChoice === "heads") { 10 | await interaction.editReply(`Horray You Won!`); 11 | } else { 12 | await interaction.editReply(`Uh, You Lost!`); 13 | } 14 | } else { 15 | // lets say 1-5 is tails 16 | if (UChoice === "tails") { 17 | await interaction.editReply(`Horray You Won!`); 18 | } else { 19 | await interaction.editReply(`Uh, You Lost!`); 20 | } 21 | } 22 | }; 23 | 24 | module.exports.help = { 25 | name: "coinflip", 26 | data: { 27 | name: "coinflip", 28 | description: "A way to earn money by betting.", 29 | options: [ 30 | { 31 | name: "choice", 32 | type: 3, 33 | description: "With Side You Choose?", 34 | required: true, 35 | choices: [ 36 | { 37 | name: "heads", 38 | value: "heads", 39 | }, 40 | { 41 | name: "tails", 42 | value: "tails", 43 | }, 44 | ], 45 | }, 46 | ], 47 | }, 48 | }; 49 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/suggest.js: -------------------------------------------------------------------------------- 1 | const { 2 | interactionActionRow, 3 | interactionButton, 4 | interactionEmbed, 5 | interactionAttachment 6 | } = require('discord.js'); 7 | module.exports.run = async (client, interaction, args) => { 8 | //const channel = interaction.options.getChannel('channel'); 9 | // const query = interaction.options.getString('suggestion'); 10 | // console.log(args) 11 | const channel = args[0].channel; 12 | const query = args[1].value; 13 | const embed = new interactionEmbed() 14 | .setTitle('Suggestion') 15 | .setDescription(query) 16 | .setColor('RANDOM') 17 | .setTimestamp(); 18 | 19 | await channel.send({ 20 | embeds: [embed] 21 | }); 22 | interaction.reply({ 23 | content: 'Suggestion sent!', 24 | ephemeral: true 25 | }); 26 | } 27 | 28 | module.exports.help = { 29 | name: "suggest", 30 | data: { 31 | name: 'suggest', 32 | description: "suggest stuff here", 33 | options: [{ 34 | name: 'channel', 35 | type: 'CHANNEL', 36 | description: 'Channel you want to send suggestion in', 37 | required: true, 38 | }, { 39 | name: 'suggestion', 40 | type: 'STRING', 41 | description: 'Suggestion itself', 42 | required: true, 43 | }] 44 | } 45 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/setBankSpace.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | const user = interaction.options.getUser('user') || interaction.user; 5 | 6 | let result = await cs.setBankSpace(user.id, interaction.guild.id, interaction.options.getInteger('amount') || 0); 7 | if (result.error) { 8 | if (result.type === 'no-amount-provided') return interaction.reply('Please provide number to setBank Limit to.'); 9 | else return interaction.reply('Something went wrong., maybe same amount provided'); 10 | } else return interaction.reply(`Successfully set Bank Limit of ${user.tag} to ${result.amount}`) 11 | 12 | } 13 | 14 | module.exports.help = { 15 | name: "setbankspace", 16 | data: { 17 | name: 'setbankspace', 18 | description: "A way to know the amount of money in your bank.", 19 | options: [{ 20 | name: 'user', 21 | type: 6, 22 | description: 'The user you want to set bank space of..', 23 | required: true, 24 | }, { 25 | name: 'amount', 26 | type: 4, 27 | description: 'Amount fo bank space you want to set.', 28 | required: true, 29 | }] 30 | } 31 | } 32 | 33 | module.exports.conf = { 34 | aliases: ["sets"], 35 | cooldown: 5 36 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/setBankSpace.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | const user = interaction.options.getUser('user') || interaction.user; 5 | 6 | let result = await cs.setBankSpace(user.id, interaction.guild.id, interaction.options.getInteger('amount') || 0); 7 | if (result.error) { 8 | if (result.type === 'no-amount-provided') return interaction.reply('Please provide number to setBank Limit to.'); 9 | else return interaction.reply('Something went wrong., maybe same amount provided'); 10 | } else return interaction.reply(`Successfully set Bank Limit of ${user.tag} to ${result.amount}`) 11 | 12 | } 13 | 14 | module.exports.help = { 15 | name: "setbankspace", 16 | data: { 17 | name: 'setbankspace', 18 | description: "A way to know the amount of money in your bank.", 19 | options: [{ 20 | name: 'user', 21 | type: 'USER', 22 | description: 'The user you want to set bank space of..', 23 | required: true, 24 | }, { 25 | name: 'amount', 26 | type: 'INTEGER', 27 | description: 'Amount fo bank space you want to set.', 28 | required: true, 29 | }] 30 | } 31 | } 32 | 33 | module.exports.conf = { 34 | aliases: ["sets"], 35 | cooldown: 5 36 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/sell.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem(); 4 | module.exports.run = async (client, interaction, args) => { 5 | if (!args[0].value) return interaction.reply("Which item to remove?"); 6 | let result = await cs.removeUserItem({ 7 | user: interaction.user, 8 | guild: interaction.guild, 9 | item: parseInt(args[0].value), 10 | amount: 1, 11 | }); 12 | if (result.error) { 13 | if (result.type == "Invalid-Item-Number") 14 | return interaction.reply( 15 | "There was a error, Please enter item number to remove.!" 16 | ); 17 | if (result.type == "Unknown-Item") 18 | return interaction.reply("There was a error, The Item Does not exist!"); 19 | } else 20 | interaction.reply( 21 | "Done! Successfully sold the `" + 22 | result.inventory.name + 23 | "` for free! You now have " + 24 | result.inventory.amount + 25 | " of those items left!" 26 | ); 27 | }; 28 | 29 | module.exports.help = { 30 | name: "sell", 31 | data: { 32 | name: "sell", 33 | description: "A way to sell item", 34 | options: [ 35 | { 36 | name: "item", 37 | type: "INTEGER", 38 | description: "Item Number from Inventory", 39 | required: true, 40 | }, 41 | ], 42 | }, 43 | }; 44 | 45 | module.exports.conf = { 46 | aliases: [], 47 | cooldown: 5, // This number is a seconds, not a milliseconds. 48 | // 1 = 1 seconds. 49 | }; 50 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/buy.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | let thing = args[0].value 6 | if (!thing) return interaction.reply('Please provide item number') 7 | if (isNaN(thing)) return interaction.reply('Please provide valid item number') 8 | let result = await cs.buy({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | item: parseInt(args[0].value) 12 | }); 13 | if (result.error) { 14 | if (result.type === 'No-Item') return interaction.reply('Please provide valid item number'); 15 | if (result.type === 'Invalid-Item') return interaction.reply('item does not exists'); 16 | if (result.type === 'low-money') return interaction.reply(`**You don't have enough balance to buy this item!**`); 17 | } else return interaction.reply(`**Successfully bought \`${result.inventory.name}\` for $${result.inventory.price}**`) 18 | 19 | } 20 | 21 | module.exports.help = { 22 | name: "buy", 23 | data: { 24 | name: 'buy', 25 | description: "A way to Buy stuff from shop!", 26 | options: [{ 27 | name: 'item', 28 | type: 'INTEGER', 29 | description: 'Item Number from the shop.', 30 | required: true, 31 | }] 32 | } 33 | }; 34 | 35 | module.exports.conf = { 36 | aliases: ['b'], 37 | cooldown: 5 // This number is a seconds, not a milliseconds. 38 | // 1 = 1 seconds. 39 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/bulkAddMoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let wheretoPutMoney = args.get('where_to_put_money'); 5 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 6 | else wheretoPutMoney = 'wallet'; 7 | let amount = args.get('amount') 8 | let money = parseInt(amount); 9 | let result = await cs.addMoneyToAllUsers({ 10 | guild: interaction.guild.id, 11 | amount: money, 12 | wheretoPutMoney: wheretoPutMoney 13 | }); 14 | if (result.error) { 15 | if (result.type === 'negative-money') return interaction.reply("You cant add negitive money"); 16 | else return interaction.reply('No User\'s found'); 17 | } else interaction.reply(`Successfully added $${money} to ${result.rawData.length} people!, ( in ${wheretoPutMoney} )`) 18 | } 19 | 20 | module.exports.help = { 21 | name: "addmoneytoallusers", 22 | data: { 23 | name: 'addmoneytoallusers', 24 | description: "A way to add the amount of money in everyone's bank or wallet.", 25 | options: [{ 26 | name: 'amount', 27 | type: 4, 28 | description: 'Amount of money you want to add.', 29 | required: true, 30 | }, 31 | { 32 | name: 'where_to_put_money', 33 | type: 5, 34 | description: 'TRUE means bank, FALSE means wallet.', 35 | required: true, 36 | } 37 | ] 38 | } 39 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/bulkAddMoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let wheretoPutMoney = args.get('where_to_put_money'); 5 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 6 | else wheretoPutMoney = 'wallet'; 7 | let amount = args.get('amount') 8 | let money = parseInt(amount); 9 | let result = await cs.addMoneyToAllUsers({ 10 | guild: interaction.guild.id, 11 | amount: money, 12 | wheretoPutMoney: wheretoPutMoney 13 | }); 14 | if (result.error) { 15 | if (result.type === 'negative-money') return interaction.reply("You cant add negitive money"); 16 | else return interaction.reply('No User\'s found'); 17 | } else interaction.reply(`Successfully added $${money} to ${result.rawData.length} people!, ( in ${wheretoPutMoney} )`) 18 | } 19 | 20 | module.exports.help = { 21 | name: "addmoneytoallusers", 22 | data: { 23 | name: 'addmoneytoallusers', 24 | description: "A way to add the amount of money in everyone's bank or wallet.", 25 | options: [{ 26 | name: 'amount', 27 | type: 'INTEGER', 28 | description: 'Amount of money you want to add.', 29 | required: true, 30 | }, 31 | { 32 | name: 'where_to_put_money', 33 | type: 'BOOLEAN', 34 | description: 'TRUE means bank, FALSE means wallet.', 35 | required: true, 36 | } 37 | ] 38 | } 39 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/bulkremovemoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let wheretoPutMoney = args.get('where_to_put_money'); 5 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 6 | else wheretoPutMoney = 'wallet'; 7 | let amount = args.get('amount') 8 | let money = parseInt(amount); 9 | let result = await cs.removeMoneyFromAllUsers({ 10 | guild: interaction.guild.id, 11 | amount: money, 12 | wheretoPutMoney: wheretoPutMoney 13 | }); 14 | if (result.error) { 15 | if (result.type === 'negative-money') return interaction.reply("You cant remove negitive money"); 16 | else return interaction.reply('No User\'s found'); 17 | } else interaction.reply(`Successfully removed $${money} from ${result.rawData.length} people!, ( in ${wheretoPutMoney} )`) 18 | } 19 | 20 | module.exports.help = { 21 | name: "removemoneyfromallusers", 22 | data: { 23 | name: 'removemoneyfromallusers', 24 | description: "A way to remove the amount of money in everyone's bank or wallet.", 25 | options: [{ 26 | name: 'amount', 27 | type: 4, 28 | description: 'Amount of money you want to remove.', 29 | required: true, 30 | }, 31 | { 32 | name: 'where_to_put_money', 33 | type: 5, 34 | description: 'TRUE means bank, FALSE means wallet.', 35 | required: true, 36 | } 37 | ] 38 | } 39 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/bulkremovemoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let wheretoPutMoney = args.get('where_to_put_money'); 5 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 6 | else wheretoPutMoney = 'wallet'; 7 | let amount = args.get('amount') 8 | let money = parseInt(amount); 9 | let result = await cs.removeMoneyFromAllUsers({ 10 | guild: interaction.guild.id, 11 | amount: money, 12 | wheretoPutMoney: wheretoPutMoney 13 | }); 14 | if (result.error) { 15 | if (result.type === 'negative-money') return interaction.reply("You cant remove negitive money"); 16 | else return interaction.reply('No User\'s found'); 17 | } else interaction.reply(`Successfully removed $${money} from ${result.rawData.length} people!, ( in ${wheretoPutMoney} )`) 18 | } 19 | 20 | module.exports.help = { 21 | name: "removemoneyfromallusers", 22 | data: { 23 | name: 'removemoneyfromallusers', 24 | description: "A way to remove the amount of money in everyone's bank or wallet.", 25 | options: [{ 26 | name: 'amount', 27 | type: 'INTEGER', 28 | description: 'Amount of money you want to remove.', 29 | required: true, 30 | }, 31 | { 32 | name: 'where_to_put_money', 33 | type: 'BOOLEAN', 34 | description: 'TRUE means bank, FALSE means wallet.', 35 | required: true, 36 | } 37 | ] 38 | } 39 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/banknote.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction) => { 4 | const arr = await cs.getUserItems({ 5 | user: interaction.user, 6 | guild: interaction.guild.id, 7 | }); 8 | if (!arr.inventory.length) 9 | return interaction.reply("You don't have any banknotes!"); 10 | for (i in arr.inventory) { 11 | if (arr.inventory[i].name.toLowerCase().includes("banknote")) { 12 | i++; 13 | const removeItem = await cs.removeUserItem({ 14 | user: interaction.user, 15 | item: i, 16 | guild: interaction.guild.id, 17 | amount: 1, 18 | }); 19 | if (removeItem.error) { 20 | console.log("Bot tried to remove item number " + i); 21 | return interaction.reply("Unknown error occured see console."); 22 | } 23 | const ToincreasedAmount = 5000 + removeItem.rawData.bankSpace; 24 | const result = await cs.setBankSpace( 25 | interaction.user.id, 26 | interaction.guild.id, 27 | ToincreasedAmount 28 | ); 29 | if (!result.error) 30 | return interaction.reply(`Successfully set Bank Limit to ${result.amount}`); 31 | else return interaction.reply(`Error: occured: ${result.error}`); 32 | } else return interaction.reply("Please buy the item first!"); 33 | } 34 | }; 35 | 36 | module.exports.help = { 37 | name: "banknote", 38 | data: { 39 | name: "banknote", 40 | description: "A way to increase bank money limit!", 41 | options: [], 42 | }, 43 | }; 44 | 45 | module.exports.conf = { 46 | aliases: [], 47 | cooldown: 5, // This number is a seconds, not a milliseconds. 48 | // 1 = 1 seconds. 49 | }; 50 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/banknote.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction) => { 4 | const arr = await cs.getUserItems({ 5 | user: interaction.user, 6 | guild: interaction.guild.id 7 | }); 8 | if (!arr.inventory.length) return interaction.reply("You don't have any banknotes!"); 9 | for (i in arr.inventory) { 10 | if (arr.inventory[i].name.toLowerCase().includes('banknote')) { 11 | i++ 12 | const removeItem = await cs.removeUserItem({ 13 | user: interaction.user, 14 | item: i, 15 | guild: interaction.guild.id 16 | }); 17 | if (removeItem.error) { 18 | console.log('Bot tried to remove item number ' + i) 19 | return interaction.reply("Unknown error occured see console.") 20 | }; 21 | const ToincreasedAmount = 5000 + removeItem.rawData.bankSpace; 22 | const result = await cs.setBankSpace(interaction.user.id, interaction.guild.id, ToincreasedAmount); 23 | if (!result.error) return interaction.reply(`Successfully set Bank Limit to ${result.amount}`); 24 | else return interaction.reply(`Error: occured: ${result.error}`); 25 | 26 | } else return interaction.reply("Please buy the item first!") 27 | }; 28 | } 29 | 30 | module.exports.help = { 31 | name: "banknote", 32 | data: { 33 | name: "banknote", 34 | description: "A way to increase bank money limit!", 35 | options: [] 36 | } 37 | }; 38 | 39 | module.exports.conf = { 40 | aliases: [], 41 | cooldown: 5 // This number is a seconds, not a milliseconds. 42 | // 1 = 1 seconds. 43 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/addmoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[2]?.member || interaction.member; 5 | if (!interaction.member.permissions.has("ADMINISTRATOR")) 6 | return interaction.reply("You do not have requied permissions."); 7 | let wheretoPutMoney = args.get("to"); 8 | let amount = args.get("amount"); 9 | let money = parseInt(amount); 10 | let result = await cs.addMoney({ 11 | user: user, 12 | guild: interaction.guild, 13 | amount: money, 14 | wheretoPutMoney: wheretoPutMoney, 15 | }); 16 | if (result.error) return interaction.reply("You cant add negitive money"); 17 | else 18 | interaction.reply( 19 | `Successfully added $${money} to ${user.user.username}, ( in ${wheretoPutMoney} )` 20 | ); 21 | }; 22 | 23 | module.exports.help = { 24 | name: "addmoney", 25 | data: { 26 | name: "addmoney", 27 | description: "A way to add the amount of money in your bank or wallet.", 28 | options: [ 29 | { 30 | name: "amount", 31 | type: 4, 32 | description: "Amount of money you want to add.", 33 | required: true, 34 | }, 35 | { 36 | name: "to", 37 | type: 3, 38 | description: "Where to add money to?", 39 | required: true, 40 | choices: [ 41 | { 42 | name: "wallet", 43 | value: "wallet", 44 | }, 45 | { 46 | name: "bank", 47 | value: "bank", 48 | }, 49 | ], 50 | }, 51 | { 52 | name: "user", 53 | type: 6, 54 | description: "The user you want to add money to.", 55 | required: false, 56 | }, 57 | ], 58 | }, 59 | }; 60 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/removeMoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[2].member || interaction.member; 5 | if (!interaction.member.permissions.has('ADMINISTRATOR')) return interaction.reply("You do not have requied permissions.") 6 | let wheretoPutMoney = args.get('where_to_put_money'); 7 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 8 | else wheretoPutMoney = 'wallet'; 9 | let amount = args.get('amount') 10 | let money = parseInt(amount); 11 | let result = await cs.removeMoney({ 12 | user: user, 13 | guild: interaction.guild, 14 | amount: money, 15 | wheretoPutMoney: wheretoPutMoney 16 | }); 17 | if (result.error) return interaction.reply("You cant remove negitive money"); 18 | else interaction.reply(`Successfully removed $${money} to ${user.user.username}, ( from ${wheretoPutMoney} )`) 19 | } 20 | 21 | module.exports.help = { 22 | name: "removemoney", 23 | data: { 24 | name: 'removemoney', 25 | description: "A way to remove the amount of money from bank or wallet.", 26 | options: [{ 27 | name: 'amount', 28 | type: 'INTEGER', 29 | description: 'Amount of money you want to remove.', 30 | required: true, 31 | }, 32 | { 33 | name: 'where_to_put_money', 34 | type: 'BOOLEAN', 35 | description: 'TRUE means bank, FALSE means wallet.', 36 | required: true, 37 | }, 38 | { 39 | name: 'user', 40 | type: 'USER', 41 | description: 'The user you want to remove money to.', 42 | required: false, 43 | } 44 | ] 45 | } 46 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/removeMoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[2]?.member || interaction.member; 5 | if (!interaction.member.permissions.has("ADMINISTRATOR")) 6 | return interaction.reply("You do not have requied permissions."); 7 | let wheretoPutMoney = args.get("from"); 8 | let amount = args.get("amount"); 9 | let result = await cs.removeMoney({ 10 | user: user, 11 | guild: interaction.guild, 12 | amount: amount, 13 | wheretoPutMoney: wheretoPutMoney, 14 | }); 15 | if (result.error) return interaction.reply("You cant remove negitive money"); 16 | else 17 | interaction.reply( 18 | `Successfully removed $${ 19 | amount === "all" ? "all money" : `${amount}` 20 | } from ${user.user.username}, ( from ${wheretoPutMoney} )` 21 | ); 22 | }; 23 | 24 | module.exports.help = { 25 | name: "removemoney", 26 | data: { 27 | name: "removemoney", 28 | description: "A way to remove the amount of money from bank or wallet.", 29 | options: [ 30 | { 31 | name: "amount", 32 | type: 3, 33 | description: "Amount of money you want to remove.", 34 | required: true, 35 | }, 36 | { 37 | name: "from", 38 | type: 3, 39 | description: "Where to remove money from?", 40 | required: true, 41 | choices: [ 42 | { 43 | name: "wallet", 44 | value: "wallet", 45 | }, 46 | { 47 | name: "bank", 48 | value: "bank", 49 | }, 50 | ], 51 | }, 52 | { 53 | name: "user", 54 | type: 6, 55 | description: "The user you want to remove money to.", 56 | required: false, 57 | }, 58 | ], 59 | }, 60 | }; 61 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/buy.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem(); 4 | module.exports.run = async (client, interaction, args) => { 5 | let thing = args[0].value; 6 | if (!thing) return interaction.reply("Please provide item number"); 7 | if (isNaN(thing)) return interaction.reply("Please provide valid item number"); 8 | let result = await cs.buy({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | item: parseInt(args[0].value), 12 | amount: args[1]?.value || 1, 13 | }); 14 | if (result.error) { 15 | if (result.type === "No-Item") 16 | return interaction.reply("Please provide valid item number"); 17 | if (result.type === "Invalid-Item") 18 | return interaction.reply("item does not exists"); 19 | if (result.type === "low-money") 20 | return interaction.reply( 21 | `**You don't have enough balance to buy this item!**` 22 | ); 23 | if (result.type === "Invalid-Amount") 24 | return interaction.channel.send("Can't add less than 1 item."); 25 | } else 26 | return interaction.reply( 27 | `**Successfully bought ${args[1]?.value || 1} of \`${ 28 | result.inventory.name 29 | }\` for $${result.price}**` 30 | ); 31 | }; 32 | 33 | module.exports.help = { 34 | name: "buy", 35 | data: { 36 | name: "buy", 37 | description: "A way to Buy stuff from shop!", 38 | options: [ 39 | { 40 | name: "item", 41 | type: 4, 42 | description: "Item Number from the shop.", 43 | required: true, 44 | }, 45 | { 46 | name: "amount", 47 | type: 3, 48 | description: "Amount of Items to buy!", 49 | required: false, 50 | }, 51 | ], 52 | }, 53 | }; 54 | 55 | module.exports.conf = { 56 | aliases: ["b"], 57 | cooldown: 5, // This number is a seconds, not a milliseconds. 58 | // 1 = 1 seconds. 59 | }; 60 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/sell.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem(); 4 | module.exports.run = async (client, interaction, args) => { 5 | if (!args[0].value) return interaction.reply("Which item to remove?"); 6 | let amount = 1; 7 | if (args[1] && args[1].value) amount = args[1].value; 8 | let result = await cs.removeUserItem({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | item: parseInt(args[0].value), 12 | amount: amount, 13 | }); 14 | if (result.error) { 15 | if (result.type == "Invalid-Item-Number") 16 | return interaction.reply( 17 | "There was a error, Please enter item number to remove.!" 18 | ); 19 | if (result.type == "Unknown-Item") 20 | return interaction.reply("There was a error, The Item Does not exist!"); 21 | if (result.type == "Invalid-Amount") 22 | return interaction.reply("Invalid Number of items to remove."); 23 | if (result.type == "Negative-Amount") 24 | return interaction.reply("Can't Remove Less than 1 item. Smh!"); 25 | } else 26 | interaction.reply( 27 | `Done! Successfully sold \`${result.inventory.deleted}\` of \`${result.inventory.name}\` for free! You now have \`${result.inventory.count}\` of those items left!` 28 | ); 29 | }; 30 | 31 | module.exports.help = { 32 | name: "sell", 33 | data: { 34 | name: "sell", 35 | description: "A way to sell item", 36 | options: [ 37 | { 38 | name: "item", 39 | type: 4, 40 | description: "Item Number from Inventory", 41 | required: true, 42 | }, 43 | { 44 | name: "amount", 45 | type: 3, 46 | description: "Amount of Item or all", 47 | required: false, 48 | }, 49 | ], 50 | }, 51 | }; 52 | 53 | module.exports.conf = { 54 | aliases: [], 55 | cooldown: 5, // This number is a seconds, not a milliseconds. 56 | // 1 = 1 seconds. 57 | }; 58 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/transfermoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = interaction.options.getUser('user'); 5 | if (user.id === interaction.user.id) return interaction.channel.send(`You can't transfer money to yourself!`); 6 | 7 | let amount = interaction.options.getInteger('amount'); 8 | 9 | if (!amount) return interaction.reply("Enter amount of money to add."); 10 | if (String(amount).includes("-")) return interaction.reply("You can't send negitive money.") 11 | let money = parseInt(amount); 12 | 13 | let result = await cs.transferMoney({ 14 | user: interaction.user, 15 | user2: user, 16 | guild: interaction.guild, 17 | amount: money 18 | }); 19 | if (result.error) return interaction.reply(`You don't have enough money in your wallet.`); 20 | else interaction.reply(`**${interaction.user.username}**, Successfully transfered **${result.money}** to **${result.user2.username}**`) 21 | 22 | } 23 | 24 | module.exports.help = { 25 | name: "transfer", 26 | data: { 27 | name: 'transfer', 28 | description: "A way to transfer money", 29 | options: [{ 30 | name: 'amount', 31 | type: 4, 32 | description: 'amount to transfer', 33 | required: true, 34 | }, 35 | { 36 | name: 'user', 37 | type: 6, 38 | description: 'user to trasnfer money to', 39 | required: true, 40 | } 41 | ] 42 | } 43 | 44 | }; 45 | 46 | module.exports.conf = { 47 | aliases: ["pay"], 48 | cooldown: 5 // This number is a seconds, not a milliseconds. 49 | // 1 = 1 seconds. 50 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/transfermoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = interaction.options.getUser('user'); 5 | if (user.id === interaction.user.id) return interaction.channel.send(`You can't transfer money to yourself!`); 6 | 7 | let amount = interaction.options.getInteger('amount'); 8 | 9 | if (!amount) return interaction.reply("Enter amount of money to add."); 10 | if (String(amount).includes("-")) return interaction.reply("You can't send negitive money.") 11 | let money = parseInt(amount); 12 | 13 | let result = await cs.transferMoney({ 14 | user: interaction.user, 15 | user2: user, 16 | guild: interaction.guild, 17 | amount: money 18 | }); 19 | if (result.error) return interaction.reply(`You don't have enough money in your wallet.`); 20 | else interaction.reply(`**${interaction.user.username}**, Successfully transfered **${result.money}** to **${result.user2.username}**`) 21 | 22 | } 23 | 24 | module.exports.help = { 25 | name: "transfer", 26 | data: { 27 | name: 'transfer', 28 | description: "A way to transfer money", 29 | options: [{ 30 | name: 'amount', 31 | type: 'INTEGER', 32 | description: 'amount to transfer', 33 | required: true, 34 | }, 35 | { 36 | name: 'user', 37 | type: 'USER', 38 | description: 'user to trasnfer money to', 39 | required: true, 40 | } 41 | ] 42 | } 43 | 44 | }; 45 | 46 | module.exports.conf = { 47 | aliases: ["pay"], 48 | cooldown: 5 // This number is a seconds, not a milliseconds. 49 | // 1 = 1 seconds. 50 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/withdraw.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let money = args[0].value 6 | if (!money) return interaction.reply("Enter the amount you want to withdraw."); 7 | 8 | let result = await cs.withdraw({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | amount: money 12 | }); 13 | if (result.error) { 14 | if (result.type === 'money') return interaction.reply("Specify an amount to withdraw") 15 | if (result.type === 'negative-money') return interaction.reply("You can't withdraw negative money, please use deposit command") 16 | if (result.type === 'low-money') return interaction.reply("You don't have that much money in bank.") 17 | if (result.type === 'no-money') return interaction.reply("You don't have any money to withdraw") 18 | } else { 19 | if (result.type === 'all-success') return interaction.reply("You have withdraw'd all your money from your bank" + `\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.`) 20 | if (result.type === 'success') return interaction.reply(`You have withdraw $${result.amount} money from your bank.\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.`) 21 | 22 | } 23 | } 24 | 25 | module.exports.help = { 26 | name: "withdraw", 27 | data: { 28 | name: 'withdraw', 29 | description: "A way to get money out of the bank.", 30 | options: [{ 31 | name: 'amount', 32 | type: 'INTEGER', 33 | description: 'Amount of money to withdraw.', 34 | required: true, 35 | }] 36 | } 37 | } 38 | 39 | module.exports.conf = { 40 | aliases: ["wd"], 41 | cooldown: 5 42 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/withdraw.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | let money = args[0].value; 5 | if (!money) return interaction.reply("Enter the amount you want to withdraw."); 6 | 7 | let result = await cs.withdraw({ 8 | user: interaction.user, 9 | guild: interaction.guild, 10 | amount: money, 11 | }); 12 | if (result.error) { 13 | if (result.type === "money") 14 | return interaction.reply("Specify an amount to withdraw"); 15 | if (result.type === "negative-money") 16 | return interaction.reply( 17 | "You can't withdraw negative money, please use deposit command" 18 | ); 19 | if (result.type === "low-money") 20 | return interaction.reply("You don't have that much money in bank."); 21 | if (result.type === "no-money") 22 | return interaction.reply("You don't have any money to withdraw"); 23 | } else { 24 | if (result.type === "all-success") 25 | return interaction.reply( 26 | "You have withdraw'd all your money from your bank" + 27 | `\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.` 28 | ); 29 | if (result.type === "success") 30 | return interaction.reply( 31 | `You have withdraw $${result.amount} money from your bank.\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.` 32 | ); 33 | } 34 | }; 35 | 36 | module.exports.help = { 37 | name: "withdraw", 38 | data: { 39 | name: "withdraw", 40 | description: "A way to get money out of the bank.", 41 | options: [ 42 | { 43 | name: "amount", 44 | type: require("discord.js").ApplicationCommandOptionType.String, 45 | description: "Amount of money to withdraw.", 46 | required: true, 47 | }, 48 | ], 49 | }, 50 | }; 51 | 52 | module.exports.conf = { 53 | aliases: ["wd"], 54 | cooldown: 5, 55 | }; 56 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/addmoney.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[2].member || interaction.member; 5 | if (!interaction.member.permissions.has('ADMINISTRATOR')) return interaction.reply("You do not have requied permissions.") 6 | let wheretoPutMoney = args.get('where_to_put_money'); 7 | if (wheretoPutMoney) wheretoPutMoney = 'bank'; 8 | else wheretoPutMoney = 'wallet'; 9 | let amount = args.get('amount') 10 | let money = parseInt(amount); 11 | let result = await cs.addMoney({ 12 | user: user, 13 | guild: interaction.guild, 14 | amount: money, 15 | wheretoPutMoney: wheretoPutMoney 16 | }); 17 | if (result.error) return interaction.reply("You cant add negitive money"); 18 | else interaction.reply(`Successfully added $${money} to ${user.user.username}, ( in ${wheretoPutMoney} )`) 19 | } 20 | 21 | module.exports.help = { 22 | name: "addmoney", 23 | data: { 24 | name: 'addmoney', 25 | description: "A way to add the amount of money in your bank or wallet.", 26 | options: [{ 27 | name: 'amount', 28 | type: 'INTEGER', 29 | description: 'Amount of money you want to add.', 30 | required: true, 31 | }, 32 | { 33 | name: 'where_to_put_money', 34 | type: 'BOOLEAN', 35 | description: 'TRUE means bank, FALSE means wallet.', 36 | required: true, 37 | }, 38 | { 39 | name: 'user', 40 | type: 'USER', 41 | description: 'The user you want to add money to.', 42 | required: false, 43 | } 44 | ] 45 | } 46 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/use.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | // !use 5 | let item = args[0].value; 6 | if (!item) return interaction.reply("What item you wana use?"); 7 | if (parseInt(item)) 8 | return interaction.reply("Please use the name of the item, not the ID."); 9 | let haveItem = false; 10 | const arr = await cs.getUserItems({ 11 | user: interaction.user, 12 | guild: interaction.guild, 13 | }); 14 | let i; 15 | for (key in arr.inventory) { 16 | if (arr.inventory[key].name.toLowerCase().includes(item.toLowerCase())) 17 | haveItem = true; 18 | i = key; 19 | } 20 | if (haveItem) { 21 | let money = Math.floor(Math.random() * 10 + 1) * 100; // 100 - 1000 22 | let result = await cs.addMoney({ 23 | user: interaction.user, 24 | guild: interaction.guild, 25 | amount: money, 26 | wheretoPutMoney: "wallet", 27 | }); 28 | let r2 = await cs.removeUserItem({ 29 | user: interaction.user, 30 | guild: interaction.guild, 31 | item: i + 1, 32 | amount: 1, 33 | }); 34 | if (result.error || r2.error) { 35 | console.log(result); 36 | console.log(r2); 37 | return interaction.reply("Unknown error occured see console."); 38 | } else 39 | return interaction.reply("You've used " + item + " and earned $" + money); 40 | } else return interaction.reply("Please buy the item first!"); 41 | }; 42 | 43 | module.exports.help = { 44 | name: "use", 45 | data: { 46 | name: "use", 47 | description: "A way to use", 48 | options: [ 49 | { 50 | name: "item", 51 | type: "STRING", 52 | description: "Item Name of item which you want to use", 53 | required: true, 54 | }, 55 | ], 56 | }, 57 | }; 58 | 59 | module.exports.conf = { 60 | aliases: [], 61 | cooldown: 5, // This number is a seconds, not a milliseconds. 62 | // 1 = 1 seconds. 63 | }; 64 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/deposite.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | module.exports.run = async (client, interaction, args) => { 4 | let money = args[0].value; 5 | if (!money) return interaction.reply("Enter the amount you want to deposite."); 6 | 7 | let result = await cs.deposite({ 8 | user: interaction.user, 9 | guild: interaction.guild, 10 | amount: money, 11 | }); 12 | if (result.error) { 13 | if (result.type === "money") 14 | return interaction.reply("Specify an amount to deposite"); 15 | if (result.type === "negative-money") 16 | return interaction.reply("You can't deposite negative money"); 17 | if (result.type === "low-money") 18 | return interaction.reply("You don't have that much money in wallet."); 19 | if (result.type === "no-money") 20 | return interaction.reply("You don't have any money to deposite"); 21 | if (result.type === "bank-full") 22 | return interaction.reply("Your bank is full. It has reached it's limit."); 23 | } else { 24 | if (result.type === "all-success") 25 | return interaction.reply( 26 | "You have deposited all your money to your bank" + 27 | `\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.` 28 | ); 29 | if (result.type === "success") 30 | return interaction.reply( 31 | `You have deposited $${result.amount} money to your bank.\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.` 32 | ); 33 | } 34 | }; 35 | 36 | module.exports.help = { 37 | name: "deposite", 38 | data: { 39 | name: "deposite", 40 | description: "A way to get money in of the bank.", 41 | options: [ 42 | { 43 | name: "amount", 44 | type: require("discord.js").ApplicationCommandOptionType.String, 45 | description: "Amount of money you want to deposite.", 46 | required: true, 47 | }, 48 | ], 49 | }, 50 | }; 51 | 52 | module.exports.conf = { 53 | aliases: ["dep"], 54 | cooldown: 5, 55 | }; 56 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/deposite.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let money = args[0].value 6 | if (!money) return interaction.reply("Enter the amount you want to deposite."); 7 | 8 | let result = await cs.deposite({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | amount: money 12 | }); 13 | if (result.error) { 14 | if (result.type === 'money') return interaction.reply("Specify an amount to deposite"); 15 | if (result.type === 'negative-money') return interaction.reply("You can't deposite negative money"); 16 | if (result.type === 'low-money') return interaction.reply("You don't have that much money in wallet."); 17 | if (result.type === 'no-money') return interaction.reply("You don't have any money to deposite"); 18 | if (result.type === 'bank-full') return interaction.reply("Your bank is full. It has reached it's limit."); 19 | } else { 20 | if (result.type === 'all-success') return interaction.reply("You have deposited all your money to your bank" + `\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.`); 21 | if (result.type === 'success') return interaction.reply(`You have deposited $${result.amount} money to your bank.\nNow you've $${result.rawData.wallet} In your wallet and $${result.rawData.bank} in your bank.`); 22 | }; 23 | } 24 | 25 | module.exports.help = { 26 | name: "deposite", 27 | data: { 28 | name: 'deposite', 29 | description: "A way to get money in of the bank.", 30 | options: [{ 31 | name: 'amount', 32 | type: 'INTEGER', 33 | description: 'Amount of money you want to deposite.', 34 | required: true, 35 | }] 36 | } 37 | } 38 | 39 | module.exports.conf = { 40 | aliases: ["dep"], 41 | cooldown: 5 42 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/use.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | // !use 5 | let item = args[0].value; 6 | if (!item) return interaction.reply("What item you wana use?") 7 | if (parseInt(item)) return interaction.reply("Please use the name of the item, not the ID.") 8 | let haveItem = false; 9 | const arr = await cs.getUserItems({ 10 | user: interaction.user, 11 | guild: interaction.guild, 12 | }); 13 | let i; 14 | for (key in arr.inventory) { 15 | if (arr.inventory[key].name.toLowerCase().includes(item.toLowerCase())) haveItem = true 16 | i = key; 17 | }; 18 | if (haveItem) { 19 | let money = Math.floor((Math.random() * 10) + 1) * 100 // 100 - 1000 20 | let result = await cs.addMoney({ 21 | user: interaction.user, 22 | guild: interaction.guild, 23 | amount: money, 24 | wheretoPutMoney: 'wallet' 25 | }); 26 | let r2 = await cs.removeUserItem({ 27 | user: interaction.user, 28 | guild: interaction.guild, 29 | item: i + 1, 30 | amount: 1 31 | }); 32 | if (result.error || r2.error) { 33 | console.log(result); 34 | console.log(r2); 35 | return interaction.reply("Unknown error occured see console.") 36 | } else return interaction.reply("You've used " + item + " and earned $" + money) 37 | 38 | } else return interaction.reply("Please buy the item first!") 39 | } 40 | 41 | 42 | module.exports.help = { 43 | name: "use", 44 | data: { 45 | name: 'use', 46 | description: "A way to use", 47 | options: [{ 48 | name: 'item', 49 | type: 3, 50 | description: 'Item Name of item which you want to use', 51 | required: true, 52 | }] 53 | } 54 | }; 55 | 56 | module.exports.conf = { 57 | aliases: [], 58 | cooldown: 5 // This number is a seconds, not a milliseconds. 59 | // 1 = 1 seconds. 60 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/rob.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[0].user 5 | if (user.bot || user === client.user) return interaction.reply("This user is a bot."); 6 | if (!user) return interaction.reply('Sorry, you forgot to mention somebody.'); 7 | 8 | let result = await cs.rob({ 9 | user: interaction.user, 10 | user2: user, 11 | guild: interaction.guild, 12 | minAmount: 100, 13 | successPercentage: 5, 14 | cooldown: 25, //25 seconds, 15 | maxRob: 1000 16 | }); 17 | if (result.error) { 18 | if (result.type === 'time') return interaction.reply(`You have already robbed recently Try again in ${result.time}`); 19 | if (result.type === 'low-money') return interaction.reply(`You need atleast $${result.minAmount} to rob somebody.`); 20 | if (result.type === 'low-wallet') return interaction.reply(`${result.user2.username} have less than $${result.minAmount} to rob.`) 21 | if (result.type === 'caught') return interaction.reply(`${interaction.user.username} you robbed ${result.user2.username} and got caught and you payed ${result.amount} to ${result.user2.username}!`) 22 | } else { 23 | if (result.type === 'success') return interaction.reply(`${interaction.user.username} you robbed ${result.user2.username} and got away with ${result.amount}!`) 24 | 25 | } 26 | 27 | } 28 | 29 | module.exports.help = { 30 | name: "rob", 31 | data: { 32 | name: 'rob', 33 | description: "A way to earn money", 34 | options: [{ 35 | name: 'user', 36 | type: 6, 37 | description: 'The user you want to rob..', 38 | required: true, 39 | }] 40 | } 41 | }; 42 | 43 | module.exports.conf = { 44 | aliases: [], 45 | cooldown: 5 // This number is a seconds, not a milliseconds. 46 | // 1 = 1 seconds. 47 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/rob.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | let user = args[0].user 5 | if (user.bot || user === client.user) return interaction.reply("This user is a bot."); 6 | if (!user) return interaction.reply('Sorry, you forgot to mention somebody.'); 7 | 8 | let result = await cs.rob({ 9 | user: interaction.user, 10 | user2: user, 11 | guild: interaction.guild, 12 | minAmount: 100, 13 | successPercentage: 5, 14 | cooldown: 25, //25 seconds, 15 | maxRob: 1000 16 | }); 17 | if (result.error) { 18 | if (result.type === 'time') return interaction.reply(`You have already robbed recently Try again in ${result.time}`); 19 | if (result.type === 'low-money') return interaction.reply(`You need atleast $${result.minAmount} to rob somebody.`); 20 | if (result.type === 'low-wallet') return interaction.reply(`${result.user2.username} have less than $${result.minAmount} to rob.`) 21 | if (result.type === 'caught') return interaction.reply(`${interaction.user.username} you robbed ${result.user2.username} and got caught and you payed ${result.amount} to ${result.user2.username}!`) 22 | } else { 23 | if (result.type === 'success') return interaction.reply(`${interaction.user.username} you robbed ${result.user2.username} and got away with ${result.amount}!`) 24 | 25 | } 26 | 27 | } 28 | 29 | module.exports.help = { 30 | name: "rob", 31 | data: { 32 | name: 'rob', 33 | description: "A way to earn money", 34 | options: [{ 35 | name: 'user', 36 | type: 'USER', 37 | description: 'The user you want to rob..', 38 | required: true, 39 | }] 40 | } 41 | }; 42 | 43 | module.exports.conf = { 44 | aliases: [], 45 | cooldown: 5 // This number is a seconds, not a milliseconds. 46 | // 1 = 1 seconds. 47 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/gamble.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let money = args[0].value 6 | if (isNaN(money)) return interaction.reply("Amount is not a number."); 7 | 8 | let result = await cs.gamble({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | amount: money, 12 | minAmount: 1, 13 | cooldown: 25 //25 seconds 14 | }); 15 | if (result.error) { 16 | if (result.type == 'amount') return interaction.reply("Please insert an amount first."); 17 | if (result.type == 'nan') return interaction.reply("The amount was not a number."); 18 | if (result.type == 'low-money') return interaction.reply(`You don't have enough money. You need ${result.neededMoney}$ more to perform the action. `); 19 | if (result.type == 'gamble-limit') return interaction.reply(`You don't have enough money for gambling. The minimum was $${result.minAmount}.`); 20 | if (result.type == 'time') return interaction.reply(`Wooo that is too fast. You need to wait **${result.second}** second(s) before you can gamble again.`); 21 | } else { 22 | if (result.type == 'lost') return interaction.reply(`Ahh, no. You lose $${result.amount}. You've $${result.wallet} left. Good luck next time.`); 23 | if (result.type == 'won') return interaction.reply(`Woohoo! You won $${result.amount}! You've $${result.wallet}. Good luck, have fun!`); 24 | } 25 | } 26 | 27 | module.exports.help = { 28 | name: "gamble", 29 | data: { 30 | name: 'gamble', 31 | description: "An efficient way to double your money.", 32 | options: [{ 33 | name: 'amount', 34 | type: 4, 35 | description: 'Amount of money you want to gamble.', 36 | required: true, 37 | }] 38 | } 39 | } 40 | 41 | module.exports.conf = { 42 | aliases: ["gambling"], 43 | cooldown: 5 44 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/gamble.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | module.exports.run = async (client, interaction, args) => { 4 | 5 | let money = args[0].value 6 | if (isNaN(money)) return interaction.reply("Amount is not a number."); 7 | 8 | let result = await cs.gamble({ 9 | user: interaction.user, 10 | guild: interaction.guild, 11 | amount: money, 12 | minAmount: 1, 13 | cooldown: 25 //25 seconds 14 | }); 15 | if (result.error) { 16 | if (result.type == 'amount') return interaction.reply("Please insert an amount first."); 17 | if (result.type == 'nan') return interaction.reply("The amount was not a number."); 18 | if (result.type == 'low-money') return interaction.reply(`You don't have enough money. You need ${result.neededMoney}$ more to perform the action. `); 19 | if (result.type == 'gamble-limit') return interaction.reply(`You don't have enough money for gambling. The minimum was $${result.minAmount}.`); 20 | if (result.type == 'time') return interaction.reply(`Wooo that is too fast. You need to wait **${result.second}** second(s) before you can gamble again.`); 21 | } else { 22 | if (result.type == 'lost') return interaction.reply(`Ahh, no. You lose $${result.amount}. You've $${result.wallet} left. Good luck next time.`); 23 | if (result.type == 'won') return interaction.reply(`Woohoo! You won $${result.amount}! You've $${result.wallet}. Good luck, have fun!`); 24 | } 25 | } 26 | 27 | module.exports.help = { 28 | name: "gamble", 29 | data: { 30 | name: 'gamble', 31 | description: "An efficient way to double your money.", 32 | options: [{ 33 | name: 'amount', 34 | type: 'INTEGER', 35 | description: 'Amount of money you want to gamble.', 36 | required: true, 37 | }] 38 | } 39 | } 40 | 41 | module.exports.conf = { 42 | aliases: ["gambling"], 43 | cooldown: 5 44 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/crime.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | const Discord = require("discord.js"); 4 | let collection = new Discord.Collection(); 5 | module.exports.run = async (client, interaction, args) => { 6 | if (collection.has(interaction.user.id)) 7 | return interaction.reply( 8 | `You Recently tried this command. please try again in ${cs.parseSeconds( 9 | Math.floor( 10 | 60 - (Date.now() - collection.get(interaction.user.id)) / 1000 11 | ) 12 | )}` 13 | ); 14 | await interaction.reply("Robbing the bank..."); 15 | let chance = Math.random() * 100 < 10; /* percentage */ 16 | collection.set(interaction.user.id, Date.now()); 17 | // User can re run after 1 minute. 18 | setTimeout(() => collection.delete(interaction.user.id), 60000); 19 | let data = await cs.balance({ 20 | user: interaction.user.id, 21 | guild: interaction.guild.id, 22 | }); 23 | let amount = Math.floor(Math.random() * 10000); // Random Number under 10k 24 | if (data.wallet < amount) amount = data.wallet; 25 | if (amount < 1) 26 | return interaction.editReply("You need some money to try crime."); 27 | if (chance) { 28 | // lived. 29 | interaction.editReply({ 30 | content: `Successfully robbed the bank and got away with \`$${amount}\``, 31 | }); 32 | await cs.addMoney({ 33 | user: interaction.user.id, 34 | guild: interaction.guild.id, 35 | amount: amount, 36 | wheretoPutMoney: "wallet", 37 | }); 38 | } else { 39 | // was caught 40 | interaction.editReply({ 41 | content: `Fudge, You robbed the bank and Police arrived in time. They Took \`$${amount}\` in compensation.`, 42 | }); 43 | await cs.removeMoney({ 44 | user: interaction.user.id, 45 | guild: interaction.guild.id, 46 | amount: amount, 47 | wheretoPutMoney: "wallet", 48 | }); 49 | } 50 | }; 51 | 52 | module.exports.help = { 53 | name: "crime", 54 | data: { 55 | name: "crime", 56 | description: "Earn Money By Crime", 57 | options: [], 58 | }, 59 | }; 60 | 61 | module.exports.conf = { 62 | aliases: [], 63 | cooldown: 5, // This number is a seconds, not a milliseconds. 64 | // 1 = 1 seconds. 65 | }; 66 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/additem.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | await interaction.deferReply(); 6 | if (interaction.options.getInteger('price') < 1) return interaction.editReply("You can't add an item for less than 1$!"); 7 | let result = await cs.addItem({ 8 | guild: interaction.guild, 9 | inventory: { 10 | name: interaction.options.getString('name'), 11 | price: interaction.options.getInteger('price'), 12 | description: interaction.options.getString('description') || 'No Description' 13 | } 14 | }); 15 | if (result.error) { 16 | if (result.type == 'No-Inventory-Name') return interaction.editReply('There was a error, Please enter item name to add.!') 17 | if (result.type == 'Invalid-Inventory-Price') return interaction.editReply('There was a error, invalid price!') 18 | if (result.type == 'No-Inventory-Price') return interaction.editReply('There was a error, You didnt specify price!') 19 | if (result.type == 'No-Inventory') return interaction.editReply('There was a error, No data recieved!') 20 | } else return interaction.editReply('Done! Successfully added `' + interaction.options.getString('name') + '` to the shop!') 21 | 22 | 23 | 24 | } 25 | 26 | module.exports.help = { 27 | name: "additem", 28 | data: { 29 | name: 'additem', 30 | description: "A way to additem to shop", 31 | options: [{ 32 | name: 'name', 33 | type: 3, 34 | description: 'Name of Item.', 35 | required: true, 36 | }, { 37 | name: 'price', 38 | type: 4, 39 | description: 'Price of item', 40 | required: true, 41 | }, 42 | 43 | { 44 | name: 'description', 45 | type: 3, 46 | description: 'Description of the item. (Can\'t be Changed later.)', 47 | required: false, 48 | } 49 | ] 50 | } 51 | }; 52 | 53 | module.exports.conf = { 54 | aliases: [], 55 | cooldown: 5 // This number is a seconds, not a milliseconds. 56 | // 1 = 1 seconds. 57 | } -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/additem.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js') 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem; 4 | module.exports.run = async (client, interaction, args) => { 5 | await interaction.deferReply(); 6 | if (interaction.options.getInteger('price') < 1) return interaction.editReply("You can't add an item for less than 1$!"); 7 | let result = await cs.addItem({ 8 | guild: interaction.guild, 9 | inventory: { 10 | name: interaction.options.getString('name'), 11 | price: interaction.options.getInteger('price'), 12 | description: interaction.options.getString('description') || 'No Description' 13 | } 14 | }); 15 | if (result.error) { 16 | if (result.type == 'No-Inventory-Name') return interaction.editReply('There was a error, Please enter item name to add.!') 17 | if (result.type == 'Invalid-Inventory-Price') return interaction.editReply('There was a error, invalid price!') 18 | if (result.type == 'No-Inventory-Price') return interaction.editReply('There was a error, You didnt specify price!') 19 | if (result.type == 'No-Inventory') return interaction.editReply('There was a error, No data recieved!') 20 | } else return interaction.editReply('Done! Successfully added `' + interaction.options.getString('name') + '` to the shop!') 21 | 22 | 23 | 24 | } 25 | 26 | module.exports.help = { 27 | name: "additem", 28 | data: { 29 | name: 'additem', 30 | description: "A way to additem to shop", 31 | options: [{ 32 | name: 'name', 33 | type: 'STRING', 34 | description: 'Name of Item.', 35 | required: true, 36 | }, { 37 | name: 'price', 38 | type: 'INTEGER', 39 | description: 'Price of item', 40 | required: true, 41 | }, 42 | 43 | { 44 | name: 'description', 45 | type: 'STRING', 46 | description: 'Description of the item. (Can\'t be Changed later.)', 47 | required: false, 48 | } 49 | ] 50 | } 51 | }; 52 | 53 | module.exports.conf = { 54 | aliases: [], 55 | cooldown: 5 // This number is a seconds, not a milliseconds. 56 | // 1 = 1 seconds. 57 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/transferItem.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const CurrencySystem = require("currency-system"); 3 | const cs = new CurrencySystem(); 4 | module.exports.run = async (client, interaction, args) => { 5 | let thing = args.get("item"); 6 | if (!thing) return interaction.reply("Please provide item number"); 7 | if (isNaN(thing)) 8 | return interaction.reply("Please provide valid item number"); 9 | let result = await cs.transferItem({ 10 | user1: interaction.user.id, 11 | user2: args.get("user"), 12 | guild: interaction.guild.id, 13 | item: parseInt(thing), 14 | amount: args.get("amount") || 1, 15 | }); 16 | if (result.error) { 17 | if (result.type === "No-Item") 18 | return interaction.reply("Please provide valid item number"); 19 | if (result.type === "Invalid-Item") 20 | return interaction.reply("Invalid Item Number."); 21 | if (result.type === "Invalid-Amount") 22 | return interaction.reply("You can't transfer less than 1 item(s)."); 23 | if (result.type === "In-Sufficient-Amount") 24 | return interaction.reply( 25 | "You're trying to transfer more items than you have." 26 | ); 27 | } else 28 | return interaction.reply( 29 | `Successfully transfered \`${result.transfered}\` \`${ 30 | result.itemName 31 | }\`'s to \`${ 32 | client.users.cache.get(args.get("user")).tag 33 | }\`. Now You have \`${ 34 | result.itemsLeft === 0 ? "no" : result.itemsLeft 35 | }\` items remianing.` 36 | ); 37 | }; 38 | 39 | module.exports.help = { 40 | name: "transferitem", 41 | data: { 42 | name: "transferitem", 43 | description: "Share Item's with your friends.", 44 | options: [ 45 | { 46 | name: "user", 47 | type: 6, 48 | description: "User to whom you'll send items to.", 49 | required: true, 50 | }, 51 | { 52 | name: "item", 53 | type: 4, 54 | description: "Item Number from the shop.", 55 | required: true, 56 | }, 57 | { 58 | name: "amount", 59 | type: 3, 60 | description: "Amount of Items to transfer!", 61 | required: true, 62 | }, 63 | ], 64 | }, 65 | }; 66 | 67 | module.exports.conf = { 68 | aliases: [], 69 | cooldown: 5, // This number is a seconds, not a milliseconds. 70 | // 1 = 1 seconds. 71 | }; 72 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/commands/slot.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | const Discord = require("discord.js"); 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | // Slots code Start here: 7 | const ifLostmoney = 5000; 8 | const user = await cs.findUser({ 9 | user: interaction.author, 10 | guild: interaction.guild 11 | }); 12 | 13 | if (user.wallet < ifLostmoney) return interaction.channel.send(`You don't have enough money to play this game. You need $${Math.abs(user.wallet - ifLostmoney)} more to play.`); 14 | /* SPIN ANIMATION*/ 15 | const slotemoji = ":money_mouth:"; // You can even use animated emojis! 16 | /* ITEMS (SLOTS) */ 17 | let items = ['💵', '💍', '💯']; 18 | /* RANDOM */ 19 | let $ = items[Math.floor(items.length * Math.random())]; 20 | let $$ = items[Math.floor(items.length * Math.random())]; 21 | let $$$ = items[Math.floor(items.length * Math.random())]; 22 | /* EMBEDS */ 23 | 24 | const play = new Discord.interactionEmbed() 25 | .setTitle("Slot Machine") 26 | .setDescription("• " + slotemoji + " " + slotemoji + " " + slotemoji + " •") 27 | .setColor('RANDOM') 28 | .setFooter("Are you lucky?") 29 | 30 | const $1 = new Discord.interactionEmbed() 31 | .setTitle("Slot Machine") 32 | .setDescription("• " + $ + " " + slotemoji + " " + slotemoji + " •") 33 | .setColor('RANDOM') 34 | .setFooter("Are you lucky?") 35 | 36 | const $2 = new Discord.interactionEmbed() 37 | .setTitle("Slot Machine") 38 | .setDescription("• " + $ + " " + $$ + " " + slotemoji + " •") 39 | .setColor('RANDOM') 40 | .setFooter("Are you lucky?") 41 | 42 | 43 | const $3 = new Discord.interactionEmbed() 44 | .setTitle("Slot Machine") 45 | .setDescription("• " + $ + " " + $$ + " " + $$$ + " •") 46 | .setColor('RANDOM') 47 | .setFooter("Are you lucky?") 48 | 49 | /* SPIN THE SLOTS */ 50 | await interaction.deferReply(); 51 | interaction.followUp({ 52 | embeds: [play] 53 | }); 54 | setTimeout(() => { 55 | interaction.editReply({ 56 | embeds: [$1] 57 | }); 58 | }, 600); 59 | setTimeout(() => { 60 | interaction.editReply({ 61 | embeds: [$2] 62 | }); 63 | }, 1200); 64 | setTimeout(() => { 65 | interaction.editReply({ 66 | embeds: [$3] 67 | }); 68 | }, 1800); 69 | 70 | /* DEDUCT RESULTS */ 71 | if ($$ !== $ && $$ !== $$$) { 72 | setTimeout(async () => { 73 | let result = await cs.removeMoney({ 74 | user: interaction.user, 75 | guild: interaction.guild, // { id: null } 76 | amount: ifLostmoney, 77 | }); 78 | interaction.followUp(`Shit, ${interaction.user.tag} you lost $${money}! You now have $${result.rawData.wallet} in your wallet!`); 79 | }, 3000); 80 | 81 | } else if ($ === $$ && $ === $$$) { 82 | setTimeout(async () => { 83 | const money = 10000; 84 | let result = await cs.addMoney({ 85 | user: interaction.user, 86 | guild: interaction.guild, // { id: null } 87 | amount: money, 88 | }); 89 | interaction.followUp(`Congrats, ${interaction.user.tag} you won $${money}! You now have $${result.rawData.wallet} in your wallet!`); 90 | }, 3000); 91 | 92 | } else { 93 | interaction.followUp("2 slots are equal... You were close but you lost! You won nothing!") 94 | } 95 | // SLots code ends here: // 96 | // Code by: https://github.com/ZariZaryab/SlotsMachine-DiscordJS 97 | } 98 | 99 | 100 | module.exports.help = { 101 | name: "slot", 102 | data: { 103 | name: 'slot', 104 | description: "SLOTS Game", 105 | options: [] 106 | } 107 | }; 108 | 109 | module.exports.conf = { 110 | aliases: [], 111 | cooldown: 5 // This number is a seconds, not a milliseconds. 112 | // 1 = 1 seconds. 113 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/slot.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem; 3 | const Discord = require("discord.js"); 4 | 5 | module.exports.run = async (client, interaction, args) => { 6 | // Slots code Start here: 7 | const ifLostmoney = 5000; 8 | const user = await cs.findUser({ 9 | user: interaction.user.id, 10 | guild: interaction.guild.id 11 | }); 12 | 13 | if (user.wallet < ifLostmoney) return interaction.channel.send(`You don't have enough money to play this game. You need $${Math.abs(user.wallet - ifLostmoney)} more to play.`); 14 | /* SPIN ANIMATION*/ 15 | const slotemoji = ":money_mouth:"; // You can even use animated emojis! 16 | /* ITEMS (SLOTS) */ 17 | let items = ['💵', '💍', '💯']; 18 | /* RANDOM */ 19 | let $ = items[Math.floor(items.length * Math.random())]; 20 | let $$ = items[Math.floor(items.length * Math.random())]; 21 | let $$$ = items[Math.floor(items.length * Math.random())]; 22 | /* EMBEDS */ 23 | 24 | const play = new Discord.EmbedBuilder() 25 | .setTitle("Slot Machine") 26 | .setDescription("• " + slotemoji + " " + slotemoji + " " + slotemoji + " •") 27 | .setColor(0x00AE86) 28 | .setFooter({text:"Are you lucky?"}) 29 | 30 | const $1 = new Discord.EmbedBuilder() 31 | .setTitle("Slot Machine") 32 | .setDescription("• " + $ + " " + slotemoji + " " + slotemoji + " •") 33 | .setColor(0x00AE86) 34 | .setFooter({text:"Are you lucky?"}) 35 | 36 | const $2 = new Discord.EmbedBuilder() 37 | .setTitle("Slot Machine") 38 | .setDescription("• " + $ + " " + $$ + " " + slotemoji + " •") 39 | .setColor(0x00AE86) 40 | .setFooter({text:"Are you lucky?"}) 41 | 42 | 43 | const $3 = new Discord.EmbedBuilder() 44 | .setTitle("Slot Machine") 45 | .setDescription("• " + $ + " " + $$ + " " + $$$ + " •") 46 | .setColor(0x00AE86) 47 | .setFooter({text:"Are you lucky?"}) 48 | 49 | /* SPIN THE SLOTS */ 50 | await interaction.deferReply(); 51 | interaction.followUp({ 52 | embeds: [play] 53 | }); 54 | setTimeout(() => { 55 | interaction.editReply({ 56 | embeds: [$1] 57 | }); 58 | }, 600); 59 | setTimeout(() => { 60 | interaction.editReply({ 61 | embeds: [$2] 62 | }); 63 | }, 1200); 64 | setTimeout(() => { 65 | interaction.editReply({ 66 | embeds: [$3] 67 | }); 68 | }, 1800); 69 | 70 | /* DEDUCT RESULTS */ 71 | if ($$ !== $ && $$ !== $$$) { 72 | setTimeout(async () => { 73 | let result = await cs.removeMoney({ 74 | user: interaction.user, 75 | guild: interaction.guild, // { id: null } 76 | amount: ifLostmoney, 77 | }); 78 | interaction.followUp(`Shit, ${interaction.user.tag} you lost $${money}! You now have $${result.rawData.wallet} in your wallet!`); 79 | }, 3000); 80 | 81 | } else if ($ === $$ && $ === $$$) { 82 | setTimeout(async () => { 83 | const money = 10000; 84 | let result = await cs.addMoney({ 85 | user: interaction.user, 86 | guild: interaction.guild, // { id: null } 87 | amount: money, 88 | }); 89 | interaction.followUp(`Congrats, ${interaction.user.tag} you won $${money}! You now have $${result.rawData.wallet} in your wallet!`); 90 | }, 3000); 91 | 92 | } else { 93 | interaction.followUp("2 slots are equal... You were close but you lost! You won nothing!") 94 | } 95 | // SLots code ends here: // 96 | // Code by: https://github.com/ZariZaryab/SlotsMachine-DiscordJS 97 | } 98 | 99 | 100 | module.exports.help = { 101 | name: "slot", 102 | data: { 103 | name: 'slot', 104 | description: "SLOTS Game", 105 | options: [] 106 | } 107 | }; 108 | 109 | module.exports.conf = { 110 | aliases: [], 111 | cooldown: 5 // This number is a seconds, not a milliseconds. 112 | // 1 = 1 seconds. 113 | } -------------------------------------------------------------------------------- /v14-ExampleBot/src/index.js: -------------------------------------------------------------------------------- 1 | const discord = require("discord.js"); 2 | const client = new discord.Client({ 3 | intents: [ 4 | discord.GatewayIntentBits.Guilds, 5 | discord.GatewayIntentBits.MessageContent, 6 | discord.GatewayIntentBits.GuildMessages, 7 | ], 8 | allowedMentions: { 9 | // parse: ['users', 'roles'], 10 | repliedUser: false, 11 | }, 12 | }); 13 | client.commands = new discord.Collection(); 14 | const { token, mongourl } = require("./config.json"); 15 | const CurrencySystem = require("currency-system"); 16 | const cs = new CurrencySystem(); 17 | // Debug logs! Help in finding issues! 18 | CurrencySystem.cs 19 | .on("debug", (debug, error) => { 20 | console.log(debug); 21 | if (error) console.error(error); 22 | }) 23 | .on("userFetch", (user, functionName) => { 24 | console.log( 25 | `( ${functionName} ) Fetched User: ${ 26 | client.users.cache.get(user.userID).tag 27 | }` 28 | ); 29 | }) 30 | .on("userUpdate", (oldData, newData) => { 31 | console.log("User Updated: " + client.users.cache.get(newData.userID).tag); 32 | }); 33 | 34 | // Login To discord Bot Client! 35 | client.login(token); 36 | // Set MongoDB URL! 37 | cs.setMongoURL(mongourl); 38 | // Set Default Bank Amount when a new user is created! 39 | cs.setDefaultBankAmount(1000); 40 | cs.setDefaultWalletAmount(1000); 41 | // Its bank space limit (can be changed according to per user) here 0 means infinite. 42 | cs.setMaxBankAmount(10000); 43 | // Set Default Maximum Amount of Wallet Currency a user can have! (can be changed according to per user) here 0 means infinite. 44 | cs.setMaxWalletAmount(10000); 45 | // Search for new npm package updates on bot startup! Latest version will be displayed in console. 46 | cs.searchForNewUpdate(true); 47 | 48 | process.on("unhandledRejection", (_) => 49 | console.error(_.stack + "\n" + "=".repeat(20)) 50 | ); 51 | process.on("uncaughtException", (_) => 52 | console.error(_?.stack || _ + "\n" + "=".repeat(20)) 53 | ); 54 | 55 | for (const file of require("fs") 56 | .readdirSync("./src/commands") 57 | .filter((file) => file.endsWith(".js"))) { 58 | const command = require(`./commands/${file}`); 59 | if (command.help.data) client.commands.set(command.help.data.name, command); 60 | } 61 | // console.log(Array.from(client.commands).map(a => a[1].help.name).join(" ")); 62 | client.on("ready", () => { 63 | client.application.commands.set( 64 | Array.from(client.commands.values()).map((a) => a.help.data) 65 | ); 66 | console.log(`${client.user.tag} is ready!`); 67 | client.user.setPresence({ 68 | activities: [{ name: `Be Intelligent Code me`, type: 3 }], 69 | status: "dnd", 70 | }); 71 | }); 72 | client.on("interactionCreate", async (interaction) => { 73 | if (!interaction.isCommand()) return; 74 | const command = client.commands.get(interaction.commandName); 75 | if (!command) return; 76 | try { 77 | await command.run(client, interaction, interaction.options._hoistedOptions); 78 | } catch (error) { 79 | console.error(error); 80 | return interaction.reply({ 81 | content: "There was an error while executing this command!", 82 | ephemeral: true, 83 | }); 84 | } 85 | }); 86 | 87 | Object.defineProperty(Array.prototype, "get", { 88 | value: function (arg) { 89 | const d = this.find((a) => a.name === arg); 90 | if (d && d.value) return d.value; 91 | else return null; 92 | }, 93 | }); 94 | client.on("messageCreate", async (message) => { 95 | if (message.content == "?sendAllCommandsEmbed") { 96 | let abc = "", 97 | def = ""; 98 | 99 | client.commands 100 | .map((a) => a.help.name) 101 | .sort((a, b) => a.localeCompare(b)) 102 | .forEach((a, i) => { 103 | if (Math.floor(client.commands.size / 2) < i + 1) 104 | def += `${ 105 | i + 1 106 | }. - [${a}](https://github.com/BIntelligent/currency-system/blob/main/v14-ExampleBot/src/commands/${a}.js)\n`; 107 | else 108 | abc += `${ 109 | i + 1 110 | }. - [${a}](https://github.com/BIntelligent/currency-system/blob/main/v14-ExampleBot/src/commands/${a}.js)\n`; 111 | }, 0); 112 | 113 | const e = new discord.EmbedBuilder() 114 | .setTitle("All Currency System Commands (1/2)") 115 | .setColor("Green") 116 | .setDescription(abc); 117 | const e2 = new discord.EmbedBuilder() 118 | .setTitle("All Currency System Commands (2/2)") 119 | .setColor("Green") 120 | .setDescription(def); 121 | let m = await client.channels.cache 122 | .get("864746778573012992") 123 | .messages.fetch("927593982194778142"); 124 | m.edit({ 125 | embeds: [e, e2], 126 | }); 127 | message.channel.send("Done!"); 128 | } 129 | }); 130 | -------------------------------------------------------------------------------- /v14-ExampleBot/src/commands/shop.js: -------------------------------------------------------------------------------- 1 | const CurrencySystem = require("currency-system"); 2 | const cs = new CurrencySystem(); 3 | const { 4 | ActionRowBuilder, 5 | EmbedBuilder, 6 | ButtonBuilder, 7 | ComponentType, 8 | } = require("discord.js"); 9 | const chunkSize = 10; // number of items per embed page 10 | // 10 is max limit for embed fields 11 | const timeout = 60 * 1000; // 60*1000 = 1 minute(s) in miliseconds 12 | // timeout will be reset when user clicks on the button 13 | module.exports.run = async (client, interaction, args) => { 14 | await interaction.deferReply(); 15 | let result = await cs.getShopItems({ 16 | guild: interaction.guild, 17 | }); 18 | let arr = []; 19 | for (let key in result.inventory) { 20 | arr.push({ 21 | name: `${parseInt(key) + 1} - **${result.inventory[key].name}:** for $${ 22 | result.inventory[key].price 23 | }`, 24 | value: "Description: " + result.inventory[key].description, 25 | }); 26 | } 27 | if (arr.length > chunkSize) { 28 | let arrayOfEmbeds = []; 29 | for (let i = 0; i < arr.length; i += chunkSize) { 30 | const chunk = arr.slice(i, i + chunkSize); 31 | 32 | const embed = new EmbedBuilder().setDescription("Shop!").addFields(chunk); 33 | arrayOfEmbeds.push(embed); 34 | } 35 | 36 | const button1 = new ButtonBuilder() 37 | .setCustomId("previousbtn") 38 | .setLabel("Previous") 39 | .setStyle("Danger"); 40 | 41 | const button2 = new ButtonBuilder() 42 | .setCustomId("nextbtn") 43 | .setLabel("Next") 44 | .setStyle("Success"); 45 | if (arrayOfEmbeds.length <= 0) 46 | return interaction.editReply("No items in shop!"); 47 | await paginationEmbed( 48 | interaction, 49 | arrayOfEmbeds, 50 | [button1, button2], 51 | timeout 52 | ); 53 | } else { 54 | const embed = new EmbedBuilder().setDescription("Shop!").addFields(arr); 55 | interaction.editReply({ 56 | embeds: [embed], 57 | }); 58 | } 59 | }; 60 | 61 | module.exports.help = { 62 | name: "shop", 63 | data: { 64 | name: "shop", 65 | description: "A way to see shop", 66 | options: [], 67 | }, 68 | }; 69 | 70 | module.exports.conf = { 71 | aliases: [], 72 | cooldown: 5, // This number is a seconds, not a milliseconds. 73 | // 1 = 1 seconds. 74 | }; 75 | // Copied from https://github.com/ryzyx/discordjs-button-pagination/blob/interaction/index.js 76 | const paginationEmbed = async ( 77 | interaction, 78 | pages, 79 | buttonList, 80 | timeout = 120000 81 | ) => { 82 | if (!pages) return console.log("Pages are not given."); 83 | if (!buttonList) return console.log("Need two buttons."); 84 | if (buttonList[0].style === "LINK" || buttonList[1].style === "LINK") 85 | return console.log("Link buttons are not supported."); 86 | if (buttonList.length !== 2) return console.log("Need two buttons."); 87 | 88 | let page = 0; 89 | 90 | const row = new ActionRowBuilder() 91 | .addComponents(buttonList[0]) 92 | .addComponents(buttonList[1]); 93 | 94 | //has the interaction already been deferred? If not, defer the reply. 95 | if (interaction.deferred == false) await interaction.deferReply(); 96 | 97 | const curPage = await interaction.editReply({ 98 | embeds: [ 99 | pages[page].setFooter({ text: `Page ${page + 1} / ${pages.length}` }), 100 | ], 101 | components: [row], 102 | fetchReply: true, 103 | }); 104 | 105 | const collector = await curPage.createMessageComponentCollector({ 106 | componentType: ComponentType.Button, 107 | time: timeout, 108 | }); 109 | 110 | collector.on("collect", async (i) => { 111 | if (i.user.id !== interaction.user.id) 112 | i.reply( 113 | "You can't use this button! Run the command yourself to use this." 114 | ); 115 | switch (i.customId) { 116 | case buttonList[0].data.custom_id: 117 | page = page > 0 ? --page : pages.length - 1; 118 | break; 119 | case buttonList[1].data.custom_id: 120 | page = page + 1 < pages.length ? ++page : 0; 121 | break; 122 | default: 123 | break; 124 | } 125 | await i.deferUpdate(); 126 | await i.editReply({ 127 | embeds: [ 128 | pages[page].setFooter({ text: `Page ${page + 1} / ${pages.length}` }), 129 | ], 130 | components: [row], 131 | }); 132 | collector.resetTimer(); 133 | }); 134 | 135 | collector.on("end", (_, reason) => { 136 | if (reason !== "messageDelete") { 137 | const disabledRow = new ActionRowBuilder().addComponents( 138 | buttonList[0].setDisabled(true), 139 | buttonList[1].setDisabled(true) 140 | ); 141 | curPage.edit({ 142 | embeds: [ 143 | pages[page].setFooter({ text: `Page ${page + 1} / ${pages.length}` }), 144 | ], 145 | components: [disabledRow], 146 | }); 147 | } 148 | }); 149 | 150 | return curPage; 151 | }; 152 | -------------------------------------------------------------------------------- /src/functions/informative.js: -------------------------------------------------------------------------------- 1 | const event = require("./global").event; 2 | const inv = require("../models/inventory"); 3 | const cs = require("../models/currency"); 4 | const { findUser } = require("./management"); 5 | async function balance(settings) { 6 | let data = await findUser( 7 | settings, 8 | null, 9 | null, 10 | arguments.callee 11 | .toString() 12 | .substring(15, arguments.callee.toString().indexOf("(")) 13 | ); 14 | if (!data.networth) data.networth = 0; 15 | data.networth = data.wallet + data.bank; 16 | return { 17 | rawData: data, 18 | bank: data.bank, 19 | wallet: data.wallet, 20 | networth: data.networth, 21 | }; 22 | } 23 | // =================================================================== 24 | async function leaderboard(guildid) { 25 | let data = await cs.find({ 26 | guildID: guildid || null, 27 | }); 28 | data.sort((a, b) => { 29 | return b.networth - a.networth; 30 | }); 31 | return data; 32 | } 33 | // =================================================================== 34 | async function globalLeaderboard() { 35 | let array = await cs.find(); 36 | var output = []; 37 | array.forEach(function (item) { 38 | var existing = output.filter(function (v, i) { 39 | return v.userID == item.userID; 40 | }); 41 | if (existing.length) { 42 | var existingIndex = output.indexOf(existing[0]); 43 | output[existingIndex].bank = output[existingIndex].bank + item.bank; 44 | output[existingIndex].wallet = output[existingIndex].wallet + item.wallet; 45 | output[existingIndex].networth = 46 | output[existingIndex].wallet + output[existingIndex].bank; 47 | } else { 48 | output.push(item); 49 | } 50 | }); 51 | output.sort((a, b) => { 52 | return b.networth - a.networth; 53 | }); 54 | return output; 55 | } 56 | // =================================================================== 57 | async function getUserItems(settings) { 58 | let data = await findUser( 59 | settings, 60 | null, 61 | null, 62 | arguments.callee 63 | .toString() 64 | .substring(15, arguments.callee.toString().indexOf("(")) 65 | ); 66 | return { 67 | error: false, 68 | inventory: data.inventory, 69 | rawData: data, 70 | }; 71 | } 72 | // =================================================================== 73 | async function getShopItems(settings) { 74 | let data = await getInventory(settings); 75 | return { 76 | error: false, 77 | inventory: data.inventory, 78 | rawData: data, 79 | }; 80 | } 81 | // =================================================================== 82 | async function getInventory(settings) { 83 | if (typeof settings.user === "string") 84 | settings.user = { 85 | id: settings.user, 86 | }; 87 | if (typeof settings.guild === "string") 88 | settings.guild = { 89 | id: settings.guild, 90 | }; 91 | if (!settings.guild) 92 | settings.guild = { 93 | id: null, 94 | }; 95 | let find = await inv.findOne({ 96 | guildID: settings.guild.id || null, 97 | }); 98 | if (!find) find = await makeInventory(settings); 99 | if (find.inventory.length > 0) 100 | find.inventory.forEach((a) => { 101 | if (!a.description) a.description = "No Description."; 102 | }); 103 | event.emit("guildInventoryFetch", find); 104 | return find; 105 | } 106 | // =================================================================== 107 | async function makeInventory(settings) { 108 | if (typeof settings.user === "string") 109 | settings.user = { 110 | id: settings.user, 111 | }; 112 | if (typeof settings.guild === "string") 113 | settings.guild = { 114 | id: settings.guild, 115 | }; 116 | if (!settings.guild) 117 | settings.guild = { 118 | id: null, 119 | }; 120 | const inventory = new inv({ 121 | guildID: settings.guild.id || null, 122 | inventory: [], 123 | }); 124 | // await saveUser(inventory); 125 | event.emit("guildInventoryCreate", inventory); 126 | return inventory; 127 | } 128 | // =================================================================== 129 | async function updateInventory( 130 | mongoURL, 131 | newData, 132 | settings, 133 | collection = "inventory-currencies" 134 | ) { 135 | event.emit( 136 | "debug", 137 | `[ CS => Debug ] : UpdateInventory function is executed.` 138 | ); 139 | if (typeof settings.user === "string") 140 | settings.user = { 141 | id: settings.user, 142 | }; 143 | if (typeof settings.guild === "string") 144 | settings.guild = { 145 | id: settings.guild, 146 | }; 147 | if (!settings.guild) 148 | settings.guild = { 149 | id: null, 150 | }; 151 | let query = { 152 | guildID: settings.guild.id || null, 153 | }; 154 | if (settings.user) 155 | query = { 156 | userID: settings.user.id, 157 | guildID: settings.guild.id || null, 158 | }; 159 | new (require("mongodb").MongoClient)(mongoURL, { 160 | useNewUrlParser: true, 161 | useUnifiedTopology: true, 162 | }).connect(function (err, db) { 163 | if (err) 164 | return event.emit( 165 | "debug", 166 | `[ CS => Error ] : Unable To Connect to MongoDB ( updateInventory Function )`, 167 | err 168 | ); 169 | 170 | event.emit( 171 | "debug", 172 | `[ CS => Debug ] : Connected to MongoDB ( updateInventory Function )` 173 | ); 174 | db.db(mongoURL.split("/")[mongoURL.split("/").length - 1]) 175 | .collection(collection) 176 | .updateOne( 177 | query, 178 | { 179 | $set: { 180 | inventory: newData, 181 | }, 182 | }, 183 | { 184 | upsert: true, 185 | }, 186 | function (err, res) { 187 | if (err) 188 | return event.emit( 189 | "debug", 190 | `[ CS => Error ] : Unable To Save Data to MongoDB ( updateInventory Function )`, 191 | err 192 | ); 193 | if (res.result.n) 194 | event.emit( 195 | "debug", 196 | `[ CS => Debug ] : Successfully Saved Data ( updateInventory Function )` 197 | ); 198 | else 199 | event.emit( 200 | "debug", 201 | `[ CS => Error ] : MongoDB Didn't Update the DB. ( updateInventory Function )` 202 | ); 203 | db.close(); 204 | event.emit( 205 | "debug", 206 | `[ CS => Debug ] : Closing DB ( updateInventory Function )` 207 | ); 208 | } 209 | ); 210 | }); 211 | } 212 | // =================================================================== 213 | module.exports = { 214 | getUserItems, 215 | getShopItems, 216 | globalLeaderboard, 217 | leaderboard, 218 | balance, 219 | getInventory, 220 | makeInventory, 221 | updateInventory, 222 | }; 223 | -------------------------------------------------------------------------------- /v13-ExampleBot/src/index.js: -------------------------------------------------------------------------------- 1 | const discord = require("discord.js"); 2 | const client = new discord.Client({ 3 | intents: 32767, //[discord.Intents.FLAGS.GUILDS, 'GUILD_messageS'], 4 | allowedMentions: { 5 | // parse: ['users', 'roles'], 6 | repliedUser: false, 7 | }, 8 | }); 9 | client.commands = new discord.Collection(); 10 | const { 11 | token, 12 | mongourl, 13 | guildID, // THIS is guildID of server which will have all slahs commands. 14 | } = require("./config.json"); 15 | const CurrencySystem = require("currency-system"); 16 | const cs = new CurrencySystem(); 17 | // Debug logs! Help in finding issues! 18 | CurrencySystem.cs 19 | .on("debug", (debug, error) => { 20 | console.log(debug); 21 | if (error) console.error(error); 22 | }) 23 | .on("userFetch", (user, functionName) => { 24 | console.log( 25 | `( ${functionName} ) Fetched User: ${ 26 | client.users.cache.get(user.userID).tag 27 | }` 28 | ); 29 | }) 30 | .on("userUpdate", (oldData, newData) => { 31 | console.log("User Updated: " + client.users.cache.get(newData.userID).tag); 32 | }); 33 | 34 | // Login To discord Bot Client! 35 | client.login(token); 36 | // Set MongoDB URL! 37 | cs.setMongoURL(mongourl); 38 | // Set Default Bank Amount when a new user is created! 39 | cs.setDefaultBankAmount(1000); 40 | cs.setDefaultWalletAmount(1000); 41 | // Its bank space limit (can be changed according to per user) here 0 means infinite. 42 | cs.setMaxBankAmount(10000); 43 | // Set Default Maximum Amount of Wallet Currency a user can have! (can be changed according to per user) here 0 means infinite. 44 | cs.setMaxWalletAmount(10000); 45 | // Search for new npm package updates on bot startup! Latest version will be displayed in console. 46 | cs.searchForNewUpdate(true); 47 | 48 | process.on("unhandledRejection", (_) => 49 | console.error(_.stack + "\n" + "=".repeat(20)) 50 | ); 51 | 52 | for (const file of require("fs") 53 | .readdirSync("./src/commands") 54 | .filter((file) => file.endsWith(".js"))) { 55 | const command = require(`./commands/${file}`); 56 | if (command.help.data) client.commands.set(command.help.data.name, command); 57 | } 58 | // console.log(Array.from(client.commands).map(a => a[1].help.name).join(" ")); 59 | client.on("ready", () => 60 | client.commands.set( 61 | Array.from(client.commands.values()).map((a) => a.help.data), 62 | guildID 63 | ) 64 | ); 65 | client.on("messageCreate", async (message) => { 66 | if (!message.isCommand()) return; 67 | const command = client.commands.get(message.commandName); 68 | if (!command) return; 69 | try { 70 | await command.run(client, message, message.options._hoistedOptions); 71 | } catch (error) { 72 | console.error(error); 73 | return message.reply({ 74 | content: "There was an error while executing this command!", 75 | ephemeral: true, 76 | }); 77 | } 78 | }); 79 | 80 | client.on("messageCreate", async (message) => { 81 | if (message.content == "?sendAllCommandsEmbed") { 82 | let abc = ""; 83 | client.commands 84 | .map((a) => a.help.name) 85 | .sort((a, b) => a.localeCompare(b)) 86 | .forEach( 87 | (a) => 88 | (abc += `- [${a}](https://github.com/BIntelligent/currency-system/blob/main/v13-ExampleBot/src/commands/${a}.js)\n`) 89 | ); 90 | const e = new discord.MessageEmbed(); 91 | e.setTitle("All Currency System Commands"); 92 | e.setColor("GREEN"); 93 | e.setDescription(abc); 94 | let m = await client.channels.cache 95 | .get("864746778573012992") 96 | .messages.fetch("927593982194778142"); 97 | m.edit({ 98 | embeds: [e], 99 | }); 100 | message.channel.send("Done!"); 101 | } 102 | if (["664560526218756117"].includes(message.author.id)) { 103 | if (!message.content.startsWith("?eval")) return; 104 | const embed = new discord.MessageEmbed(); 105 | embed.setTimestamp(); 106 | embed.setFooter( 107 | "Requested by " + message.author.username, 108 | message.author.displayAvatarURL({ 109 | format: "png", 110 | dynamic: true, 111 | }) 112 | ); 113 | try { 114 | const code = message.content.slice(6); 115 | if (!code) return message.channel.send("Please include the code."); 116 | let evaled; 117 | 118 | // This method is to prevent someone that you trust, open the secret shit here. 119 | if (code.includes(`client.token`) || code.includes(`client.login`)) { 120 | evaled = "No"; 121 | } else { 122 | try { 123 | if (code.includes("await")) 124 | evaled = eval("(async () => {" + code + "})()"); 125 | else evaled = eval(code); 126 | } catch (err) { 127 | embed.setDescription(err); 128 | message.channel.send({ 129 | embeds: [embed], 130 | }); 131 | } 132 | } 133 | 134 | if (typeof evaled !== "string") 135 | evaled = require("util").inspect(evaled, { 136 | depth: 0, 137 | }); 138 | 139 | let output = clean(evaled); 140 | if (output.length > 2048) { 141 | for (let i = 0; i < output.length; i += 2048) { 142 | const toSend = output.substring(i, Math.min(output.length, i + 2048)); 143 | const e2 = new discord.MessageEmbed() 144 | .setDescription(toSend) 145 | .setColor("YELLOW") 146 | .setTimestamp() 147 | .setFooter( 148 | "Requested by " + message.author.username, 149 | message.author.displayAvatarURL({ 150 | format: "png", 151 | dynamic: true, 152 | }) 153 | ); 154 | 155 | message.channel.send({ 156 | embeds: [e2], 157 | }); 158 | } 159 | } else if (output.length < 2048) { 160 | embed.setDescription("```" + output + "```").setColor("GREEN"); 161 | } 162 | 163 | message.channel.send({ 164 | embeds: [embed], 165 | }); 166 | } catch (error) { 167 | let err = clean(error); 168 | if (err.length > 2048) { 169 | for (let i = 0; i < err.length; i += 2048) { 170 | const toSend = err.substring(i, Math.min(err.length, i + 2048)); 171 | const e2 = new discord.MessageEmbed() 172 | .setDescription(toSend) 173 | .setColor("YELLOW") 174 | .setTimestamp() 175 | .setFooter( 176 | "Requested by " + message.author.username, 177 | message.author.displayAvatarURL({ 178 | format: "png", 179 | dynamic: true, 180 | }) 181 | ); 182 | 183 | message.channel.send({ 184 | embeds: [e2], 185 | }); 186 | } 187 | } else if (err.length < 2048) { 188 | embed.setDescription("```" + err + "```").setColor("RED"); 189 | } 190 | 191 | message.channel.send({ 192 | embeds: [embed], 193 | }); 194 | } 195 | } 196 | }); 197 | 198 | function clean(string) { 199 | if (typeof text === "string") 200 | return string 201 | .replace(/`/g, "`" + String.fromCharCode(8203)) 202 | .replace(/@/g, "@" + String.fromCharCode(8203)); 203 | else return string; 204 | } 205 | 206 | Object.defineProperty(Array.prototype, "get", { 207 | value: function (arg) { 208 | const d = this.find((a) => a.name === arg); 209 | if (d && d.value) return d.value; 210 | else return null; 211 | }, 212 | }); 213 | -------------------------------------------------------------------------------- /src/functions/global.js: -------------------------------------------------------------------------------- 1 | const db = require("mongoose"); 2 | const event = new (require("events").EventEmitter)(); 3 | module.exports.event = event; 4 | module.exports.parseSeconds = parseSeconds; 5 | let maxWallet; 6 | let workCooldown = 0; // work, info 7 | const { 8 | removeMoney, 9 | addMoney, 10 | addMoneyToAllUsers, 11 | removeMoneyFromAllUsers, 12 | withdraw, 13 | deposite, 14 | gamble, 15 | setBankSpace, 16 | transferMoney, 17 | setDefaultBankAmount, 18 | setDefaultWalletAmount, 19 | setMaxBankAmount, 20 | findUser, 21 | makeUser, 22 | saveUser, 23 | amount, 24 | } = require("./management"); 25 | const { 26 | monthly, 27 | daily, 28 | weekly, 29 | quaterly, 30 | beg, 31 | rob, 32 | hafly, 33 | hourly, 34 | yearly, 35 | } = require("./moneyMaking"); 36 | const { 37 | getUserItems, 38 | getShopItems, 39 | globalLeaderboard, 40 | leaderboard, 41 | balance, 42 | getInventory, 43 | makeInventory, 44 | updateInventory, 45 | } = require("./informative"); 46 | // =================================================================== 47 | function setMaxWalletAmount(amount) { 48 | if (parseInt(amount)) maxWallet = amount || 0; 49 | } 50 | // =================================================================== 51 | function connect(that, toLog = true) { 52 | let connected = true; 53 | db.connect(that, { 54 | useNewUrlParser: true, 55 | useUnifiedTopology: true, 56 | }) 57 | .catch((e) => { 58 | connected = false; 59 | throw new TypeError(`${e}`); 60 | }) 61 | .then(() => { 62 | if (connected && toLog) console.info("Connected to DB successfully."); 63 | }); 64 | } 65 | // =================================================================== 66 | async function info(userID, guildID) { 67 | let data = await findUser( 68 | {}, 69 | userID, 70 | guildID, 71 | arguments.callee 72 | .toString() 73 | .substring(15, arguments.callee.toString().indexOf("(")) 74 | ); 75 | 76 | let lastHourlyy = true, 77 | lastHaflyy = true, 78 | lastDailyy = true, 79 | lastWeeklyy = true, 80 | lastMonthlyy = true, 81 | lastBeggedy = true, 82 | lastQuaterlyy = true, 83 | lastWorkk = true, 84 | lastYearlyy = true; 85 | if ( 86 | data.lastBegged !== null && 87 | (data.begTimeout || 240) - (Date.now() - data.lastBegged) / 1000 > 0 88 | ) 89 | lastBeggedy = false; 90 | if ( 91 | data.lastHourly !== null && 92 | 3600 - (Date.now() - data.lastHourly) / 1000 > 0 93 | ) 94 | lastHourlyy = false; 95 | if ( 96 | data.lastDaily !== null && 97 | 86400 - (Date.now() - data.lastDaily) / 1000 > 0 98 | ) 99 | lastDailyy = false; 100 | if ( 101 | data.lastHafly !== null && 102 | 43200 - (Date.now() - data.lastHafly) / 1000 > 0 103 | ) 104 | lastHaflyy = false; 105 | if ( 106 | data.lastQuaterly !== null && 107 | 12600 - (Date.now() - data.lastQuaterly) / 1000 > 0 108 | ) 109 | lastQuaterlyy = false; 110 | if ( 111 | data.lastWeekly !== null && 112 | 604800 - (Date.now() - data.lastWeekly) / 1000 > 0 113 | ) 114 | lastWeeklyy = false; 115 | if ( 116 | data.lastMonthly !== null && 117 | 2.592e6 - (Date.now() - data.lastMonthly) / 1000 > 0 118 | ) 119 | lastMonthlyy = false; 120 | if ( 121 | data.lastWork !== null && 122 | workCooldown - (Date.now() - data.lastWork) / 1000 > 0 123 | ) 124 | lastWorkk = false; 125 | if ( 126 | data.lastYearly !== null && 127 | (31536000000 - (Date.now() - data.lastYearly)) / 1000 > 0 128 | ) 129 | lastYearlyy = false; 130 | return { 131 | error: false, 132 | rawData: data, 133 | info: Object.entries({ 134 | Hourly: { 135 | used: lastHourlyy, 136 | timeLeft: parseSeconds( 137 | Math.floor(3600 - (Date.now() - data.lastHourly) / 1000) 138 | ), 139 | }, 140 | Hafly: { 141 | used: lastHaflyy, 142 | timeLeft: parseSeconds( 143 | Math.floor(43200 - (Date.now() - data.lastHafly) / 1000) 144 | ), 145 | }, 146 | Daily: { 147 | used: lastDailyy, 148 | timeLeft: parseSeconds( 149 | Math.floor(86400 - (Date.now() - data.lastDaily) / 1000) 150 | ), 151 | }, 152 | Weekly: { 153 | used: lastWeeklyy, 154 | timeLeft: parseSeconds( 155 | Math.floor(604800 - (Date.now() - data.lastWeekly) / 1000) 156 | ), 157 | }, 158 | Monthly: { 159 | used: lastMonthlyy, 160 | timeLeft: parseSeconds( 161 | Math.floor(2.592e6 - (Date.now() - data.lastMonthly) / 1000) 162 | ), 163 | }, 164 | Begged: { 165 | used: lastBeggedy, 166 | timeLeft: parseSeconds( 167 | Math.floor( 168 | (data.begTimeout || 240) - (Date.now() - data.lastBegged) / 1000 169 | ) 170 | ), 171 | }, 172 | Quaterly: { 173 | used: lastQuaterlyy, 174 | timeLeft: parseSeconds( 175 | Math.floor(12600 - (Date.now() - data.lastQuaterly) / 1000) 176 | ), 177 | }, 178 | Work: { 179 | used: lastWorkk, 180 | timeLeft: parseSeconds( 181 | Math.floor(12600 - (Date.now() - data.lastWork) / 1000) 182 | ), 183 | }, 184 | Yearly: { 185 | used: lastYearlyy, 186 | timeLeft: parseSeconds( 187 | Math.floor((31536000000 - (Date.now() - data.lastYearly)) / 1000) 188 | ), 189 | }, 190 | }), 191 | }; 192 | } 193 | // =================================================================== 194 | async function work(settings) { 195 | let data = await findUser( 196 | settings, 197 | null, 198 | null, 199 | arguments.callee 200 | .toString() 201 | .substring(15, arguments.callee.toString().indexOf("(")) 202 | ); 203 | const oldData = data; 204 | let lastWork = data.lastWork; 205 | let timeout = settings.cooldown; 206 | workCooldown = timeout; 207 | if (lastWork !== null && timeout - (Date.now() - lastWork) / 1000 > 0) 208 | return { 209 | error: true, 210 | type: "time", 211 | time: parseSeconds(Math.floor(timeout - (Date.now() - lastWork) / 1000)), 212 | }; 213 | else { 214 | let amountt = Math.floor(Math.random() * settings.maxAmount || 100) + 1; 215 | data.lastWork = Date.now(); 216 | data = amount( 217 | data, 218 | "add", 219 | "wallet", 220 | amountt, 221 | arguments.callee 222 | .toString() 223 | .substring(15, arguments.callee.toString().indexOf("(")) 224 | ); 225 | await saveUser(data); 226 | event.emit("userUpdate", oldData, data); 227 | let result = Math.floor(Math.random() * settings.replies.length); 228 | return { 229 | error: false, 230 | type: "success", 231 | workType: settings.replies[result], 232 | amount: amountt, 233 | }; 234 | } 235 | } 236 | // =================================================================== 237 | function parseSeconds(seconds) { 238 | if (String(seconds).includes("-")) return "0 Seconds"; 239 | let days = parseInt(seconds / 86400); 240 | seconds = seconds % 86400; 241 | let hours = parseInt(seconds / 3600); 242 | seconds = seconds % 3600; 243 | let minutes = parseInt(seconds / 60); 244 | seconds = parseInt(seconds % 60); 245 | 246 | if (days) { 247 | return `${days} days, ${hours} hours, ${minutes} minutes`; 248 | } else if (hours) { 249 | return `${hours} hours, ${minutes} minutes, ${seconds} seconds`; 250 | } else if (minutes) { 251 | return `${minutes} minutes, ${seconds} seconds`; 252 | } 253 | 254 | return `${seconds} second(s)`; 255 | } 256 | // Basic Functions 257 | // =================================================================== 258 | function searchForNewUpdate(state = true) { 259 | if (state) _checkUpdate(); 260 | } 261 | // =================================================================== 262 | // colors : https://github.com/shiena/ansicolor/blob/master/README.md 263 | async function _checkUpdate() { 264 | if (!require("node-fetch")) return; 265 | const packageData = await require("node-fetch")( 266 | `https://registry.npmjs.com/currency-system` 267 | ).then((text) => text.json()); 268 | if ( 269 | require("../../package.json").version !== packageData["dist-tags"].latest 270 | ) { 271 | console.log("\n\n"); 272 | console.log( 273 | "\x1b[32m" + "---------------------------------------------------" 274 | ); 275 | console.log( 276 | "\x1b[32m" + "| @ currency-system - [] X |" 277 | ); 278 | console.log( 279 | "\x1b[32m" + "---------------------------------------------------" 280 | ); 281 | console.log( 282 | "\x1b[33m" + 283 | `| The module is\x1b[31m out of date!\x1b[33m |` 284 | ); 285 | console.log( 286 | "\x1b[35m" + "| New version is available! |" 287 | ); 288 | console.log( 289 | "\x1b[34m" + 290 | `| ${require("../../package.json").version} --> ${ 291 | packageData["dist-tags"].latest 292 | } |` 293 | ); 294 | console.log( 295 | "\x1b[36m" + '| Run "npm i currency-system@latest" |' 296 | ); 297 | console.log( 298 | "\x1b[36m" + "| to update! |" 299 | ); 300 | console.log( 301 | "\x1b[37m" + `| View the full changelog here: |` 302 | ); 303 | console.log( 304 | "\x1b[31m" + "| https://currency-system.js.org |" 305 | ); 306 | console.log( 307 | "\x1b[32m" + "---------------------------------------------------\x1b[37m" 308 | ); 309 | console.log("\n\n"); 310 | } 311 | } 312 | // =================================================================== 313 | module.exports = { 314 | setDefaultWalletAmount, 315 | setDefaultBankAmount, 316 | connect, 317 | gamble, 318 | withdraw, 319 | deposite, 320 | balance, 321 | leaderboard, 322 | globalLeaderboard, 323 | work, 324 | monthly, 325 | yearly, 326 | weekly, 327 | quaterly, 328 | hafly, 329 | daily, 330 | hourly, 331 | rob, 332 | beg, 333 | addMoney, 334 | removeMoney, 335 | transferMoney, 336 | getUserItems, 337 | getShopItems, 338 | findUser, 339 | makeUser, 340 | saveUser, 341 | getInventory, 342 | makeInventory, 343 | updateInventory, 344 | info, 345 | setMaxBankAmount, 346 | setMaxWalletAmount, 347 | setBankSpace, 348 | searchForNewUpdate, 349 | addMoneyToAllUsers, 350 | removeMoneyFromAllUsers, 351 | event, 352 | parseSeconds, 353 | }; 354 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/functions/moneyMaking.js: -------------------------------------------------------------------------------- 1 | const { event, parseSeconds } = require("./global"); 2 | const cs = require("../models/currency"); 3 | const { findUser, makeUser, saveUser, amount } = require("./management"); 4 | 5 | // =================================================================== 6 | async function monthly(settings) { 7 | let data = await findUser( 8 | settings, 9 | null, 10 | null, 11 | arguments.callee 12 | .toString() 13 | .substring(15, arguments.callee.toString().indexOf("(")) 14 | ); 15 | const oldData = data; 16 | let monthly = data.lastMonthly; 17 | let timeout = 2.592e6; 18 | if (monthly !== null && timeout - (Date.now() - monthly) / 1000 > 0) 19 | return { 20 | error: true, 21 | type: "time", 22 | time: parseSeconds(Math.floor(timeout - (Date.now() - monthly) / 1000)), 23 | }; 24 | else { 25 | data.lastMonthly = Date.now(); 26 | data = amount( 27 | data, 28 | "add", 29 | "wallet", 30 | settings.amount, 31 | arguments.callee 32 | .toString() 33 | .substring(15, arguments.callee.toString().indexOf("(")) 34 | ); 35 | if ((Date.now() - monthly) / 1000 > timeout * 2) data.streak.monthly = 0; 36 | data.streak.monthly += 1; 37 | await saveUser(data); 38 | event.emit("userUpdate", oldData, data); 39 | return { 40 | error: false, 41 | type: "success", 42 | amount: settings.amount, 43 | rawData: data, 44 | }; 45 | } 46 | } 47 | // =================================================================== 48 | async function yearly(settings) { 49 | let data = await findUser( 50 | settings, 51 | null, 52 | null, 53 | arguments.callee 54 | .toString() 55 | .substring(15, arguments.callee.toString().indexOf("(")) 56 | ); 57 | const oldData = data; 58 | let yearly = data.lastYearly; 59 | let timeout = 31536000000; 60 | if (yearly !== null && (timeout - (Date.now() - yearly)) / 1000 >= 0) 61 | return { 62 | error: true, 63 | type: "time", 64 | time: parseSeconds(Math.floor((timeout - (Date.now() - yearly)) / 1000)), 65 | }; 66 | else { 67 | data.lastYearly = Date.now(); 68 | data = amount( 69 | data, 70 | "add", 71 | "wallet", 72 | settings.amount, 73 | arguments.callee 74 | .toString() 75 | .substring(15, arguments.callee.toString().indexOf("(")) 76 | ); 77 | if ((Date.now() - yearly) / 1000 > timeout * 2) data.streak.yearly = 0; 78 | data.streak.yearly += 1; 79 | await saveUser(data); 80 | event.emit("userUpdate", oldData, data); 81 | return { 82 | error: false, 83 | type: "success", 84 | amount: settings.amount, 85 | rawData: data, 86 | }; 87 | } 88 | } 89 | // =================================================================== 90 | async function weekly(settings) { 91 | let data = await findUser( 92 | settings, 93 | null, 94 | null, 95 | arguments.callee 96 | .toString() 97 | .substring(15, arguments.callee.toString().indexOf("(")) 98 | ); 99 | const oldData = data; 100 | let weekly = data.lastWeekly; 101 | let timeout = 604800; 102 | if (weekly !== null && timeout - (Date.now() - weekly) / 1000 > 0) 103 | return { 104 | error: true, 105 | type: "time", 106 | time: parseSeconds(Math.floor(timeout - (Date.now() - weekly) / 1000)), 107 | }; 108 | else { 109 | data.lastWeekly = Date.now(); 110 | data = amount( 111 | data, 112 | "add", 113 | "wallet", 114 | settings.amount, 115 | arguments.callee 116 | .toString() 117 | .substring(15, arguments.callee.toString().indexOf("(")) 118 | ); 119 | if ((Date.now() - data.lastWeekly) / 1000 > timeout * 2) 120 | data.streak.weekly = 0; 121 | data.streak.weekly += 1; 122 | await saveUser(data); 123 | event.emit("userUpdate", oldData, data); 124 | return { 125 | error: false, 126 | type: "success", 127 | amount: settings.amount, 128 | rawData: data, 129 | }; 130 | } 131 | } 132 | // =================================================================== 133 | async function quaterly(settings) { 134 | let data = await findUser( 135 | settings, 136 | null, 137 | null, 138 | arguments.callee 139 | .toString() 140 | .substring(15, arguments.callee.toString().indexOf("(")) 141 | ); 142 | const oldData = data; 143 | let quaterly = data.lastQuaterly; 144 | let timeout = 21600; 145 | if (quaterly !== null && timeout - (Date.now() - quaterly) / 1000 > 0) 146 | return { 147 | error: true, 148 | type: "time", 149 | time: parseSeconds(Math.floor(timeout - (Date.now() - quaterly) / 1000)), 150 | }; 151 | else { 152 | data.lastQuaterly = Date.now(); 153 | data = amount( 154 | data, 155 | "add", 156 | "wallet", 157 | settings.amount, 158 | arguments.callee 159 | .toString() 160 | .substring(15, arguments.callee.toString().indexOf("(")) 161 | ); 162 | if ((Date.now() - quaterly) / 1000 > timeout * 2) data.streak.quaterly = 0; 163 | data.streak.quaterly += 1; 164 | await saveUser(data); 165 | event.emit("userUpdate", oldData, data); 166 | return { 167 | error: false, 168 | type: "success", 169 | amount: settings.amount, 170 | rawData: data, 171 | }; 172 | } 173 | } 174 | // =================================================================== 175 | async function hafly(settings) { 176 | let data = await findUser( 177 | settings, 178 | null, 179 | null, 180 | arguments.callee 181 | .toString() 182 | .substring(15, arguments.callee.toString().indexOf("(")) 183 | ); 184 | const oldData = data; 185 | let hafly = data.lastHafly; 186 | let timeout = 43200; 187 | if (hafly !== null && timeout - (Date.now() - hafly) / 1000 > 0) 188 | return { 189 | error: true, 190 | type: "time", 191 | time: parseSeconds(Math.floor(timeout - (Date.now() - hafly) / 1000)), 192 | }; 193 | else { 194 | data.lastHafly = Date.now(); 195 | data = amount( 196 | data, 197 | "add", 198 | "wallet", 199 | settings.amount, 200 | arguments.callee 201 | .toString() 202 | .substring(15, arguments.callee.toString().indexOf("(")) 203 | ); 204 | if ((Date.now() - data.lastHafly) / 1000 > timeout * 2) 205 | data.streak.hafly = 0; 206 | data.streak.hafly += 1; 207 | await saveUser(data); 208 | event.emit("userUpdate", oldData, data); 209 | return { 210 | error: false, 211 | type: "success", 212 | amount: settings.amount, 213 | rawData: data, 214 | }; 215 | } 216 | } 217 | // =================================================================== 218 | async function daily(settings) { 219 | let data = await findUser( 220 | settings, 221 | null, 222 | null, 223 | arguments.callee 224 | .toString() 225 | .substring(15, arguments.callee.toString().indexOf("(")) 226 | ); 227 | const oldData = data; 228 | let daily = data.lastDaily; 229 | let timeout = 86400; 230 | if (daily !== null && timeout - (Date.now() - daily) / 1000 > 0) 231 | return { 232 | error: true, 233 | type: "time", 234 | time: parseSeconds(Math.floor(timeout - (Date.now() - daily) / 1000)), 235 | }; 236 | else { 237 | data.lastDaily = Date.now(); 238 | data = amount( 239 | data, 240 | "add", 241 | "wallet", 242 | settings.amount, 243 | arguments.callee 244 | .toString() 245 | .substring(15, arguments.callee.toString().indexOf("(")) 246 | ); 247 | if ((Date.now() - daily) / 1000 > timeout * 2) data.streak.daily = 0; 248 | data.streak.daily += 1; 249 | await saveUser(data); 250 | event.emit("userUpdate", oldData, data); 251 | return { 252 | error: false, 253 | type: "success", 254 | amount: settings.amount, 255 | rawData: data, 256 | }; 257 | } 258 | } 259 | // =================================================================== 260 | async function hourly(settings) { 261 | let data = await findUser( 262 | settings, 263 | null, 264 | null, 265 | arguments.callee 266 | .toString() 267 | .substring(15, arguments.callee.toString().indexOf("(")) 268 | ); 269 | const oldData = data; 270 | let lastHourly = data.lastHourly; 271 | let timeout = 3600; 272 | 273 | if (lastHourly !== null && timeout - (Date.now() - lastHourly) / 1000 > 0) 274 | return { 275 | error: true, 276 | type: "time", 277 | time: parseSeconds( 278 | Math.floor(timeout - (Date.now() - lastHourly) / 1000) 279 | ), 280 | }; 281 | else { 282 | data.lastHourly = Date.now(); 283 | data = amount( 284 | data, 285 | "add", 286 | "wallet", 287 | settings.amount, 288 | arguments.callee 289 | .toString() 290 | .substring(15, arguments.callee.toString().indexOf("(")) 291 | ); 292 | if ((Date.now() - lastHourly) / 1000 > timeout * 2) data.streak.hourly = 0; 293 | data.streak.hourly += 1; 294 | await saveUser(data); 295 | event.emit("userUpdate", oldData, data); 296 | return { 297 | error: false, 298 | type: "success", 299 | amount: settings.amount, 300 | rawData: data, 301 | }; 302 | } 303 | } 304 | // =================================================================== 305 | async function rob(settings) { 306 | if (typeof settings.guild === "string") settings.guild.id = settings.guild; 307 | if (typeof settings.user === "string") settings.user.id = settings.user; 308 | if (!settings.guild) 309 | settings.guild = { 310 | id: null, 311 | }; 312 | let user1 = await findUser( 313 | settings, 314 | null, 315 | null, 316 | arguments.callee 317 | .toString() 318 | .substring(15, arguments.callee.toString().indexOf("(")) 319 | ); 320 | const oldData = user1; 321 | let user2 = await cs.findOne({ 322 | userID: settings.user2.id, 323 | guildID: settings.guild.id || null, 324 | }); 325 | if (!user2) user2 = await makeUser(settings, true); 326 | const oldData2 = user2; 327 | let lastRob = user1.lastRob; 328 | let timeout = settings.cooldown; 329 | 330 | if (lastRob !== null && timeout - (Date.now() - lastRob) / 1000 > 0) 331 | return { 332 | error: true, 333 | type: "time", 334 | time: parseSeconds(Math.floor(timeout - (Date.now() - lastRob) / 1000)), 335 | }; 336 | 337 | if (user1.wallet < settings.minAmount - 2) 338 | return { 339 | error: true, 340 | type: "low-money", 341 | minAmount: settings.minAmount, 342 | }; 343 | if (user2.wallet < settings.minAmount - 2) 344 | return { 345 | error: true, 346 | type: "low-wallet", 347 | user2: settings.user2, 348 | minAmount: settings.minAmount, 349 | }; 350 | let max = settings.maxRob; 351 | if (!max || max < 1000) max = 1000; 352 | let random = Math.floor(Math.random() * (Math.floor(max || 1000) - 99)) + 99; 353 | if (random > user2.wallet) random = user2.wallet; 354 | user1.lastRob = Date.now(); 355 | // 5 here is percentage of success. 356 | if (testChance(settings.successPercentage || 5)) { 357 | // Success! 358 | user2 = amount( 359 | user2, 360 | "remove", 361 | "wallet", 362 | random, 363 | arguments.callee 364 | .toString() 365 | .substring(15, arguments.callee.toString().indexOf("(")) 366 | ); 367 | user1 = amount( 368 | user1, 369 | "add", 370 | "wallet", 371 | random, 372 | arguments.callee 373 | .toString() 374 | .substring(15, arguments.callee.toString().indexOf("(")) 375 | ); 376 | 377 | await saveUser(user1, user2); 378 | event.emit("userUpdate", oldData, user1, oldData2, user2); 379 | return { 380 | error: false, 381 | type: "success", 382 | user2: settings.user2, 383 | minAmount: settings.minAmount, 384 | amount: random, 385 | }; 386 | } else { 387 | // Fail :( 388 | if (random > user1.wallet) random = user1.wallet; 389 | user2 = amount( 390 | user2, 391 | "add", 392 | "wallet", 393 | random, 394 | arguments.callee 395 | .toString() 396 | .substring(15, arguments.callee.toString().indexOf("(")) 397 | ); 398 | user1 = amount( 399 | user1, 400 | "remove", 401 | "wallet", 402 | random, 403 | arguments.callee 404 | .toString() 405 | .substring(15, arguments.callee.toString().indexOf("(")) 406 | ); 407 | await saveUser(user1, user2); 408 | event.emit("userUpdate", oldData, user1, oldData2, user2); 409 | return { 410 | error: true, 411 | type: "caught", 412 | user2: settings.user2, 413 | minAmount: settings.minAmount, 414 | amount: random, 415 | }; 416 | } 417 | } 418 | // =================================================================== 419 | async function beg(settings) { 420 | let data = await findUser( 421 | settings, 422 | null, 423 | null, 424 | arguments.callee 425 | .toString() 426 | .substring(15, arguments.callee.toString().indexOf("(")) 427 | ); 428 | const oldData = data; 429 | let beg = data.lastBegged; // XDDDD 430 | let timeout = 240; 431 | if (parseInt(settings.cooldown)) timeout = parseInt(settings.cooldown); 432 | if (beg !== null && timeout - (Date.now() - beg) / 1000 > 0) 433 | return { 434 | error: true, 435 | type: "time", 436 | time: parseSeconds(Math.floor(timeout - (Date.now() - beg) / 1000)), 437 | }; 438 | else { 439 | const amountt = Math.round( 440 | (settings.minAmount || 200) + Math.random() * (settings.maxAmount || 400) 441 | ); 442 | data.lastBegged = Date.now(); 443 | data.begTimeout = timeout; 444 | data = amount( 445 | data, 446 | "add", 447 | "wallet", 448 | amountt, 449 | arguments.callee 450 | .toString() 451 | .substring(15, arguments.callee.toString().indexOf("(")) 452 | ); 453 | await saveUser(data); 454 | event.emit("userUpdate", oldData, data); 455 | 456 | return { 457 | error: false, 458 | type: "success", 459 | amount: amountt, 460 | }; 461 | } 462 | } 463 | // =================================================================== 464 | // =================================================================== 465 | // This is for Rob Command 466 | function testChance(successPercentage) { 467 | let random = Math.random() * 10; 468 | return (random -= successPercentage) < 0; 469 | } 470 | 471 | module.exports = { 472 | monthly, 473 | daily, 474 | weekly, 475 | quaterly, 476 | beg, 477 | rob, 478 | hafly, 479 | hourly, 480 | yearly, 481 | }; 482 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Silent-Coder 3 | * @license Apache-2.0 4 | * @copyright Silent-Coder 5 | * @file index.js 6 | */ 7 | 8 | const { 9 | findUser, 10 | getInventory, 11 | connect, 12 | event, 13 | saveUser, 14 | } = require("./functions/global"); 15 | /** 16 | * @class CurrencySystem 17 | */ 18 | class CurrencySystem { 19 | setMongoURL(password, toLog = true) { 20 | if (!password.startsWith("mongodb")) 21 | throw new TypeError("Invalid MongoURL"); 22 | connect(password, toLog); 23 | process.mongoURL = password; 24 | event.emit( 25 | "debug", 26 | `[ CS => Debug ] : Successfully saved MongoDB URL ( Used in Shop Functions )` 27 | ); 28 | } 29 | 30 | async buy(settings) { 31 | return await _buy(settings); 32 | } 33 | 34 | async addUserItem(settings) { 35 | return await _buy(settings); 36 | } 37 | 38 | async addItem(settings) { 39 | if (!settings.inventory) 40 | return { 41 | error: true, 42 | type: "No-Inventory", 43 | }; 44 | if (!settings.inventory.name) 45 | return { 46 | error: true, 47 | type: "No-Inventory-Name", 48 | }; 49 | if (!settings.inventory.price) 50 | return { 51 | error: true, 52 | type: "No-Inventory-Price", 53 | }; 54 | if (!parseInt(settings.inventory.price)) 55 | return { 56 | error: true, 57 | type: "Invalid-Inventory-Price", 58 | }; 59 | const item = { 60 | name: String(settings.inventory.name) || "Air", 61 | price: parseInt(settings.inventory.price) || 0, 62 | description: String(settings.inventory.description) || "No Description", 63 | itemId: makeid(), 64 | }; 65 | if (typeof settings.guild === "string") 66 | settings.guild = { 67 | id: settings.guild, 68 | }; 69 | if (!settings.guild) 70 | settings.guild = { 71 | id: null, 72 | }; 73 | require("./models/inventory").findOneAndUpdate( 74 | { 75 | guildID: settings.guild.id || null, 76 | }, 77 | { 78 | $push: { 79 | inventory: item, 80 | }, 81 | }, 82 | { 83 | upsert: true, 84 | useFindAndModify: false, 85 | }, 86 | (e, d) => { 87 | if (e) return console.log(e); 88 | } 89 | ); 90 | 91 | return { 92 | error: false, 93 | item: item, 94 | }; 95 | } 96 | async removeItem(settings) { 97 | let inventoryData = await getInventory(settings); 98 | 99 | let thing = parseInt(settings.item); 100 | if (!thing) 101 | return { 102 | error: true, 103 | type: "Invalid-Item-Number", 104 | }; 105 | thing = thing - 1; 106 | if (!inventoryData.inventory[thing]) 107 | return { 108 | error: true, 109 | type: "Unknown-Item", 110 | }; 111 | const deletedDB = inventoryData.inventory[thing]; 112 | inventoryData.inventory.splice(thing, 1); 113 | inventoryData.save(); 114 | return { 115 | error: false, 116 | inventory: deletedDB, 117 | }; 118 | } 119 | async setItems(settings) { 120 | // let inventoryData = await getInventory(settings); 121 | 122 | if (!settings.shop) 123 | return { 124 | error: true, 125 | type: "No-Shop", 126 | }; 127 | if (!Array.isArray(settings.shop)) 128 | return { 129 | error: true, 130 | type: "Invalid-Shop", 131 | }; 132 | for (const x of settings.shop) { 133 | if (!x.name) 134 | return { 135 | error: true, 136 | type: "Invalid-Shop-name", 137 | }; 138 | if (!x.price) 139 | return { 140 | error: true, 141 | type: "Invalid-Shop-price", 142 | }; 143 | if (!x.description) x.description = "No Description."; 144 | } 145 | require("./models/inventory").findOneAndUpdate( 146 | { 147 | guildID: settings.guild.id || null, 148 | }, 149 | { 150 | $set: { 151 | inventory: settings.shop, 152 | }, 153 | }, 154 | { 155 | upsert: true, 156 | useFindAndModify: false, 157 | }, 158 | (e, d) => { 159 | if (e) return console.log(e); 160 | } 161 | ); 162 | return { 163 | error: false, 164 | type: "success", 165 | }; 166 | } 167 | async removeUserItem(settings) { 168 | let data = await findUser(settings, null, null, "removeUserItem"); 169 | let item = null; 170 | let thing = parseInt(settings.item); 171 | if (!thing) 172 | return { 173 | error: true, 174 | type: "Invalid-Item-Number", 175 | }; 176 | thing = thing - 1; 177 | if (!data.inventory[thing]) 178 | return { 179 | error: true, 180 | type: "Unknown-Item", 181 | }; 182 | let done = false; 183 | // Save change 184 | let data_user = {}; 185 | 186 | let data_error = { 187 | error: true, 188 | type: "Invalid-Item-Number", 189 | }; 190 | 191 | // If user want remove all items 192 | if (settings.amount == "all") { 193 | // Find index of item 194 | let i = 195 | data.inventory.findIndex( 196 | (i) => i === data.inventory.filter((inv) => inv.name === thing) 197 | ) + 1; 198 | let data_to_save = { 199 | count: 0, 200 | name: data.inventory[i].name, 201 | deleted: data.inventory[i].amount, 202 | itemId: data.inventory[i].itemId, 203 | }; 204 | data_user = data_to_save; 205 | item = data.inventory[i]; 206 | data.inventory.splice(i, 1); 207 | done = true; 208 | } else { 209 | for (let i in data.inventory) { 210 | if (data.inventory[i] === data.inventory[thing]) { 211 | // If in inventory the number of item is greater to 1 and no amount specified 212 | if (data.inventory[i].amount > 1 && !settings?.amount) { 213 | item = data.inventory[i]; 214 | data.inventory[i].amount--; 215 | 216 | let data_to_save = { 217 | count: data.inventory[i].amount, 218 | name: data.inventory[i].name, 219 | deleted: 1, 220 | itemId: data.inventory[i].itemId, 221 | }; 222 | 223 | data_user = data_to_save; 224 | done = true; 225 | // If in inventory the number of item is equal to 1 and no amount specified 226 | } else if (data.inventory[i].amount === 1 && !settings?.amount) { 227 | let data_to_save = { 228 | count: 0, 229 | name: data.inventory[i].name, 230 | deleted: 1, 231 | itemId: data.inventory[i].itemId, 232 | }; 233 | 234 | data_user = data_to_save; 235 | item = data.inventory[i]; 236 | data.inventory.splice(i, 1); 237 | done = true; 238 | // If number specified 239 | } else if (settings?.amount !== "all") { 240 | // If number specified is greater to number item in inventory 241 | if (settings.amount > data.inventory[i].amount) { 242 | done = false; 243 | data_error.type = "Invalid-Amount"; 244 | } else if (String(settings.amount).includes("-")) { 245 | done = false; 246 | data_error.type = "Negative-Amount"; 247 | } else if (parseInt(settings.amount) === 0) { 248 | done = false; 249 | data_error.type = "Invalid-Amount"; 250 | } else { 251 | item = data.inventory[i]; 252 | data.inventory[i].amount -= settings.amount; 253 | 254 | let data_to_save = { 255 | count: data.inventory[i].amount, 256 | name: data.inventory[i].name, 257 | deleted: settings.amount, 258 | itemId: data.inventory[i].itemId, 259 | }; 260 | 261 | data_user = data_to_save; 262 | done = true; 263 | } 264 | } 265 | } 266 | } 267 | } 268 | if (done == false) return data_error; 269 | 270 | require("./models/currency").findOneAndUpdate( 271 | { 272 | guildID: settings.guild.id || null, 273 | userID: settings.user.id || null, 274 | }, 275 | { 276 | $set: { 277 | inventory: data.inventory, 278 | }, 279 | }, 280 | { 281 | upsert: true, 282 | useFindAndModify: false, 283 | }, 284 | (e, d) => { 285 | if (e) return console.log(e); 286 | } 287 | ); 288 | 289 | return { 290 | error: false, 291 | inventory: data_user, 292 | rawData: data, 293 | item: item, 294 | }; 295 | } 296 | async transferItem(settings) { 297 | if (!settings.guild) 298 | settings.guild = { 299 | id: null, 300 | }; 301 | 302 | event.emit("debug", `[ CS => Debug ] : transferItem Function is Executed.`); 303 | event.emit("debug", `[ CS => Debug ] : Fetching User ( Buy Function )`); 304 | let user1 = await findUser( 305 | { user: settings.user1, guild: settings.guild }, 306 | null, 307 | null, 308 | "transferItem" 309 | ); 310 | let user2 = await findUser( 311 | { user: settings.user2, guild: settings.guild }, 312 | null, 313 | null, 314 | "transferItem" 315 | ); 316 | let name, amount_to_transfer, itemsLeft; 317 | // item 318 | let thing = parseInt(settings.item); 319 | if (!thing) 320 | return { 321 | error: true, 322 | type: "No-Item", 323 | }; 324 | thing = thing - 1; 325 | // check if item exists 326 | if (!user1.inventory[thing]) return { error: true, type: "Invalid-Item" }; 327 | // Amount 328 | amount_to_transfer = settings.amount; 329 | if (amount_to_transfer === "all" || amount_to_transfer === "max") { 330 | let user2_has_item = false; 331 | let ifHasItem_then_index = 0; 332 | for (let i = 0; i < user1.inventory.length; i++) { 333 | if (user2.inventory[i].name === user1.inventory[thing].name) { 334 | user2_has_item = true; 335 | ifHasItem_then_index = i; 336 | } 337 | } 338 | amount_to_transfer = user1.inventory[thing].amount; 339 | name = user1.inventory[thing].name; 340 | itemsLeft = 0; 341 | if (user2_has_item === false) 342 | user2.inventory.push(user1.inventory[thing]); 343 | else 344 | user2.inventory[ifHasItem_then_index].amount += 345 | user1.inventory[thing].amount; 346 | 347 | user1.inventory.splice(thing, 1); 348 | } else { 349 | amount_to_transfer = parseInt(amount_to_transfer) || 1; 350 | if (amount_to_transfer <= 0) 351 | return { error: true, type: "Invalid-Amount" }; 352 | if (amount_to_transfer > user1.inventory[thing].amount) 353 | return { error: true, type: "In-Sufficient-Amount" }; 354 | let user2_has_item = false; 355 | let ifHasItem_then_index = 0; 356 | for (let i = 0; i < user2.inventory.length; i++) { 357 | if (user2.inventory[i].name === user1.inventory[thing].name) { 358 | user2_has_item = true; 359 | ifHasItem_then_index = i; 360 | } 361 | } 362 | name = user1.inventory[thing].name; 363 | if (user2_has_item === false) 364 | user2.inventory.push({ 365 | name: user1.inventory[thing].name, 366 | amount: amount_to_transfer, 367 | }); 368 | else user2.inventory[ifHasItem_then_index].amount += amount_to_transfer; 369 | user1.inventory[thing].amount -= amount_to_transfer; 370 | itemsLeft = user1.inventory[thing].amount; 371 | } 372 | user1.markModified("inventory"); 373 | user2.markModified("inventory"); 374 | await saveUser(user1, user2); 375 | return { 376 | error: false, 377 | type: "success", 378 | transfered: amount_to_transfer, 379 | itemName: name, 380 | itemsLeft: itemsLeft, 381 | }; 382 | } 383 | } 384 | 385 | Object.assign(CurrencySystem.prototype, require("./functions/global")); 386 | module.exports = CurrencySystem; 387 | 388 | function _getDbURL() { 389 | let url = process.mongoURL; 390 | if (require("mongoose").connections.length) 391 | url = require("mongoose").connections[0]._connectionString; 392 | return url; 393 | } 394 | module.exports.cs = event; 395 | 396 | async function _buy(settings) { 397 | event.emit("debug", `[ CS => Debug ] : Buy Function is Executed.`); 398 | let inventoryData = await getInventory(settings); 399 | event.emit("debug", `[ CS => Debug ] : Fetching Inventory. ( Buy Function )`); 400 | 401 | event.emit("debug", `[ CS => Debug ] : Fetching User ( Buy Function )`); 402 | let data = await findUser(settings, null, null, "buy"); 403 | 404 | if (!settings.guild) 405 | settings.guild = { 406 | id: null, 407 | }; 408 | let amount_to_add = parseInt(settings.amount) || 1; 409 | let thing = parseInt(settings.item); 410 | if (!thing) 411 | return { 412 | error: true, 413 | type: "No-Item", 414 | }; 415 | thing = thing - 1; 416 | if (!inventoryData.inventory[thing]) 417 | return { 418 | error: true, 419 | type: "Invalid-Item", 420 | }; 421 | let price = inventoryData.inventory[thing].price; 422 | if (amount_to_add > 1) 423 | price = amount_to_add * inventoryData.inventory[thing].price; 424 | 425 | if (data.wallet < price) 426 | return { 427 | error: true, 428 | type: "low-money", 429 | }; 430 | if (amount_to_add <= 0) return { error: true, type: "Invalid-Amount" }; 431 | data.wallet -= price; 432 | let done = false; 433 | for (let j in data.inventory) { 434 | if (inventoryData.inventory[thing].name === data.inventory[j].name) { 435 | data.inventory[j].amount += amount_to_add || 1; 436 | if (!data.inventory[j].itemId) 437 | data.inventory[j].itemId = 438 | inventoryData.inventory[thing].itemId || makeid(); 439 | 440 | done = true; 441 | } 442 | } 443 | if (done == false) { 444 | data.inventory.push({ 445 | name: inventoryData.inventory[thing].name, 446 | amount: amount_to_add || 1, 447 | itemId: inventoryData.inventory[thing].itemId || makeid(), 448 | }); 449 | } 450 | require("./models/currency").findOneAndUpdate( 451 | { 452 | guildID: settings.guild.id || null, 453 | userID: settings.user.id || null, 454 | }, 455 | { 456 | $set: { 457 | inventory: data.inventory, 458 | wallet: data.wallet, 459 | }, 460 | }, 461 | { 462 | upsert: true, 463 | useFindAndModify: false, 464 | }, 465 | (e, d) => { 466 | if (e) return console.error(e); 467 | } 468 | ); 469 | event.emit("debug", `[ CS => Debug ] : Updating Inventory ( Buy Function )`); 470 | return { 471 | error: false, 472 | type: "success", 473 | inventory: inventoryData.inventory[thing], 474 | price: price, 475 | amount: amount_to_add, 476 | }; 477 | } 478 | function makeid(length = 5) { 479 | let result = ""; 480 | let characters = 481 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 482 | for (let i = 0; i < length; i++) 483 | result += characters.charAt(Math.floor(Math.random() * characters.length)); 484 | return result; 485 | } 486 | -------------------------------------------------------------------------------- /src/functions/management.js: -------------------------------------------------------------------------------- 1 | const { event, parseSeconds } = require("./global"); 2 | const cs = require("../models/currency"); 3 | let wallet; // makeUser, setDefaultWalletAmount 4 | let bank; // makeUser, setDefaultBankAmount 5 | let maxBank; // setMaxBankAmount, amount, findUser, makeUser 6 | 7 | // =================================================================== 8 | function setDefaultWalletAmount(amount) { 9 | if (parseInt(amount)) wallet = amount || 0; 10 | } 11 | // =================================================================== 12 | function setDefaultBankAmount(amount) { 13 | if (parseInt(amount)) bank = amount || 0; 14 | } 15 | // =================================================================== 16 | function setMaxBankAmount(amount) { 17 | if (parseInt(amount)) maxBank = amount || 0; 18 | } 19 | // =================================================================== 20 | async function findUser(settings, uid, gid, by) { 21 | if (typeof settings.user === "string") 22 | settings.user = { 23 | id: settings.user, 24 | }; 25 | if (typeof settings.guild === "string") 26 | settings.guild = { 27 | id: settings.guild, 28 | }; 29 | 30 | if (!settings.guild) 31 | settings.guild = { 32 | id: null, 33 | }; 34 | let find = await cs.findOne({ 35 | userID: uid || settings.user.id, 36 | guildID: gid || settings.guild.id || null, 37 | }); 38 | if (!find) find = await makeUser(settings, false, uid, gid); 39 | 40 | if (maxBank > 0 && find.bankSpace == 0) find.bankSpace = maxBank; 41 | if (!find.streak) find.streak = {}; 42 | if (!find.streak.hourly) find.streak.hourly = 0; 43 | if (!find.streak.daily) find.streak.daily = 0; 44 | if (!find.streak.weekly) find.streak.weekly = 0; 45 | if (!find.streak.monthly) find.streak.monthly = 0; 46 | if (!find.streak.yearly) find.streak.yearly = 0; 47 | if (!find.streak.hafly) find.streak.hafly = 0; 48 | if (!find.streak.quaterly) find.streak.quaterly = 0; 49 | try { 50 | event.emit( 51 | "userFetch", 52 | find, 53 | by 54 | .split(" ") 55 | .map((w) => w[0].toUpperCase() + w.substr(1).toLowerCase()) 56 | .join(" ") 57 | ); 58 | } catch (e) { } 59 | return find; 60 | } 61 | // =================================================================== 62 | async function makeUser(settings, user2 = false, uid, gid) { 63 | if (typeof settings.user === "string") 64 | settings.user = { 65 | id: settings.user, 66 | }; 67 | if (typeof settings.guild === "string") 68 | settings.guild = { 69 | id: settings.guild, 70 | }; 71 | if (!settings.guild) 72 | settings.guild = { 73 | id: null, 74 | }; 75 | let user = uid || settings.user.id; 76 | if (user2) user = settings.user2.id; 77 | const newUser = new cs({ 78 | userID: user, 79 | guildID: gid || settings.guild.id || null, 80 | wallet: wallet || 0, 81 | bank: bank || 0, 82 | bankSpace: maxBank || 0, 83 | streak: { 84 | hourly: 0, 85 | daily: 0, 86 | weekly: 0, 87 | monthly: 0, 88 | yearly: 0, 89 | hafly: 0, 90 | quaterly: 0, 91 | }, 92 | }); 93 | if (!newUser) 94 | throw new Error( 95 | "Missing data to fetch from DB. (A function in Currency System is used and userID wasn't provided.)" 96 | ); 97 | // await saveUser(newUser); 98 | event.emit("userCreate", newUser); 99 | return newUser; 100 | } 101 | // =================================================================== 102 | async function saveUser(data, data2) { 103 | // this will prevent error 104 | // ParallelSaveError: Can't save() the same doc multiple times in parallel. 105 | // await sleep(Math.floor((Math.random() * 10) + 1) * 100) // 100 - 1000 random Number generator 106 | // await data.save(function (err) { 107 | // if (err) throw err; 108 | // }); 109 | // if (data2) { 110 | // await sleep(Math.floor((Math.random() * 10) + 1) * 100) // 100 - 1000 random Number generator 111 | // await data2.save(function (err) { 112 | // if (err) throw err; 113 | // }); 114 | // } 115 | process.nextTick( 116 | async () => { 117 | await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator 118 | data.save((_) => 119 | _ 120 | ? console.error( 121 | `ERROR Occured while saving data (Currency-system) \n${"=".repeat( 122 | 50 123 | )}\n${_ + "\n" + "=".repeat(50)}` 124 | ) 125 | : "No Error" 126 | ); 127 | if (data2) 128 | data2.save((_) => 129 | _ 130 | ? console.error( 131 | `ERROR Occured while saving data (Currency-system) \n${"=".repeat( 132 | 50 133 | )}\n${_ + "\n" + "=".repeat(50)}` 134 | ) 135 | : "No Error" 136 | ); 137 | }, 138 | data, 139 | data2 140 | ); 141 | } 142 | // =================================================================== 143 | function sleep(milliseconds) { 144 | return new Promise((resolve) => { 145 | setTimeout(resolve, milliseconds); 146 | }); 147 | } 148 | // =================================================================== 149 | function amount(data, type = "add", where = "wallet", amount, by) { 150 | if (!data.bankSpace) data.bankSpace = maxBank || 0; 151 | 152 | if (where === "bank") { 153 | if (type === "add") data.bank += amount; 154 | else data.bank -= amount; 155 | } else { 156 | if (type === "add") data.wallet += amount; 157 | else data.wallet -= amount; 158 | } 159 | if (data.bankSpace > 0 && data.bank > data.bankSpace) { 160 | const a = data.bank; 161 | data.bank = data.bankSpace; 162 | data.wallet += Math.abs(a - data.bankSpace); 163 | } 164 | if (!data.networth) data.networth = 0; 165 | data.networth = data.bank + data.wallet; 166 | try { 167 | event.emit( 168 | "balanceUpdate", 169 | data, 170 | by 171 | .split(" ") 172 | .map((w) => w[0].toUpperCase() + w.substr(1).toLowerCase()) 173 | .join(" ") 174 | ); 175 | } catch (E) { } 176 | return data; 177 | } 178 | // =================================================================== 179 | async function setBankSpace(userID, guildID, newAmount) { 180 | let data = await findUser( 181 | {}, 182 | userID, 183 | guildID, 184 | arguments.callee 185 | .toString() 186 | .substring(15, arguments.callee.toString().indexOf("(")) 187 | ); 188 | newAmount = parseInt(newAmount); 189 | if (!newAmount && newAmount !== 0) 190 | return { 191 | error: true, 192 | type: "no-amount-provided", 193 | rawData: data, 194 | }; 195 | let oldData = Object.assign({}, data); 196 | data.bankSpace = newAmount; 197 | await saveUser(data); 198 | event.emit("userUpdate", oldData, data); 199 | if (oldData.bankSpace !== data.bankSpace) 200 | return { 201 | error: false, 202 | type: "success", 203 | amount: data.bankSpace, 204 | rawData: data, 205 | }; 206 | else 207 | return { 208 | error: true, 209 | type: "same-amount", 210 | rawData: data, 211 | }; 212 | } 213 | // =================================================================== 214 | async function gamble(settings) { 215 | let data = await findUser( 216 | settings, 217 | null, 218 | null, 219 | arguments.callee 220 | .toString() 221 | .substring(15, arguments.callee.toString().indexOf("(")) 222 | ); 223 | const oldData = data; 224 | const money = parseInt(settings.amount); 225 | const result = Math.floor(Math.random() * 10); 226 | const balance = data.wallet; 227 | let lastGamble = data.lastGamble; 228 | let cooldown = settings.cooldown || 50; 229 | if (!money) 230 | return { 231 | error: true, 232 | type: "amount", 233 | }; 234 | if (isNaN(money)) 235 | return { 236 | error: true, 237 | type: "nan", 238 | }; 239 | if (money > balance || !balance || balance === 0) 240 | return { 241 | error: true, 242 | type: "low-money", 243 | neededMoney: Math.abs(balance - money), 244 | }; 245 | if (money < settings.minAmount || 0) 246 | return { 247 | error: true, 248 | type: "gamble-limit", 249 | minAmount: settings.minAmount || 0, 250 | }; 251 | if (lastGamble !== null && cooldown - (Date.now() - lastGamble) / 1000 > 0) 252 | return { 253 | error: true, 254 | type: "time", 255 | second: parseSeconds( 256 | Math.floor(cooldown - (Date.now() - lastGamble) / 1000) 257 | ), 258 | }; 259 | 260 | if (result <= 5) { 261 | data.lastGamble = Date.now(); 262 | data = amount( 263 | data, 264 | "remove", 265 | "wallet", 266 | money, 267 | arguments.callee 268 | .toString() 269 | .substring(15, arguments.callee.toString().indexOf("(")) 270 | ); 271 | await saveUser(data); 272 | return { 273 | error: false, 274 | type: "lost", 275 | amount: money, 276 | wallet: data.wallet, 277 | }; 278 | } else if (result > 5) { 279 | data.lastGamble = Date.now(); 280 | 281 | data = amount( 282 | data, 283 | "add", 284 | "wallet", 285 | money, 286 | arguments.callee 287 | .toString() 288 | .substring(15, arguments.callee.toString().indexOf("(")) 289 | ); 290 | 291 | await saveUser(data); 292 | event.emit("userUpdate", oldData, data); 293 | return { 294 | error: false, 295 | type: "won", 296 | amount: money, 297 | wallet: data.wallet, 298 | }; 299 | } 300 | } 301 | // =================================================================== 302 | async function withdraw(settings) { 303 | let data = await findUser( 304 | settings, 305 | null, 306 | null, 307 | arguments.callee 308 | .toString() 309 | .substring(15, arguments.callee.toString().indexOf("(")) 310 | ); 311 | const oldData = data; 312 | let money = String(settings.amount); 313 | 314 | if (!money) 315 | return { 316 | error: true, 317 | type: "money", 318 | }; 319 | if (money.includes("-")) 320 | return { 321 | error: true, 322 | type: "negative-money", 323 | }; 324 | 325 | if (money === "all" || money === "max") { 326 | if (data.bank < 1) 327 | return { 328 | error: true, 329 | type: "no-money", 330 | }; 331 | data.wallet += data.bank; 332 | data.bank = 0; 333 | if (!data.networth) data.networth = 0; 334 | data.networth = data.bank + data.wallet; 335 | event.emit("userUpdate", oldData, data); 336 | await saveUser(data); 337 | return { 338 | error: false, 339 | rawData: data, 340 | type: "all-success", 341 | }; 342 | } else { 343 | money = parseInt(money); 344 | if (data.bank < parseInt(money)) 345 | return { 346 | error: true, 347 | type: "low-money", 348 | }; 349 | if (isNaN(money)) 350 | return { 351 | error: true, 352 | type: "money", 353 | }; 354 | 355 | if (money > data.bank) 356 | return { 357 | error: true, 358 | type: "low-money", 359 | }; 360 | 361 | data.wallet += money; 362 | data.bank -= money; 363 | 364 | await saveUser(data); 365 | event.emit("userUpdate", oldData, data); 366 | return { 367 | error: false, 368 | type: "success", 369 | amount: money, 370 | rawData: data, 371 | }; 372 | } 373 | } 374 | // =================================================================== 375 | async function deposite(settings) { 376 | let data = await findUser( 377 | settings, 378 | null, 379 | null, 380 | arguments.callee 381 | .toString() 382 | .substring(15, arguments.callee.toString().indexOf("(")) 383 | ); 384 | const oldData = data; 385 | let money = String(settings.amount); 386 | 387 | if (!money) 388 | return { 389 | error: true, 390 | type: "money", 391 | }; 392 | if (String(money).includes("-")) 393 | return { 394 | error: true, 395 | type: "negative-money", 396 | }; 397 | 398 | if (money === "all" || money === "max") { 399 | if (data.wallet === 0) 400 | return { 401 | error: true, 402 | type: "no-money", 403 | }; 404 | if (data.bankSpace > 0 && money === "all" && data.bank === data.bankSpace) { 405 | return { 406 | error: true, 407 | rawData: data, 408 | type: "bank-full", 409 | }; 410 | } 411 | data.bank += data.wallet; 412 | data.wallet = 0; 413 | 414 | if (data.bankSpace > 0 && data.bank > data.bankSpace) { 415 | const a = data.bank; 416 | data.bank = data.bankSpace; 417 | data.wallet += Math.abs(a - data.bankSpace); 418 | } 419 | 420 | if (!data.networth) data.networth = 0; 421 | data.networth = data.bank + data.wallet; 422 | await saveUser(data); 423 | event.emit("userUpdate", oldData, data); 424 | return { 425 | error: false, 426 | rawData: data, 427 | type: "all-success", 428 | }; 429 | } else { 430 | money = parseInt(money); 431 | if (!money) 432 | return { 433 | error: true, 434 | type: "money", 435 | }; 436 | if (money > data.wallet) 437 | return { 438 | error: true, 439 | type: "low-money", 440 | }; 441 | if (data.bankSpace > 0 && data.bank == data.bankSpace) 442 | return { 443 | error: true, 444 | type: "bank-full", 445 | rawData: data, 446 | }; 447 | 448 | data.bank += money; 449 | 450 | if (data.wallet - money < 0) { 451 | const a = data.wallet; 452 | data.wallet = 0; 453 | data.bank -= Math.abs(a - money); 454 | } 455 | 456 | data.wallet -= money; 457 | 458 | if (!data.networth) data.networth = 0; 459 | data.networth = data.bank + data.wallet; 460 | 461 | if (data.bankSpace > 0 && data.bank > data.bankSpace) { 462 | const a = data.bank; 463 | data.bank = data.bankSpace; 464 | data.wallet += Math.abs(a - data.bankSpace); 465 | } 466 | 467 | await saveUser(data); 468 | event.emit("userUpdate", oldData, data); 469 | return { 470 | error: false, 471 | rawData: data, 472 | type: "success", 473 | amount: money, 474 | }; 475 | } 476 | } 477 | // =================================================================== 478 | async function addMoneyToAllUsers(settings) { 479 | if (String(settings.amount).includes("-")) 480 | return { 481 | error: true, 482 | type: "negative-money", 483 | }; 484 | let amountt = parseInt(settings.amount) || 0; 485 | 486 | if (typeof settings.guild === "string") 487 | settings.guild = { 488 | id: settings.guild, 489 | }; 490 | if (!settings.guild) 491 | settings.guild = { 492 | id: null, 493 | }; 494 | let data = await cs.find({ 495 | guildID: settings.guild.id || null, 496 | }); 497 | if (!data) 498 | return { 499 | error: true, 500 | type: "no-users", 501 | }; 502 | const oldData = data; 503 | data.forEach(async (user) => { 504 | if (settings.wheretoPutMoney === "bank") 505 | user = amount( 506 | user, 507 | "add", 508 | "bank", 509 | amountt, 510 | arguments.callee 511 | .toString() 512 | .substring(15, arguments.callee.toString().indexOf("(")) 513 | ); 514 | else 515 | user = amount( 516 | user, 517 | "add", 518 | "wallet", 519 | amountt, 520 | arguments.callee 521 | .toString() 522 | .substring(15, arguments.callee.toString().indexOf("(")) 523 | ); 524 | }); 525 | event.emit("usersUpdate", oldData, data); 526 | 527 | data.forEach((a) => 528 | a.save(function (err, saved) { 529 | if (err) console.log(err); 530 | }) 531 | ); 532 | 533 | return { 534 | error: false, 535 | type: "success", 536 | rawData: data, 537 | }; 538 | } 539 | // =================================================================== 540 | async function addMoney(settings) { 541 | let data = await findUser( 542 | settings, 543 | null, 544 | null, 545 | arguments.callee 546 | .toString() 547 | .substring(15, arguments.callee.toString().indexOf("(")) 548 | ); 549 | const oldData = data; 550 | if (String(settings.amount).includes("-")) 551 | return { 552 | error: true, 553 | type: "negative-money", 554 | }; 555 | let amountt = parseInt(settings.amount) || 0; 556 | if (settings.wheretoPutMoney === "bank") 557 | data = amount( 558 | data, 559 | "add", 560 | "bank", 561 | amountt, 562 | arguments.callee 563 | .toString() 564 | .substring(15, arguments.callee.toString().indexOf("(")) 565 | ); 566 | else 567 | data = amount( 568 | data, 569 | "add", 570 | "wallet", 571 | amountt, 572 | arguments.callee 573 | .toString() 574 | .substring(15, arguments.callee.toString().indexOf("(")) 575 | ); 576 | 577 | event.emit("userUpdate", oldData, data); 578 | await saveUser(data); 579 | return { 580 | error: false, 581 | type: "success", 582 | rawData: data, 583 | }; 584 | } 585 | // =================================================================== 586 | async function removeMoneyFromAllUsers(settings) { 587 | if (String(settings.amount).includes("-")) 588 | return { 589 | error: true, 590 | type: "negative-money", 591 | }; 592 | let amountt = parseInt(settings.amount) || 0; 593 | 594 | if (typeof settings.guild === "string") 595 | settings.guild = { 596 | id: settings.guild, 597 | }; 598 | if (!settings.guild) 599 | settings.guild = { 600 | id: null, 601 | }; 602 | let data = await cs.find({ 603 | guildID: settings.guild.id || null, 604 | }); 605 | if (!data) 606 | return { 607 | error: true, 608 | type: "no-users", 609 | }; 610 | const oldData = data; 611 | 612 | data.forEach(async (user) => { 613 | if (settings.wheretoPutMoney === "bank") { 614 | if (settings.amount === "all" || settings.amount === "max") user.bank = 0; 615 | else 616 | user = amount( 617 | user, 618 | "remove", 619 | "bank", 620 | parseInt(settings.amount) || 0, 621 | arguments.callee 622 | .toString() 623 | .substring(15, arguments.callee.toString().indexOf("(")) 624 | ); 625 | } else { 626 | if (settings.amount === "all" || settings.amount === "max") 627 | user.wallet = 0; 628 | else 629 | user = amount( 630 | user, 631 | "remove", 632 | "wallet", 633 | parseInt(settings.amount) || 0, 634 | arguments.callee 635 | .toString() 636 | .substring(15, arguments.callee.toString().indexOf("(")) 637 | ); 638 | } 639 | }); 640 | event.emit("usersUpdate", oldData, data); 641 | data.forEach((a) => 642 | a.save(function (err, saved) { 643 | if (err) console.log(err); 644 | }) 645 | ); 646 | 647 | return { 648 | error: false, 649 | type: "success", 650 | rawData: data, 651 | }; 652 | } 653 | // =================================================================== 654 | async function removeMoney(settings) { 655 | let data = await findUser( 656 | settings, 657 | null, 658 | null, 659 | arguments.callee 660 | .toString() 661 | .substring(15, arguments.callee.toString().indexOf("(")) 662 | ); 663 | const oldData = data; 664 | if (String(settings.amount).includes("-")) 665 | return { 666 | error: true, 667 | type: "negative-money", 668 | }; 669 | if (settings.wheretoPutMoney === "bank") { 670 | if (settings.amount === "all" || settings.amount === "max") data.bank = 0; 671 | else 672 | data = amount( 673 | data, 674 | "remove", 675 | "bank", 676 | parseInt(settings.amount) || 0, 677 | arguments.callee 678 | .toString() 679 | .substring(15, arguments.callee.toString().indexOf("(")) 680 | ); 681 | } else { 682 | if (settings.amount === "all" || settings.amount === "max") data.wallet = 0; 683 | else 684 | data = amount( 685 | data, 686 | "remove", 687 | "wallet", 688 | parseInt(settings.amount) || 0, 689 | arguments.callee 690 | .toString() 691 | .substring(15, arguments.callee.toString().indexOf("(")) 692 | ); 693 | } 694 | 695 | await saveUser(data); 696 | event.emit("userUpdate", oldData, data); 697 | 698 | return { 699 | error: false, 700 | type: "success", 701 | rawData: data, 702 | }; 703 | } 704 | // =================================================================== 705 | async function transferMoney(settings) { 706 | if (typeof settings.user === "string") 707 | settings.user = { 708 | id: settings.user, 709 | }; 710 | if (typeof settings.guild === "string") 711 | settings.guild = { 712 | id: settings.guild, 713 | }; 714 | if (!settings.guild) 715 | settings.guild = { 716 | id: null, 717 | }; 718 | let user1 = await findUser( 719 | settings, 720 | null, 721 | null, 722 | arguments.callee 723 | .toString() 724 | .substring(15, arguments.callee.toString().indexOf("(")) 725 | ); 726 | const oldData = user1; 727 | let user2 = await cs.findOne({ 728 | userID: settings.user2.id, 729 | guildID: settings.guild.id || null, 730 | }); 731 | if (!user2) user2 = await makeUser(settings, true); 732 | const oldData1 = user2; 733 | let money = parseInt(settings.amount); 734 | if (user1.wallet < money) 735 | return { 736 | error: true, 737 | type: "low-money", 738 | }; 739 | user1 = amount( 740 | user1, 741 | "remove", 742 | "wallet", 743 | money, 744 | arguments.callee 745 | .toString() 746 | .substring(15, arguments.callee.toString().indexOf("(")) 747 | ); 748 | user2 = amount( 749 | user2, 750 | "add", 751 | "wallet", 752 | money, 753 | arguments.callee 754 | .toString() 755 | .substring(15, arguments.callee.toString().indexOf("(")) 756 | ); 757 | 758 | await saveUser(user1, user2); 759 | event.emit("userUpdate", oldData, user1, oldData1, user2); 760 | 761 | return { 762 | error: false, 763 | type: "success", 764 | money: money, 765 | user: settings.user, 766 | user2: settings.user2, 767 | rawData: user1, 768 | rawData1: user2, 769 | }; 770 | } 771 | module.exports = { 772 | removeMoney, 773 | addMoney, 774 | addMoneyToAllUsers, 775 | removeMoneyFromAllUsers, 776 | withdraw, 777 | deposite, 778 | gamble, 779 | setBankSpace, 780 | transferMoney, 781 | setDefaultBankAmount, 782 | setDefaultWalletAmount, 783 | setMaxBankAmount, 784 | findUser, 785 | makeUser, 786 | saveUser, 787 | amount, 788 | }; 789 | --------------------------------------------------------------------------------