Compare commits
No commits in common. "7fe2b0fa1280e0dc9bc670faa1df256afb6ba3be" and "aee470b583ee0ee11e419ee8c771811c08a9be3a" have entirely different histories.
7fe2b0fa12
...
aee470b583
158
commands.js
158
commands.js
@ -1,21 +1,147 @@
|
|||||||
global.commands = [
|
global.commands = {
|
||||||
{
|
"help": {
|
||||||
name: "list",
|
usage: "[command]",
|
||||||
description: "Show the members on the other side of an MPP bridge",
|
aliases: ["commands"],
|
||||||
exec: i => {
|
exec: async function (msg) {
|
||||||
let bridge = bridges.find(x => x.channel == i.channel.id);
|
if (msg.args[1]) {
|
||||||
if (!bridge) return i.reply({ephemeral: true, content: "Not available in this channel"});
|
var commandName = msg.args[1];
|
||||||
let ppl_list = Object.values(bridge.client.ppl).map(m => `\`${m._id}\` ${m.name}`);
|
var command = commands[commandName];
|
||||||
i.reply({content: `__**${ppl_list.length} people are playing**__\n${ppl_list.join("\n")}`});
|
if (!command)
|
||||||
|
for (let cmdNme in commands) {
|
||||||
|
let cmd = commands[cmdNme];
|
||||||
|
if (cmd.aliases && cmd.aliases.includes(commandName)) {command = cmd; break;}
|
||||||
|
}
|
||||||
|
if (!command) return msg.react('❓');
|
||||||
|
var str = '`'+`!${commandName} ${command.usage || ''}`.trim()+'`\n';
|
||||||
|
if (command.hasOwnProperty('aliases')) str += `**Aliases:** \`!${command.aliases.join(', !')}\`\n`;
|
||||||
|
if (command.hasOwnProperty('description')) str += `\n${command.description}`;
|
||||||
|
msg.channel.send({embed:{
|
||||||
|
description: str
|
||||||
|
}});
|
||||||
|
} else {
|
||||||
|
var cmdArr = [];
|
||||||
|
for (var command in commands) {
|
||||||
|
if (!commands[command].op) cmdArr.push(`!${command}`);
|
||||||
|
}
|
||||||
|
var embed = {
|
||||||
|
title: "Commands",
|
||||||
|
description: cmdArr.join(', '),
|
||||||
|
footer: {text: "Use `!help <command>` for more info on a command."}
|
||||||
|
};
|
||||||
|
msg.channel.send({embed});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
},
|
||||||
|
|
||||||
|
'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]) {
|
||||||
|
var channel = msg.mentions.channels.first();
|
||||||
|
if (!channel) {
|
||||||
|
msg.react(`⚠`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var channel = msg.channel;
|
||||||
|
}
|
||||||
|
if (!channel.permissionsFor(msg.member).has('MANAGE_CHANNELS')) return msg.react('🚫');
|
||||||
|
await channel.setParent(config.channels.deleted_channels);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
await channel.lockPermissions();
|
||||||
|
msg.react('🆗');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
client.on("interactionCreate", interaction => {
|
"eval": {
|
||||||
commands.find(x => x.name == interaction.commandName)?.exec?.(interaction);
|
op: true,
|
||||||
});
|
description: "Evaluate javascript",
|
||||||
|
usage: "<code>",
|
||||||
client.once("ready", () => {
|
aliases: ['>'],
|
||||||
client.guilds.resolve(config.guildID)?.commands.set(commands);
|
exec: async function (message) {
|
||||||
|
var msg = message, m = message,
|
||||||
|
guild = message.guild,
|
||||||
|
channel = message.channel,
|
||||||
|
member = message.member,
|
||||||
|
client = dClient,
|
||||||
|
send = function(){
|
||||||
|
channel.send.apply(channel, arguments);
|
||||||
|
},
|
||||||
|
say = send;
|
||||||
|
try {
|
||||||
|
var out = eval(message.content.substr(2));
|
||||||
|
} catch (error) {
|
||||||
|
var out = error;
|
||||||
|
} finally {
|
||||||
|
message.channel.send('`'+out+'`', {split:{char:''}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"exec": {
|
||||||
|
op: true,
|
||||||
|
description: "Run a shell command",
|
||||||
|
usage: "<command>",
|
||||||
|
aliases: ["$"],
|
||||||
|
exec: async function (msg) {
|
||||||
|
require("child_process").exec(msg.txt(1), function(error, stdout, stderr){
|
||||||
|
if (error) msg.channel.send(error, {split:{char:'',maxLength:2000}});
|
||||||
|
if (stdout) msg.channel.send(stdout, {split:{char:'',maxLength:2000}});
|
||||||
|
if (stderr) msg.channel.send(stderr, {split:{char:'',maxLength:2000}});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dClient.on('messageCreate', async message => {
|
||||||
|
if (!message.content.startsWith('!')) return;
|
||||||
|
if (message.author.id === dClient.user.id) return;
|
||||||
|
|
||||||
|
var args = message.content.split(' ');
|
||||||
|
var cmd = args[0].slice(1).toLowerCase();
|
||||||
|
var txt = function(i){return args.slice(i).join(' ').trim()};
|
||||||
|
|
||||||
|
message.args = args;
|
||||||
|
message.cmd = cmd;
|
||||||
|
message.txt = function(i){return this.args.slice(i).join(' ')};
|
||||||
|
if (!message.guild) message.guild = dClient.guilds.resolve(config.guildID);
|
||||||
|
if (!message.member) message.member = dClient.guilds.resolve(config.guildID).members.resolve(message.author.id);
|
||||||
|
|
||||||
|
Object.keys(commands).forEach(commandName => {
|
||||||
|
var command = commands[commandName];
|
||||||
|
if (!(commandName === cmd || (command.aliases && command.aliases.includes(cmd)))) return;
|
||||||
|
if (command.op && !config.opIDs.includes(message.author.id)) return message.react('🚫');
|
||||||
|
command.exec(message, args, txt).then(
|
||||||
|
(res) => {
|
||||||
|
switch (res) {
|
||||||
|
case "ENOTBRIDGE":
|
||||||
|
message.channel.send(random([
|
||||||
|
`This is not a bridged channel.`,
|
||||||
|
`You can only use this command in a bridged channel.`
|
||||||
|
]));
|
||||||
|
break;
|
||||||
|
case "EBADUSG":
|
||||||
|
message.channel.send(`**Usage:** \`!${commandName} ${command.usage}\``);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
message.reply(`:warning: An error occured: \`\`\`\n${err.stack}\n\`\`\`<@281134216115257344>`);
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
});
|
});
|
@ -12,6 +12,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"opID": "707359017252683896",
|
"opID": "707359017252683896",
|
||||||
|
"opIDs": ["707359017252683896", "330499035419115522"], //TODO i dont need multiple ops anymore
|
||||||
"guildID": testmode ? "467473467634089985" : "321819041348190249",
|
"guildID": testmode ? "467473467634089985" : "321819041348190249",
|
||||||
|
|
||||||
"channels": { // includes voice channels & category channels
|
"channels": { // includes voice channels & category channels
|
||||||
|
37
eval-exec.js
37
eval-exec.js
@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
client.on("messageCreate", async function (message) {
|
|
||||||
if (message.author.id != config.opID) return;
|
|
||||||
if (message.content.startsWith("!>")) {
|
|
||||||
with (message) {
|
|
||||||
try {
|
|
||||||
var x = await eval(message.content.substr(2).trim());
|
|
||||||
} catch(e) {
|
|
||||||
var x = e.message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeof x == "undefined") return void await message.react(config.eval_undefined_emoji);
|
|
||||||
let t = typeof x == 'string' ? 'txt' : 'js';
|
|
||||||
if (typeof x != 'string' && typeof x != "function") x = require('util').inspect(x, {depth: 1});
|
|
||||||
let cb = `\`\`\`${t}\n${x}\`\`\``;
|
|
||||||
if (cb.length <= 2000)
|
|
||||||
message.channel.send(cb);
|
|
||||||
else
|
|
||||||
message.channel.send({files:[{
|
|
||||||
attachment: Buffer.from(x),
|
|
||||||
name: `output.${t}`
|
|
||||||
}]});
|
|
||||||
}
|
|
||||||
else if (message.content.startsWith("!$")) {
|
|
||||||
let cp = require("child_process").spawn("bash", ["-c", message.content.substr(2).trim()]);
|
|
||||||
function ondat(a) {
|
|
||||||
try {
|
|
||||||
var split = Discord.Util.splitMessage(a.toString(), {split:{char:'\n',length:2000}});
|
|
||||||
} catch(x) {
|
|
||||||
var split = Discord.Util.splitMessage(a.toString(), {split:{char:'',length:2000}});
|
|
||||||
}
|
|
||||||
split.forEach(message.channel.send.bind(message.channel));
|
|
||||||
}
|
|
||||||
cp.stdout.on("data", ondat);
|
|
||||||
cp.stderr.on("data", ondat);
|
|
||||||
}
|
|
||||||
});
|
|
16
main.js
16
main.js
@ -30,13 +30,13 @@ global.dClient = new Discord.Client({
|
|||||||
|
|
||||||
dClient.login(config.DISCORD_TOKEN);
|
dClient.login(config.DISCORD_TOKEN);
|
||||||
|
|
||||||
dClient.on('ready', () => {
|
dClient.once('ready', () => {
|
||||||
console.log('Discord Client Ready');
|
console.log('Discord Client Ready');
|
||||||
});
|
|
||||||
|
|
||||||
require('./eval-exec');
|
require('./commands');
|
||||||
require("./commands");
|
require('./mppbridger');
|
||||||
require('./mppbridger');
|
require('./misc');
|
||||||
require('./misc');
|
require('./ddpbridge');
|
||||||
require('./ddpbridge');
|
require('./prbridge');
|
||||||
require('./prbridge');
|
|
||||||
|
});
|
||||||
|
@ -97,7 +97,6 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||||||
|
|
||||||
// MPP to Discord
|
// MPP to Discord
|
||||||
gClient.on('a', async msg => {
|
gClient.on('a', async msg => {
|
||||||
if (msg.p._id == gClient.getOwnParticipant()._id) return;
|
|
||||||
var id = msg.p._id.substr(0,6);
|
var id = msg.p._id.substr(0,6);
|
||||||
var name = sanitizeName(msg.p.name);
|
var name = sanitizeName(msg.p.name);
|
||||||
var content = msg.a;
|
var content = msg.a;
|
||||||
@ -107,28 +106,26 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||||||
|
|
||||||
// Discord to MPP
|
// Discord to MPP
|
||||||
{
|
{
|
||||||
let msgQueue = [];
|
//let msgQueue = [];
|
||||||
dClient.on('message', async message => {
|
dClient.on('message', async message => {
|
||||||
if (message.channel.id !== channel.id || 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 str = message.cleanContent;
|
||||||
var aname = message.author.tag;
|
var aname = message.author.tag;
|
||||||
if (str.startsWith('/') || str.startsWith('\\'))
|
//if (str.startsWith('/') || str.startsWith('\\'))
|
||||||
msgQueue.push(`⤹ ${aname}`);
|
// msgQueue.push(`⤹ ${aname}`);
|
||||||
else
|
//else
|
||||||
str = `${aname}: ${str}`;
|
str = `${aname}: ${str}`;
|
||||||
if (str.startsWith('\\')) str = str.slice(1);
|
//if (str.startsWith('\\')) str = str.slice(1);
|
||||||
if (message.attachments.size > 0) str += ' ' + message.attachments.map(a => a.url).join(' ');
|
if (message.attachments.size > 0) str += ' ' + message.attachments.map(a => a.url).join(' ');
|
||||||
if (str.length > 512) {
|
if (str.length > 512) str = str.substr(0,511) + '…';
|
||||||
str = str.substr(0,511) + '…';
|
//msgQueue.push(str);
|
||||||
message.react('⚠');
|
gClient.sendArray([{m:'a', message: str}]);
|
||||||
}
|
if (gClient.isConnected()) message.delete();
|
||||||
msgQueue.push(str);
|
|
||||||
});
|
});
|
||||||
setInterval(()=>{
|
//setInterval(()=>{
|
||||||
let message = msgQueue.shift();
|
// let message = msgQueue.shift();
|
||||||
if (message) gClient.sendArray([{m:'a', message}]);
|
// if (message) gClient.sendArray([{m:'a', message}]);
|
||||||
//todo wait moment to see if message got through then react warning if didnt
|
//}, 1600); // just about fastest without exceeding quota; I figured quota is 4 messages per 6 seconds in lobbies
|
||||||
}, 1600); // just about fastest without exceeding quota; I figured quota is 4 messages per 6 seconds in lobbies
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -205,7 +202,7 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||||||
|
|
||||||
|
|
||||||
// start
|
// start
|
||||||
client.once("ready", async function () {
|
(async function () {
|
||||||
global.bridges = require("./bridges");
|
global.bridges = require("./bridges");
|
||||||
for (let bridge of bridges) {
|
for (let bridge of bridges) {
|
||||||
try {
|
try {
|
||||||
@ -214,4 +211,4 @@ client.once("ready", async function () {
|
|||||||
handleError(error, JSON.stringify(bridge));
|
handleError(error, JSON.stringify(bridge));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})();
|
Loading…
x
Reference in New Issue
Block a user