strip out pg

This commit is contained in:
Lamp 2022-01-03 19:04:16 -08:00
parent 885493413a
commit 3249697420
9 changed files with 44 additions and 512 deletions

253
package-lock.json generated
View File

@ -8,7 +8,6 @@
"async-exit-hook": "^2.0.1",
"discord.js": "^12.5.3",
"dotenv": "^8.2.0",
"pg": "^8.7.1",
"socketcluster-client": "^14.2.2",
"ws": "^3.3.2"
}
@ -74,14 +73,6 @@
"ieee754": "^1.1.4"
}
},
"node_modules/buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==",
"engines": {
"node": ">=4"
}
},
"node_modules/clone": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz",
@ -206,120 +197,6 @@
"node": "4.x || >=6.0.0"
}
},
"node_modules/packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"node_modules/pg": {
"version": "8.7.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.1.tgz",
"integrity": "sha512-7bdYcv7V6U3KAtWjpQJJBww0UEsWuh4yQ/EjNf2HeO/NnvKjpvhEIe/A/TleP6wtmSKnUnghs5A9jUoK6iDdkA==",
"dependencies": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.5.0",
"pg-pool": "^3.4.1",
"pg-protocol": "^1.5.0",
"pg-types": "^2.1.0",
"pgpass": "1.x"
},
"engines": {
"node": ">= 8.0.0"
},
"peerDependencies": {
"pg-native": ">=2.0.0"
},
"peerDependenciesMeta": {
"pg-native": {
"optional": true
}
}
},
"node_modules/pg-connection-string": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz",
"integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ=="
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-pool": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.4.1.tgz",
"integrity": "sha512-TVHxR/gf3MeJRvchgNHxsYsTCHQ+4wm3VIHSS19z8NC0+gioEhq1okDY1sm/TYbfoP6JLFx01s0ShvZ3puP/iQ==",
"peerDependencies": {
"pg": ">=8.0"
}
},
"node_modules/pg-protocol": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz",
"integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ=="
},
"node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"dependencies": {
"split": "^1.0.0"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/prism-media": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz",
@ -419,22 +296,6 @@
}
}
},
"node_modules/split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"dependencies": {
"through": "2"
},
"engines": {
"node": "*"
}
},
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"node_modules/tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
@ -463,14 +324,6 @@
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0"
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"engines": {
"node": ">=0.4"
}
}
},
"dependencies": {
@ -526,11 +379,6 @@
"ieee754": "^1.1.4"
}
},
"buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
},
"clone": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz",
@ -615,89 +463,6 @@
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"pg": {
"version": "8.7.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.7.1.tgz",
"integrity": "sha512-7bdYcv7V6U3KAtWjpQJJBww0UEsWuh4yQ/EjNf2HeO/NnvKjpvhEIe/A/TleP6wtmSKnUnghs5A9jUoK6iDdkA==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.5.0",
"pg-pool": "^3.4.1",
"pg-protocol": "^1.5.0",
"pg-types": "^2.1.0",
"pgpass": "1.x"
}
},
"pg-connection-string": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz",
"integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ=="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-pool": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.4.1.tgz",
"integrity": "sha512-TVHxR/gf3MeJRvchgNHxsYsTCHQ+4wm3VIHSS19z8NC0+gioEhq1okDY1sm/TYbfoP6JLFx01s0ShvZ3puP/iQ==",
"requires": {}
},
"pg-protocol": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz",
"integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ=="
},
"pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "^1.0.0"
}
},
"postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q=="
},
"postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"prism-media": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz",
@ -762,19 +527,6 @@
}
}
},
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"requires": {
"through": "2"
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
@ -799,11 +551,6 @@
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0"
}
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
}
}
}

View File

@ -3,7 +3,6 @@
"async-exit-hook": "^2.0.1",
"discord.js": "^12.5.3",
"dotenv": "^8.2.0",
"pg": "^8.7.1",
"socketcluster-client": "^14.2.2",
"ws": "^3.3.2"
}

View File

