and some other stuff
This commit is contained in:
Lamp 2018-07-13 15:20:33 -07:00
parent 4eca595eac
commit d879d5cf28
No known key found for this signature in database
GPG Key ID: 0F1F8704BEDE369E
7 changed files with 57 additions and 25 deletions

View File

@ -38,7 +38,7 @@ global.commands = {
usage: "<name>",
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);
}
)

View File

@ -1,3 +1,4 @@
require('./util');
global.exitHook = require('async-exit-hook');
global.Discord = require('discord.js');
global.fs = require('fs');

View File

@ -0,0 +1,25 @@
module.exports = {
usage: "<MPP user id>",
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.")
},
}

View File

@ -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) {

View File

@ -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];

View File

@ -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}]);
})

3
src/util.js Normal file
View File

@ -0,0 +1,3 @@
Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)]
}