|
| 1 | +const { error, RuneScape, tablePages, postPages } = require('../helpers.js'); |
| 2 | +const { connection, connection_server } = require('../database.js'); |
| 3 | + |
| 4 | +module.exports = { |
| 5 | + name : 'getplayeritems', |
| 6 | + aliases : [], |
| 7 | + description : 'Get a list of players items from bank, inventory or equipment', |
| 8 | + args : ['player name', 'item location', 'page?'], |
| 9 | + guildOnly : true, |
| 10 | + cooldown : 3, |
| 11 | + botperms : ['SEND_MESSAGES'], |
| 12 | + userperms : ['MANAGE_GUILD'], |
| 13 | + execute : async (msg, args) => { |
| 14 | + const match = args.join(' ').trim().match(/^([\sA-Z()+.\-_\d]{1,12})\s+(bank|inventory|equipment)\s*(\d*)$/i); |
| 15 | + |
| 16 | + if (!match) |
| 17 | + return msg.channel.send('Invalid arguments specified.'); |
| 18 | + |
| 19 | + let [,player_name, type, page = 1] = match.map(m=>m.trim().toLowerCase()); |
| 20 | + |
| 21 | + if (player_name.length > 12) |
| 22 | + return msg.channel.send('Invalid arguments specified, Username too long.'); |
| 23 | + |
| 24 | + page = isNaN(page) ? 1 : +page; |
| 25 | + |
| 26 | + const results = await connection.query(`SELECT username, ${type} FROM members WHERE username = ?`, [player_name]).catch(error); |
| 27 | + |
| 28 | + if (!results.length) |
| 29 | + return msg.channel.send('No player found with specified name.'); |
| 30 | + |
| 31 | + let drops = results[0][type].split('|').map(d=>d.split(',')).filter(d=>d[0] > 0); |
| 32 | + |
| 33 | + if (!drops.length) |
| 34 | + return msg.channel.send(`No items in ${type}.`); |
| 35 | + |
| 36 | + let items = [...new Set(drops.map(i=>i[0]))].filter(d=>d[0] > 0).join(','); |
| 37 | + items = await connection_server.query(`SELECT id, name, tradeable, shop_price, grand_exchange_price FROM \`item_configs\` WHERE id IN(${items})`); |
| 38 | + |
| 39 | + drops = drops.map(i=>{ |
| 40 | + let item = items.find(i2=>i2.id==i[0]); |
| 41 | + |
| 42 | + if (!item) |
| 43 | + item = {id: i[0], name: '------', tradeable: null, shop_price: null, grand_exchange_price: null}; |
| 44 | + |
| 45 | + item.amount = i[1]; |
| 46 | + return item; |
| 47 | + }); |
| 48 | + |
| 49 | + drops = drops.map(item=>[ |
| 50 | + item.id, |
| 51 | + item.name.toLowerCase(), |
| 52 | + RuneScape.formatNumber(item.amount || 0), |
| 53 | + item.tradeable ? 'yes' : 'no', |
| 54 | + item.shop_price != null ? RuneScape.formatMoney(item.shop_price) : '---', |
| 55 | + item.grand_exchange_price != null ? RuneScape.formatMoney(item.grand_exchange_price) : '---', |
| 56 | + ]); |
| 57 | + |
| 58 | + const pages = await tablePages(['ID', 'Name', 'Amount', 'Tradeable', 'Shop Price', 'GE Price'], drops, `__***${results[0].username} ${type}:***__`); |
| 59 | + |
| 60 | + postPages(msg, pages, page); |
| 61 | + }, |
| 62 | +}; |
0 commit comments