@ -96,19 +96,6 @@ global.commands = {
}
},
"query": {
description: "Queries the PostgreSQL database",
usage: "<query>",
aliases: ['q', 'db', 'sql', '?'],
op: true,
exec: async function (msg) {
dbClient.query(msg.txt(1), (err, res) => {
var str = err || JSON.stringify(res);
msg.channel.send(str, {split:{char:''}});
});
}
},
}

View File

@ -24,19 +24,7 @@ global.dClient = new Discord.Client({ disableMentions: 'everyone', restRequestTi
}
global.dbClient = new (require('pg').Client)({
connectionString: process.env.DATABASE_URL,
ssl: {rejectUnauthorized: false},
});
console.log("Connecting to Postgres…")
dbClient.connect().then(function(){
console.log("Connecting to Discord…");
dClient.login(config.DISCORD_TOKEN);
}, function(err){
console.error("Failed to connect to Postgres:\n", err.stack);
process.exit(1);
});
dClient.login(config.DISCORD_TOKEN);
dClient.once('ready', () => {
console.log('Discord Client Ready');

View File

@ -0,0 +1,13 @@
[
{ "room": "lobby", "channel": "339609383644168195", "uri": "wss://mppclone.com:8443" },
{ "room": "lobby2", "channel": "350006891948277770", "uri": "wss://mppclone.com:8443" },
{ "room": "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧", "channel": "698736467559710740", "uri": "wss://mppclone.com:8443" },
{ "room": "test/awkward", "channel": "360556775860076544", "uri": "wss://mppclone.com:8443" },
{ "room": "test/fishing", "channel": "339613702472859659", "uri": "wss://mppclone.com:8443" },
{ "room": "the-dev-channel", "channel": "925129849457233970", "uri": "wss://mppclone.com:8443" },
{ "room": "lobby", "channel": "430226348901007360", "uri": "wss://mppws.cf" },
{ "room": "lobby", "channel": "339904195719200768", "uri": "wss://piano.ourworldofpixels.com" },
{ "room": "lobby", "channel": "559898407511261219", "uri": "ws://104.237.150.24:8513/" },
{ "room": "lobby", "channel": "927720571201028187", "uri": "wss://beta-mpp.cedms.jp" }
]

View File

@ -1,45 +0,0 @@
module.exports = {
usage: "<MPP room>",
description: "Creates a bridge to the specified MPP room.",
exec: async function (msg) {
if (msg.author.id != config.opID) {
msg.reply(`Bridging has been disabled; ask <@${config.opID}> if you actually want to bridge this room.`);
return;
}
var site = 'MPP';
var room = msg.txt(1);
if (!room) return "EBADUSG";
var existingBridge = (await dbClient.query("SELECT * FROM bridges WHERE mpp_room = $1 AND site = 'MPP';", [room])).rows[0];
if (existingBridge) {
if (!existingBridge.disabled) {
return msg.reply(`${site} room ${room} is already bridged.`);
} else {
if (config.disabledRooms.includes(room)) {
return msg.reply(`You cannot bridge this room.`);
} else /* rebridge */ {
let channel = dClient.guilds.resolve(config.guildID).channels.resolve(existingBridge.discord_channel_id);
await dbClient.query("UPDATE bridges SET disabled = false WHERE mpp_room = $1 AND site = 'MPP'", [room]);
await channel.setParent(config.channels.mpp_bridges);
await new Promise(resolve => setTimeout(resolve, 500));
await channel.lockPermissions();
let existingClient = clients.MPP[room];
if (existingClient) existingClient.start();
else createMPPbridge(room, existingBridge.discord_channel_id, existingBridge.site, existingBridge.webhook_id, existingBridge.webhook_token);
await msg.reply(`${site} room ${room} has been re-bridged to ${channel}.`);
return;
}
}
}
/* new bridge */
var discordChannelName = room;
var categoryID = config.channels.mpp_bridges;
var channel = await dClient.guilds.resolve(config.guildID).channels.create(discordChannelName, {parent: categoryID});
channel.setTopic(`http://www.multiplayerpiano.com/${encodeURIComponent(room)}`);
var webhook = await channel.createWebhook('Webhook');
createMPPbridge(room, channel.id, site, webhook.id, webhook.token);
dbClient.query('INSERT INTO bridges (site, mpp_room, discord_channel_id, webhook_id, webhook_token, owner_discord_user_id) VALUES ($1, $2, $3, $4, $5, $6)', [
site, room, channel.id, webhook.id, webhook.token, msg.author.id,
]);
msg.reply(`${site} room ${room} is now bridged to ${channel}.`);
}
};

View File

@ -1,28 +0,0 @@
module.exports = {
description: "Lists online participants",
aliases: ['ppl', 'online'],
exec: async function (message) {
var row = (await dbClient.query("SELECT mpp_room, site FROM bridges WHERE discord_channel_id = $1;", [message.channel.id])).rows[0];
if (!row) {
//message.react('🚫');
message.reply(`Use this in a bridged room to see who is at the other side.`);
return;
}
var client = clients[row.site][row.mpp_room];
if (!client || !client.isConnected()) {
message.reply(`This bridge is not connected.`);
return;
}
var ppl = clients[row.site][row.mpp_room].ppl;
var numberOfPpl = Object.keys(ppl).length;
var str = `__**Participants Online (${numberOfPpl})**__\n`;
var names = [];
for (let person in ppl) {
person = ppl[person];
names.push(`\`${person._id.substr(0,6)}\` ${person.name.replace(/<@/g, "<\\@")}`);
}
str += names.join(', ');
message.channel.send(str, {split:{char:''}});
}
};

View File

@ -1,29 +0,0 @@
module.exports = {
usage: "[MPP Room]",
description: "Deletes a bridge to the specified MPP room.",
exec: async function (msg) {
var bridge = (await dbClient.query("SELECT * FROM bridges WHERE mpp_room = $1 OR discord_channel_id = $2", [msg.txt(1), msg.channel.id])).rows[0];
if (!bridge) {
//msg.react('⚠️');
msg.reply(`That room is not bridged. Make sure you type the MPP room name correctly.`);
return;
}
if (bridge.disabled) {
msg.reply(`That room has already been unbridged.`);
return;
}
if (!(bridge.owner_discord_user_id == msg.author.id || msg.author.id == config.opID)) {
//msg.react('🚫');
msg.reply(`You do not own that bridge.`);
return;
}
await dbClient.query("UPDATE bridges SET disabled = 'true' WHERE mpp_room = $1", [bridge.mpp_room]);
var client = clients.MPP[bridge.mpp_room];
if (client) client.stop();
var channel = dClient.channels.resolve(bridge.discord_channel_id)
await channel.setParent(config.channels.deleted_bridges);
await new Promise(resolve => setTimeout(resolve, 500));
await channel.lockPermissions();
msg.reply(`${bridge.mpp_room} has been unbridged.`);
}
};

View File

@ -1,11 +1,9 @@
var Client = require('../lib/Client.js');
global.clients = {};
global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site = 'MPP', webhookID, webhookToken) {
var DiscordChannel = dClient.channels.resolve(DiscordChannelID);
if (!DiscordChannel) return console.error(`Couldn't bridge ${site} ${room} because Discord Channel ${DiscordChannelID} is missing!`);
if (webhookID && webhookToken) var webhook = new Discord.WebhookClient(webhookID, webhookToken, {disableMentions:'all'});
global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
channel = dClient.channels.resolve(channel);
var webhooks = await channel.fetchWebhooks();
var webhook = webhooks.first() || await channel.createWebhook("sdfadffg");
// discord message sending
{
@ -17,11 +15,11 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
if (username.length > 32) username = username.substr(0,31) + '…';
else if (username.length < 2) username = undefined;
webhook.send(msg, {username, embed, split:{char:''}}).catch(error => {
console.error(`webhook fail in ${DiscordChannel.id}: ${error.message}`);
DiscordChannel.send(msg, {embed, split:{char:''}}).catch(error => console.error(`send fail in ${DiscordChannel.id} after webhook send fail: ${error.message}`));
console.error(`webhook fail in ${channel.id}: ${error.message}`);
channel.send(msg, {embed, split:{char:''}}).catch(error => console.error(`send fail in ${channel.id} after webhook send fail: ${error.message}`));
});
}
else DiscordChannel.send(msg, {embed, split:{char:''}}).catch(error => console.error(`send fail in ${DiscordChannel.id}: ${error.message}`));
else channel.send(msg, {embed, split:{char:''}}).catch(error => console.error(`send fail in ${channel.id}: ${error.message}`));
}
function dSend(msg) {
msgBuffer.push(msg);
@ -33,22 +31,9 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
}, 3000);
}
const gClient =
site == "MPP" ? new Client((room.startsWith('lobby')||(room.startsWith('test/')&&room!='test/awkward'))?"ws://ts.terrium.net:63636":"wss://mppclone.com:8443") :
site == "WOPP" ? new Client("wss://piano.ourworldofpixels.com") :
site == "MPT" ? new Client("wss://mppws.cf") :
site == "VFDP" ? new Client("ws://www.visualfiredev.com:8080") :
site == "CMPC" ? new Client("ws://charsy.meowbin.com:16562") :
site == "BIMP" ? new Client("ws://104.237.150.24:8513/") :
site == "YFLV" ? new Client("wss://mpp.yourfriend.lv/ws") :
site == "BCMS" ? new Client("wss://beta-mpp.cedms.jp") :
undefined;
if (!gClient) return console.error(`Invalid site ${site}`);
if (site == "MPP") gClient.token = config.mpc_token;
gClient.setChannel(/*(site == "MPP" && room == "lobby") ? "lolwutsecretlobbybackdoor" : */room, {visible:false});
const gClient = new Client(uri);
if (uri == "wss://mppclone.com:8443") gClient.token = config.mpc_token; //todo hmm
gClient.setChannel(room, {visible:false});
gClient.start();
// maintain the client's presence in the channel
@ -61,7 +46,7 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
let lastError;
gClient.on("error", error => {
console.error(`[${site}][${room}]`, error.message);
console.error(`[${uri}][${room}]`, error.message);
error = error.toString();
if (lastError != error) {
dSend(`**${error.toString()}**`);
@ -70,32 +55,27 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
});
var isConnected = false; // TODO use gClient.isConnected() ?
gClient.on('connect', () => {
console.log(`[${site}][${room}] Connected to server`);
console.log(`[${uri}][${room}] Connected to server`);
dSend(`**Connected to server; joining channel…**`);
isConnected = true;
lastError = undefined;
});
gClient.on('hi', ()=>{
console.log(`[${site}][${room}] Received greeting`);
console.log(`[${uri}][${room}] Received greeting`);
if (!testmode) {
//if (site == "MPP") {
// if (!(room.startsWith('lobby')||(room.startsWith('test/')&&room!='test/awkward')))
// gClient.sendArray([{m: "userset", set: {name: config.mppname }}]);
//} else {
gClient.sendArray([{m: "userset", set: {name: config.mppname }}]);
//}
gClient.sendArray([{m: "userset", set: {name: config.mppname }}]);
}
gClient.sendArray([{m:'m',x:Math.floor(Math.random()*100),y:Math.floor(Math.random()*100)}])
});
gClient.on('disconnect', () => {
if (isConnected) {
console.log(`[${site}][${room}] Disconnected from server`);
console.log(`[${uri}][${room}] Disconnected from server`);
dSend(`**Disconnected from server**`);
isConnected = false;
}
});
/*gClient.on('status', status => {
console.log(`[${site}] [${room}] ${status}`);
console.log(`[${uri}] [${room}] ${status}`);
});*/
@ -107,12 +87,12 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
// announce channel join
if (!lastCh) {
dSend(`**Joined channel \`${msg.ch._id}\`**`);
console.log(`[${site}][${room}] Joined channel ${msg.ch._id}`);
console.log(`[${uri}][${room}] Joined channel ${msg.ch._id}`);
}
// announce channel change
else if (msg.ch._id !== lastCh) {
dSend(`**Channel changed from \`${lastCh}\` to \`${msg.ch._id}\`**`);
console.log(`[${site}][${room}] Channel changed from ${lastCh} to ${msg.ch._id}`);
console.log(`[${uri}][${room}] Channel changed from ${lastCh} to ${msg.ch._id}`);
}
lastCh = msg.ch._id;
@ -120,34 +100,6 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
gClient.on("disconnect", () => lastCh = undefined);
}
// on chown
/*gClient.on('ch', async function(msg){
// catch dropped crown
if (msg.ch.crown && !msg.ch.crown.hasOwnProperty('participantId')) {
gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]); // if possible
var avail_time = msg.ch.crown.time + 15000 - gClient.serverTimeOffset;
var ms = avail_time - Date.now();
setTimeout(()=> gClient.sendArray([{m:'chown', id: gClient.getOwnParticipant().id}]) , ms);
}
// transfer crown to owner
if (msg.ppl && msg.ch.crown && msg.ch.crown.participantId == gClient.getOwnParticipant().id) {
var res = await dbClient.query("SELECT owner_mpp__id FROM bridges WHERE mpp_room = $1 AND site = $2;", [room, site]);
if (res.rows.length == 0) return;
var owner = res.rows[0].owner_mpp__id;
if (!owner) return;
msg.ppl.some(part => {
if (part._id == owner) {
gClient.sendArray([{m:'chown', id: part.id}]);
return true;
} else return false;
});
}
});*/
// MPP to Discord
gClient.on('a', async msg => {
@ -163,7 +115,7 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
{
let msgQueue = [];
dClient.on('message', async message => {
if (message.channel.id !== DiscordChannelID || message.author.id == dClient.user.id || !message.member /*|| message.content.startsWith('!')*/) return;
if (message.channel.id !== channel.id || message.author.id == dClient.user.id || !message.member /*|| message.content.startsWith('!')*/) return;
var str = message.cleanContent;
var aname = `${message.member.displayName}#${message.member.user.discriminator}`;
if (str.startsWith('/') || str.startsWith('\\'))
@ -225,18 +177,6 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
dSend(`**Attempting to rejoin in ${minutes} minutes.**`);
}
});
// autoban perma-banned users
/*gClient.on("participant added", async part => {
var bans = (await dbClient.query("SELECT bans FROM bridges WHERE discord_channel_id = $1", [DiscordChannelID])).rows[0].bans;
if (!bans) return;
for (let b of bans)
if (part._id.startsWith(b))
gClient.sendArray([{m: "kickban", _id: part._id, ms: 60*60*1000}]);
})*/
// make room invisible when nobody else is in it
gClient.on("ch", async function(msg){
@ -254,66 +194,26 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site =
// addons
{
// record raw data
//require('./datacollector')(gClient, site, room, DiscordChannel);
let createWSMessageCollector = require("../datacollector")
gClient.on("message", createWSMessageCollector(async function(data, startDate, endDate){
var attachmentName = `${site} ${room} raw data recording from ${startDate.toISOString()} to ${endDate.toISOString()} .txt.gz`;
await DiscordChannel.send(new Discord.MessageAttachment(data, attachmentName));
var attachmentName = `${uri} ${room} raw data recording from ${startDate.toISOString()} to ${endDate.toISOString()} .txt.gz`;
await channel.send(new Discord.MessageAttachment(data, attachmentName));
}));
}
if (!clients[site]) clients[site] = {};
clients[site][room] = gClient;
return gClient;
};
// start
(async function () {
var res = await dbClient.query('SELECT * FROM bridges;');
var sites = {};
res.rows.forEach(row => {
if (row.disabled) return;
if (!sites[row.site]) sites[row.site] = [];
sites[row.site].push(row);
});
for (let site in sites) {
let arr = sites[site];
arr.sort((a, b) => {return a.position - b.position});
let i = 0;
arr.forEach(bridge => {
createMPPbridge(bridge.mpp_room, bridge.discord_channel_id, bridge.site, bridge.webhook_id, bridge.webhook_token, bridge.owner_mpp__id);
});
global.bridges = require("./bridges");
for (let bridge of bridges) {
try {
bridge.client = await createMPPbridge(bridge);
} catch(e) {
console.error(error.message, JSON.stringify(bridge));
}
}
})();
// commands
commands.bridge = require('./commands/bridge');
commands.unbridge = require('./commands/unbridge');
commands.list = require('./commands/list');
})();