From 192112d56200f4b19e7d65585568e0cc66b25c07 Mon Sep 17 00:00:00 2001 From: ledlamp Date: Fri, 11 May 2018 23:02:32 -0700 Subject: [PATCH] =?UTF-8?q?Publish=20the=20correct=20version=20?= =?UTF-8?q?=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently editing the project on different computers caused versioning derps and restored an old version. So that's why weird stuff has been happening lately. --- .gitignore | 3 +- src/colorroles.js | 79 +++++++++++++++++++++++++++++------ src/commands.js | 3 +- src/lib/jsmidgen.js | 0 src/lib/mpprecorder-module.js | 0 src/misc.js | 4 +- src/mppbridger.js | 6 +-- src/package-lock.json | 55 ++++++++++++++++++++++++ src/screenshotter.js | 1 + 9 files changed, 131 insertions(+), 20 deletions(-) mode change 100644 => 100755 src/colorroles.js mode change 100644 => 100755 src/commands.js mode change 100644 => 100755 src/lib/jsmidgen.js mode change 100644 => 100755 src/lib/mpprecorder-module.js mode change 100644 => 100755 src/misc.js mode change 100644 => 100755 src/mppbridger.js create mode 100755 src/package-lock.json mode change 100644 => 100755 src/screenshotter.js diff --git a/.gitignore b/.gitignore index 63f396d..9aecbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /local/ -/src/config.json \ No newline at end of file +/src/config.json +node_modules/ \ No newline at end of file diff --git a/src/colorroles.js b/src/colorroles.js old mode 100644 new mode 100755 index 85014e5..aba55b1 --- a/src/colorroles.js +++ b/src/colorroles.js @@ -1,37 +1,90 @@ -global.colorRoles = { - create: async function (member){ - var role = await member.guild.createRole({data:{ +global.colorRoles = { // TODO clean up this, adsfhaiusdhgaisuhg + + create: async function (guild){ // create new color role + var role = await guild.roles.create({data:{ name:"[]", permissions:[], color:"RANDOM", //position: member.guild.roles.get('346754988023873546').position }}); - member.addRole(role); return role; }, - get: function (member){ + + get: function (member){ // get color role of member return member.roles.find(role => {if (role.name.startsWith('[')) return role}); }, - ensure: function (member) { // give color role to member if they don't have one; not sure what to call this + + ensure: async function (member) { // restore or create role for member if they don't have one if (this.get(member)) return; - this.create(member); + if (await this.restore(member)) return; + var role = await this.create(member.guild); + await member.roles.add(role); }, + + pack: async function (member) { // store member color role in database and delete + var role = this.get(member); + if (!role) return; + var json = { + id: role.id, + name: role.name, + color: role.color, + hoist: role.hoist, + position: role.position, + permissions: role.permissions.bitfield, + mentionable: role.mentionable + } + var id = member.id; + var res = await dbClient.query(`SELECT * FROM member_data WHERE id = $1`, [id]); + if (res.rows[0]) { + await dbClient.query(`UPDATE member_data SET color_role = $2 WHERE id = $1`, [id, json]); + } else { + await dbClient.query(`INSERT INTO member_data (id, color_role) VALUES ($1, $2)`, [id, json]); + } // need better sql, oof + role.delete(); + }, + + restore: async function (member) { // load color role from database and reapply to member + var json = (await dbClient.query(`SELECT (color_role) FROM member_data WHERE id = $1`, [member.id])).rows[0]; + if (!json) return false; + else json = json.color_role; + var role = member.guild.roles.get(json.id); + if (!role) role = await member.guild.roles.create({data:{ + name: json.name, + color: json.color, + hoist: json.hoist, + //position: json.position, + permissions: json.permissions, + mentionable: json.mentionable + }}); + member.roles.add(role); + return true; + }, + + + + } + + + + + dClient.on('presenceUpdate', (oldMember, newMember) => { if (newMember.guild.id != config.guildID) return; - if (oldMember.presence.status != newMember.presence.status && newMember.presence.status != "offline") { - colorRoles.ensure(newMember); + if (oldMember.presence.status != newMember.presence.status) { + if (newMember.presence.status == "offline") { + colorRoles.pack(newMember); + } else { + colorRoles.ensure(newMember); + } } }); -//dClient.on('guildMemberAdd', member => colorRoles.ensure(member)); dClient.on('guildMemberRemove', member => { - if (member.guild.id != config.guildID) return; - var role = colorRoles.get(member); - if (role.members.array().length == 0) role.delete(); + colorRoles.pack(member); }); commands.color = { diff --git a/src/commands.js b/src/commands.js old mode 100644 new mode 100755 index e166166..87122a6 --- a/src/commands.js +++ b/src/commands.js @@ -41,7 +41,7 @@ global.commands = { if (!msg.args[0]) return false; //var name = msg.txt(1).replace(/[^a-zA-Z0-9]/g, '-').substr(0,100).toLowerCase(); var name = msg.txt(1); - msg.guild.createChannel(name, { + msg.guild.channels.create(name, { parent: '399735134061985792', overwrites: [ { @@ -66,6 +66,7 @@ global.commands = { 'delete': { usage: "[channel]", aliases: ['archive'], + hidden: true, description: "Archives a channel that you have permission to delete.", exec: async function (msg) { if (msg.args[1]) { diff --git a/src/lib/jsmidgen.js b/src/lib/jsmidgen.js old mode 100644 new mode 100755 diff --git a/src/lib/mpprecorder-module.js b/src/lib/mpprecorder-module.js old mode 100644 new mode 100755 diff --git a/src/misc.js b/src/misc.js old mode 100644 new mode 100755 index 694b9dd..0998bc3 --- a/src/misc.js +++ b/src/misc.js @@ -19,10 +19,10 @@ dClient.on('voiceStateUpdate', (oldMember, newMember) => { if (oldMember.voiceChannelID != vcid && newMember.voiceChannelID == vcid) { // member joined the channel - newMember.addRole(newMember.guild.roles.get(rid)); + newMember.roles.add(newMember.guild.roles.get(rid)); } else if (oldMember.voiceChannelID == vcid && newMember.voiceChannelID != vcid) { // member left the channel - newMember.removeRole(newMember.guild.roles.get(rid)); + newMember.roles.remove(newMember.guild.roles.get(rid)); } }); })(); \ No newline at end of file diff --git a/src/mppbridger.js b/src/mppbridger.js old mode 100644 new mode 100755 index b7dc228..55f17e1 --- a/src/mppbridger.js +++ b/src/mppbridger.js @@ -65,7 +65,7 @@ global.createMPPbridge = function (room, DiscordChannelID, site = 'MPP', webhook msgBuffer = []; }, 2000); //TODO make changeable - const gClient = site == "MPP" ? new Client("ws://www.multiplayerpiano.com:443") : site == "WOPP" ? new Client("ws://ourworldofpixels.com:1234", true) : site == "MPT" ? new Client("ws://23.95.115.204:8080", true) : site == "VFDP" ? new Client("ws://www.visualfiredev.com:8080") : undefined; + const gClient = site == "MPP" ? new Client("ws://www.multiplayerpiano.com:443") : site == "WOPP" ? new Client("ws://ourworldofpixels.com:1234", true) : site == "MPT" ? new Client("ws://ts.terrium.net:8080", true) : site == "VFDP" ? new Client("ws://www.visualfiredev.com:8080") : undefined; if (!gClient) return console.error(`Invalid site ${site}`); gClient.setChannel(/*(site == "MPP" && room == "lobby") ? "lolwutsecretlobbybackdoor" : */room); gClient.canConnect = true; @@ -376,7 +376,7 @@ commands.bridge = { else if ((existingBridge && existingBridge.disabled) || config.disabledRooms.includes(room)) return msg.reply(`You cannot bridge this room.`); var discordChannelName = room.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase(); var categoryID = '360557444952227851'; - var channel = await dClient.guilds.get(config.guildID).createChannel(discordChannelName, {parent: categoryID}); + var channel = await dClient.guilds.get(config.guildID).channels.create(discordChannelName, {parent: categoryID}); channel.setTopic(`Bridged to http://www.multiplayerpiano.com/${encodeURIComponent(room)}`); var webhook = await channel.createWebhook('Webhook'); createMPPbridge(room, channel.id, site, webhook.id, webhook.token); @@ -465,7 +465,7 @@ commands.list = { var names = []; for (let person in ppl) { person = ppl[person]; - names.push(`\`${person._id.substr(0,4)}\` ${person.name}`); + names.push(`\`${person._id.substr(0,6)}\` ${person.name}`); } str += names.join(', '); message.channel.send(str, {split:{char:''}}); diff --git a/src/package-lock.json b/src/package-lock.json new file mode 100755 index 0000000..a90edb5 --- /dev/null +++ b/src/package-lock.json @@ -0,0 +1,55 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + }, + "discord.js": { + "version": "github:hydrabolt/discord.js#b186472785db6bbe7de37e1a75104d79dd0cc44f", + "requires": { + "pako": "1.0.6", + "prism-media": "0.2.1", + "snekfetch": "3.6.4", + "tweetnacl": "1.0.0", + "ws": "4.1.0" + } + }, + "pako": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz", + "integrity": "sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg==" + }, + "prism-media": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.2.1.tgz", + "integrity": "sha512-Kfp1+6gzjY6X8mqKHa6D3brX+BtMUPFwzAkz4zgtVPgbkA2XxhITROdfQXVurU4fuJsylFRwqo7ciQlQCm9hAw==" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "snekfetch": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz", + "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw==" + }, + "tweetnacl": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz", + "integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins=" + }, + "ws": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", + "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", + "requires": { + "async-limiter": "1.0.0", + "safe-buffer": "5.1.1" + } + } + } +} diff --git a/src/screenshotter.js b/src/screenshotter.js old mode 100644 new mode 100755 index a05db7d..51f5f31 --- a/src/screenshotter.js +++ b/src/screenshotter.js @@ -6,6 +6,7 @@ global.screenshotter = { var page = await browser.newPage(); await page.setViewport({width: 1440, height: 900}); await page.goto('http://www.multiplayerpiano.com/lobby'); + await page.evaluate(function(){ setTimeout(()=>{ document.getElementById('modal').click() }, 1000) }); await new Promise(resolve => setTimeout(resolve, 5000)); var screenshot = await page.screenshot({type: 'png'}); var filename = `Screenshot of www.multiplayerpiano.com/lobby @ ${new Date().toISOString()}.png`;