Allow re-bridging (#1)

This commit is contained in:
ledlamp 2018-05-20 15:26:38 -07:00
parent 52ca1e4c8d
commit 1f8bfeda47
1 changed files with 16 additions and 3 deletions

View File

@ -372,12 +372,25 @@ commands.bridge = {
var room = msg.txt(1);
if (!room) return false;
var existingBridge = (await dbClient.query('SELECT * FROM bridges WHERE mpp_room = $1;', [room])).rows[0];
if (existingBridge && !existingBridge.disabled) return msg.reply(`${site} room ${room} is already bridged.`);
else if ((existingBridge && existingBridge.disabled) || config.disabledRooms.includes(room)) return msg.reply(`You cannot bridge this room.`);
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 */ {
await dbClient.query("UPDATED BRIDGES SET disabled = false WHERE mpp_room = $1", [room]);
createMPPbridge(room, existingBridge.mpp_room, existingBridge.site, existingBridge.webhook_id, existingBridge.webhook_token);
await msg.reply(`${site} room ${room} has been re-bridged.`);
return;
}
}
}
/* new bridge */
var discordChannelName = room.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase();
var categoryID = '360557444952227851';
var channel = await dClient.guilds.get(config.guildID).channels.create(discordChannelName, {parent: categoryID});
channel.setTopic(`Bridged to http://www.multiplayerpiano.com/${encodeURIComponent(room)}`);
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)', [