Skip to content

Commit

Permalink
Added shop commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Nov 11, 2019
1 parent 67a6711 commit b03969b
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 60 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var result,shards,firstShardID,lastShardID;
(async () => {
try{
//determine how many shards we will need for this manager
if (require('cluster').isMaster){
if (!debug&&require('cluster').isMaster){
result = await request.fetchInit();
shards = result["shards"];
firstShardID = result["firstShardID"];
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../commandinterface.js');
const CommandInterface = require('../../CommandInterface.js');

const ringUtil = require('../social/util/ringUtil.js');
const wallpaperUtil = require('../social/util/wallpaperUtil.js');
Expand All @@ -22,7 +22,7 @@ module.exports = new CommandInterface({

related:["owo shop"],

permissions:["SEND_MESSAGES","EMBED_LINKS","ATTACH_FILES"],
permissions:["sendMessages","embedLinks","attachFiles"],

cooldown:5000,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../commandinterface.js');
const CommandInterface = require('../../CommandInterface.js');

const food = require('../../../json/food.json');
const shopUtil = require('./util/shopUtil.js');
const cowoncy = "<:cowoncy:416043450337853441>";
const lootboxUtil = require('../zoo/lootboxUtil.js');
Expand All @@ -26,14 +25,14 @@ module.exports = new CommandInterface({

related:["owo shop","owo inv","owo equip"],

permissions:["SEND_MESSAGES","EMBED_LINKS","ATTACH_FILES"],
permissions:["sendMessages","embedLinks","attachFiles"],

cooldown:15000,
cooldown:5000,
half:80,
six:500,

execute: function(p){
var item = shopUtil.getItem(p.args);
let item = shopUtil.getItem(p.args);

if(typeof item === 'string' || item instanceof String){
p.send("**🚫 | "+p.msg.author.username+"**, "+item,3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../commandinterface.js');
const CommandInterface = require('../../CommandInterface.js');

const shopUtil = require('./util/shopUtil.js');
const lootbox = require('../zoo/lootbox.js');
Expand All @@ -25,15 +25,15 @@ module.exports = new CommandInterface({

related:["owo inv","owo weapon"],

permissions:["SEND_MESSAGES","EMBED_LINKS","ATTACH_FILES"],
permissions:["sendMessages","embedLinks","attachFiles"],

cooldown:3000,
cooldown:5000,
half:80,
six:500,

execute: function(p){
var con=p.con,msg=p.msg,args=p.args;
var item = shopUtil.getItem(args);
let con=p.con,msg=p.msg,args=p.args;
let item = shopUtil.getItem(args);
if(typeof item === 'string' || item instanceof String){
p.send("**🚫 | "+msg.author.username+"**, "+item,3000);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../commandinterface.js');
const CommandInterface = require('../../CommandInterface.js');

const lootboxUtil = require('../zoo/lootboxUtil.js');
const ringUtil = require('../social/util/ringUtil.js');
Expand All @@ -27,48 +27,43 @@ module.exports = new CommandInterface({

related:["owo equip"],

permissions:["SEND_MESSAGES","EMBED_LINKS"],
permissions:["sendMessages","embedLinks"],

cooldown:10000,
half:80,
six:500,

execute: async function(p){
var con=p.con,msg=p.msg;
let con=p.con,msg=p.msg;

/* {emoji,id,count} */
try{
let promises = await Promise.all([
ringUtil.getItems(p),
lootboxUtil.getItems(p),
gemUtil.getItems(p),
weaponUtil.getItems(p),
crateUtil.getItems(p),
wallpaperUtil.getItems(p)
]);
var text = addToString(promises);
}catch(err){
console.error(err);
return;
}
let promises = await Promise.all([
ringUtil.getItems(p),
lootboxUtil.getItems(p),
gemUtil.getItems(p),
weaponUtil.getItems(p),
crateUtil.getItems(p),
wallpaperUtil.getItems(p)
]);
let text = addToString(promises);


if(text=="") text = "Your inventory is empty :c";
text = "**====== "+msg.author.username+"'s Inventory ======**\n"+text;
p.send(text,null,{split:true});
p.send(text);
}

})

/* Converts an array of items to strings */
function addToString(items){
var sorted = [];
var itemsID = {};
var maxCount = 0;
let sorted = [];
let itemsID = {};
let maxCount = 0;
/* Sort items by id and get largest count*/
for(var i=0;i<items.length;i++){
var itemList = items[i];
for(var key in itemList){
for(let i=0;i<items.length;i++){
let itemList = items[i];
for(let key in itemList){
sorted.push(itemList[key].id);
itemsID[itemList[key].id] = itemList[key];
itemList[key].count = parseInt(itemList[key].count);
Expand All @@ -77,16 +72,16 @@ function addToString(items){
}
sorted.sort((a,b) => a-b);
items = [];
for(var i=0;i<sorted.length;i++){
for(let i=0;i<sorted.length;i++){
items.push(itemsID[sorted[i]]);
}
var digits = Math.trunc(Math.log10(maxCount)+1);
let digits = Math.trunc(Math.log10(maxCount)+1);

/* Add to text */
var text = "";
var count = 0;
for(var i=0;i<items.length;i++){
var item = items[i];
let text = "";
let count = 0;
for(let i=0;i<items.length;i++){
let item = items[i];
text += "`"+((item.id<9)?"0":"")+item.id+"`"+item.emoji+ shopUtil.toSmallNum(item.count,digits);
count++;
if(count==4){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const PageClass = require('./../PageClass.js');

const rings = require('../../../../json/rings.json');
const rings = require('../../../../data/rings.json');

module.exports = class RingPage extends PageClass {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const PageClass = require('./../PageClass.js');

const imagegen = require('../../../../../tokens/imagegen.json');
const imagegen = require('../../../../../../tokens/imagegen.json');
const perPage = 10;
const pictureEmoji = '🖼';
const idOffset = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../commandinterface.js');
const CommandInterface = require('../../CommandInterface.js');

const shopUtil = require('./util/shopUtil.js');
const PageClass = require('./PageClass.js');
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = new CommandInterface({

related:["owo money"],

permissions:["SEND_MESSAGES","EMBED_LINKS","ATTACH_FILES","ADD_REACTIONS"],
permissions:["sendMessages","embedLinks","attachFiles","addReactions"],

cooldown:15000,

Expand All @@ -51,20 +51,20 @@ async function displayShop(p){

let embed = await getPage(p,pages);
let msg = await p.send({embed});
let filter = (reaction,user) => (reaction.emoji.name===nextPageEmoji||reaction.emoji.name===prevPageEmoji)&&user.id==p.msg.author.id;
let collector = await msg.createReactionCollector(filter,{time:180000});
let filter = (emoji,userID) => (emoji.name===nextPageEmoji||emoji.name===prevPageEmoji)&&userID===p.msg.author.id;
let collector = p.reactionCollector.create(msg,filter,{time:900000,idle:120000});

await msg.react(prevPageEmoji);
await msg.react(nextPageEmoji);
await msg.addReaction(prevPageEmoji);
await msg.addReaction(nextPageEmoji);

collector.on('collect', async function(r){
if(r.emoji.name===nextPageEmoji) {
collector.on('collect', async function(emoji){
if(emoji.name===nextPageEmoji) {
if(pages.currentPage<pages.totalPages) pages.currentPage++;
else pages.currentPage = 1;
embed = await getPage(p,pages);
await msg.edit({embed});
}
else if(r.emoji.name===prevPageEmoji){
else if(emoji.name===prevPageEmoji){
if(pages.currentPage>1) pages.currentPage--;
else pages.currentPage = pages.totalPages;
embed = await getPage(p,pages);
Expand All @@ -75,14 +75,14 @@ async function displayShop(p){
collector.on('end',async function(collected){
embed = await getPage(p,pages);
embed.color = 6381923;
await msg.edit("This message is now inactive",{embed});
await msg.edit({content:"This message is now inactive",embed});
});
}

async function getPage(p,pages){
let embed = {
"author":{
"icon_url":p.msg.author.avatarURL()
"icon_url":p.msg.author.avatarURL
},
"color": 4886754,
"footer":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* For more information, see README.md and LICENSE
*/

const global = require('../../../../util/global.js');
const global = require('../../../../utils/global.js');
const numbers = ["⁰","¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹"];
const imagegen = require('../../../../../tokens/imagegen.json');
const imagegen = require('../../../../../../tokens/imagegen.json');
const nextPageEmoji = '➡';
const prevPageEmoji = '⬅';

Expand Down Expand Up @@ -92,7 +92,7 @@ async function getWallpaperPage(p,currentPage,totalPages){
embed = {
"author":{
"name":"OwO Shop: Wallpapers",
"icon_url":p.msg.author.avatarURL()
"icon_url":p.msg.author.avatarURL
},
"color": 4886754,
"footer":{
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commandList/social/util/wallpaperUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ exports.buy = async function(p,id){
let embed = {
"author":{
"name":p.msg.author.username+", you have successfully purchased \""+result[0][0].bname+"\"!",
"icon_url":p.msg.author.avatarURL()
"icon_url":p.msg.author.avatarURL
},
"color": 4886754,
"image":{
Expand Down

0 comments on commit b03969b

Please sign in to comment.