diff --git a/src/commands.js b/src/commands.js index deb9778..76b0705 100755 --- a/src/commands.js +++ b/src/commands.js @@ -38,7 +38,7 @@ global.commands = { usage: "", description: "Creates a generic text channel in this server and gives you full permissions for it.", exec: async function (msg) { - if (!msg.args[0]) return false; + if (!msg.args[0]) return "EBADUSG"; //var name = msg.txt(1).replace(/[^a-zA-Z0-9]/g, '-').substr(0,100).toLowerCase(); var name = msg.txt(1); msg.guild.channels.create(name, { @@ -145,35 +145,29 @@ dClient.on('message', message => { if (!message.guild) message.guild = dClient.guilds.get(config.guildID); if (!message.member) message.member = dClient.guilds.get(config.guildID).members.get(message.author.id); - /*if (commands.hasOwnProperty(cmd)) { - var command = commands[cmd]; - if (command.op && message.author.id !== op) return message.react('🚫'); - try { - command.exec(message, args, txt); - } catch(e) { - message.reply(`:warning: An error occured while processing your command.`); - console.error(e.stack); - } - }*/ - Object.keys(commands).forEach(commandName => { var command = commands[commandName]; if (!(commandName === cmd || (command.aliases && command.aliases.includes(cmd)))) return; if (command.op && message.author.id !== config.opID) return message.react('🚫'); - /*try { - var d = command.exec(message, args, txt); - if (d === false) message.channel.send(`**Usage:** \`!${commandName} ${command.usage}\``); - } catch(e) { - message.reply(`:warning: An error occured while processing your command.`); - console.error(e.stack); - }*/ - command.exec(message, args, txt).then( (res) => { - if (res === false) message.channel.send(`**Usage:** \`!${commandName} ${command.usage}\``); + switch (res) { + case "ENOTBRIDGE": + message.channel.send([ + `This is not a bridged channel.`, + `You can only use this command in a bridged channel.` + ].random()); + break; + case "EBADUSG": + message.channel.send(`**Usage:** \`!${commandName} ${command.usage}\``); + break; + } }, (err) => { - message.reply(`:warning: An error occured: \`\`\`\n${err.stack}\n\`\`\``); + message.reply(`:warning: An error occured: \`\`\`\n${err.stack}\n\`\`\`<@281134216115257344> ${[ + 'fix me pls', + // ran out of ideas + ].random()}`); console.error(err.stack); } ) diff --git a/src/main.js b/src/main.js index 3420dcf..42fc05f 100755 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,4 @@ +require('./util'); global.exitHook = require('async-exit-hook'); global.Discord = require('discord.js'); global.fs = require('fs'); diff --git a/src/mppbridger/commands/ban.js b/src/mppbridger/commands/ban.js new file mode 100644 index 0000000..be82c42 --- /dev/null +++ b/src/mppbridger/commands/ban.js @@ -0,0 +1,25 @@ +module.exports = { + usage: "", + description: "Adds a perma-ban on the user", + aliases: ["permaban"], + exec: async function (msg) { + if (!msg.args[1]) return "EBADUSG"; + var res = await dbClient.query('SELECT * FROM bridges WHERE discord_channel_id = $1;', [msg.channel.id]); + if (!res.rows.length) return "ENOTBRIDGE" + var bridge = res.rows[0]; + if (bridge.owner_discord_user_id != msg.author.id) return msg.reply(`You are not the owner of this bridge.`); + var _id = msg.txt(1); + await dbClient.query("UPDATE bridges SET bans = bans || $1 WHERE discord_channel_id = $2", [_id, msg.channel.id]); + await msg.reply(`OK, I'll ban anyone whose user ID equals or starts with \`${_id}\` from this room, whenever possible.`); + + var client = clients.MPP[bridge.mpp_room] + for (let p in client.ppl) { + p = client.ppl[p] + if (p._id.startsWith(_id)) + client.sendArray([{m:'kickban', _id, ms: 60*60*1000}]) + } + + if (_id.length != 24) await msg.reply(":warning: The ID you gave me does not look like a full user ID (it is not 24 chars long). If it's a truncated ID it will still work, however it could possibly ban someone else whose user ID starts with those chars.") + + }, +} \ No newline at end of file diff --git a/src/mppbridger/commands/bridge.js b/src/mppbridger/commands/bridge.js index 07822fd..345bef9 100644 --- a/src/mppbridger/commands/bridge.js +++ b/src/mppbridger/commands/bridge.js @@ -4,7 +4,7 @@ module.exports = { exec: async function (msg) { var site = 'MPP'; var room = msg.txt(1); - if (!room) return false; + if (!room) return "EBADUSG"; var existingBridge = (await dbClient.query('SELECT * FROM bridges WHERE mpp_room = $1;', [room])).rows[0]; if (existingBridge) { if (!existingBridge.disabled) { diff --git a/src/mppbridger/commands/chown.js b/src/mppbridger/commands/chown.js index 815c260..236cc9e 100644 --- a/src/mppbridger/commands/chown.js +++ b/src/mppbridger/commands/chown.js @@ -3,7 +3,7 @@ module.exports = { description: "Changes the MPP or Discord owner of a private bridge. The first argument must be either `mpp` or `discord`.", aliases: ['changeowner', 'setowner'], exec: async function (msg) { - if (msg.args.length < 3 || !['mpp','discord'].includes(msg.args[1])) return false; + if (msg.args.length < 3 || !['mpp','discord'].includes(msg.args[1])) return "EBADUSG"; var res = await dbClient.query('SELECT * FROM bridges WHERE discord_channel_id = $1;', [msg.channel.id]); if (res.rows.length == 0) return msg.react('🚫'); var bridge = res.rows[0]; diff --git a/src/mppbridger/index.js b/src/mppbridger/index.js index d94d3fa..8eecb81 100755 --- a/src/mppbridger/index.js +++ b/src/mppbridger/index.js @@ -183,7 +183,16 @@ global.createMPPbridge = function createMPPbridge(room, DiscordChannelID, site = }, minutes*60*1000+3000); dSend(`**Attempting to rejoin in ${minutes} minutes.**`); } - }); + }); + + + // autoban perma-banned users + gClient.on("participant added", async part => { + var bridge = (await dbClient.query("SELECT bans FROM bridges WHERE discord_channel_id = $1", [DiscordChannelID])).rows[0]; + for (let x of bridge.bans) + if (part._id.startsWith(x)) + gClient.sendArray([{m: "kickban", _id: part._id, ms: 60*60*1000}]); + }) diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..a59d538 --- /dev/null +++ b/src/util.js @@ -0,0 +1,3 @@ +Array.prototype.random = function () { + return this[Math.floor(Math.random() * this.length)] +} \ No newline at end of file