From 784b6fc90f16af6f69f14b9415f82dc5429b2485 Mon Sep 17 00:00:00 2001 From: Alee Date: Thu, 29 Mar 2018 19:42:42 -0400 Subject: Wheeeee new buy command!!!!! --- bot_discord.js | 4 +- commands/buy.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ commands/changelog.js | 9 ++-- commands/help.js | 2 +- items.json | 20 ++++++++ package-lock.json | 5 ++ package.json | 1 + 7 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 commands/buy.js create mode 100644 items.json diff --git a/bot_discord.js b/bot_discord.js index f02745c..03834a3 100644 --- a/bot_discord.js +++ b/bot_discord.js @@ -25,8 +25,8 @@ const Discord = require('discord.js'); const economy = require('discord-eco'); const client = new Discord.Client(); -const abVersion = '2.4.0'; -const prefix = 'ab:'; +const abVersion = '2.5.0 Beta'; +const prefix = 'abb:'; const fs = require('fs'); const config = require('./absettings.json'); console.log('Welcome to AleeBot NodeJS Terminal!'); diff --git a/commands/buy.js b/commands/buy.js new file mode 100644 index 0000000..89422ad --- /dev/null +++ b/commands/buy.js @@ -0,0 +1,124 @@ +/******************************** + * + * Buy: Command for AleeBot + * + * Copyright (c) 2018 AleeCorp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + ********************************/ +module.exports.run = async (client, message, args) => { + const economy = require('discord-eco') + const Discord = require('discord.js'); + const fs = require('fs') + const items = JSON.parse(fs.readFileSync('./items.json', 'utf8')); + + let categories = []; + + if (!args.join(" ")) { + + + for (var i in items) { + + + if (!categories.includes(items[i].type)) { + categories.push(items[i].type) + } + + } + + + const embed = new Discord.RichEmbed() + .setDescription(`Available Items`) + .setColor('#1fd619') + + for (var i = 0; i < categories.length; i++) { + + var tempDesc = ''; + + for (var c in items) { + if (categories[i] === items[c].type) { + + tempDesc += `${items[c].name} - $${items[c].price} - ${items[c].desc}\n`; + + } + + } + + embed.addField(categories[i], tempDesc); + + } + + + return message.channel.send({ + embed + }); + + + } + + let itemName = ''; + let itemPrice = 0; + let itemDesc = ''; + + for (var i in items) { + if (args.join(" ").trim().toUpperCase() === items[i].name.toUpperCase()) { + itemName = items[i].name; + itemPrice = items[i].price; + itemDesc = items[i].desc; + } + } + + + if (itemName === '') { + return message.channel.send(`Item ${args.join(" ").trim()} not found.`) + } + + + economy.fetchBalance(message.author.id + message.guild.id).then((i) => { + if (i.money <= itemPrice) { + + return message.channel.send(`You don't have enough money for this item.`); + } + + economy.updateBalance(message.author.id + message.guild.id, parseInt(`-${itemPrice}`)).then((i) => { + + message.channel.send('You bought ' + itemName + '!'); + + + if (itemName === 'Programmer Role') { + message.guild.members.get(message.author.id).addRole(message.guild.roles.find("name", "Programmers")); + } + + }) + + }) + + }; + + exports.conf = { + aliases: [], + guildOnly: false, + }; + exports.help = { + name: 'buy', + description: 'Buy things.', + usage: 'buy [item]', + category: '- Economy Commands', + }; + \ No newline at end of file diff --git a/commands/changelog.js b/commands/changelog.js index 8b5f70a..faf4aaa 100644 --- a/commands/changelog.js +++ b/commands/changelog.js @@ -25,12 +25,9 @@ module.exports.run = async (client, message) => { const Discord = require('discord.js'); const embed = new Discord.RichEmbed() - .setAuthor('AleeBot ' + '2.4.0 ' + 'Changelog', 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048') - .setDescription('What\'s new in AleeBot 2.4?') - .addField('[>] Suggestion Command!','Suggest command is only for exclusive servers!', true) - .addField('[>] Ban and kick reasons!','Now you can ban and kick people within reasons!', true) - .addField('[>] Economy!','Yes, it\'s true we\'ve now added economy in AleeBot but for now you can check for your balance!', true) - .setFooter('AleeCorp Copyright 2017') + .setAuthor('AleeBot ' + '2.5.0 Beta ' + 'Changelog', 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048') + .setDescription('What\'s new in AleeBot 2.5?') + .addField('[>] Buy Command!','Now you could buy things!', true) .setColor('#1fd619'); message.channel.sendEmbed(embed); diff --git a/commands/help.js b/commands/help.js index 6634e68..de59c3e 100644 --- a/commands/help.js +++ b/commands/help.js @@ -35,7 +35,7 @@ module.exports.run = async (client, message) => { const embed = new Discord.RichEmbed() .setTitle('AleeBot Help') - .setAuthor('AleeBot 2.4.0' + ` Help and on ${client.guilds.size} servers`, 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048') + .setAuthor('AleeBot 2.5.0 Beta' + ` Help and on ${client.guilds.size} servers`, 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048') .setDescription('Every command you input into AleeBot is `' + require('../absettings.json').prefix + '`') .setColor('#1fd619') .setFooter('AleeCorp Copyright 2018'); diff --git a/items.json b/items.json new file mode 100644 index 0000000..38054f8 --- /dev/null +++ b/items.json @@ -0,0 +1,20 @@ +{ + "Ping" : { + "name": "Ping Command", + "price": "10", + "type": "Commands", + "desc": "Buying this gives you access to ping command." + }, + "Programmer" : { + "name": "Programmer Role", + "price": "100", + "type": "Roles", + "desc": "Buying this gives you the programmer role" + }, + "theShell" : { + "name": "theShell OS", + "price": "400", + "type": "OS", + "desc": "Buying this gives you theShell OS" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8ddec42..02cc339 100644 --- a/package-lock.json +++ b/package-lock.json @@ -142,6 +142,11 @@ "ref-struct": "1.1.0" } }, + "os": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/os/-/os-0.1.1.tgz", + "integrity": "sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M=" + }, "prism-media": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.2.tgz", diff --git a/package.json b/package.json index 6cef2c7..96b6e71 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "fs": "0.0.1-security", "moment": "^2.21.0", "node-opus": "^0.2.7", + "os": "^0.1.1", "simple-youtube-api": "^5.0.1", "ytdl-core": "^0.20.2" }, -- cgit v1.2.3