Compare commits
4 Commits
aee470b583
...
7fe2b0fa12
Author | SHA1 | Date |
---|---|---|
Lamp | 7fe2b0fa12 | |
Lamp | 3ef1bccb7a | |
Lamp | fb0c39b5c8 | |
Lamp | da4e033760 |
160
commands.js
160
commands.js
|
@ -1,147 +1,21 @@
|
|||
global.commands = {
|
||||
"help": {
|
||||
usage: "[command]",
|
||||
aliases: ["commands"],
|
||||
exec: async function (msg) {
|
||||
if (msg.args[1]) {
|
||||
var commandName = msg.args[1];
|
||||
var command = commands[commandName];
|
||||
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});
|
||||
}
|
||||
global.commands = [
|
||||
{
|
||||
name: "list",
|
||||
description: "Show the members on the other side of an MPP bridge",
|
||||
exec: i => {
|
||||
let bridge = bridges.find(x => x.channel == i.channel.id);
|
||||
if (!bridge) return i.reply({ephemeral: true, content: "Not available in this channel"});
|
||||
let ppl_list = Object.values(bridge.client.ppl).map(m => `\`${m._id}\` ${m.name}`);
|
||||
i.reply({content: `__**${ppl_list.length} people are playing**__\n${ppl_list.join("\n")}`});
|
||||
}
|
||||
},
|
||||
|
||||
'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('🆗');
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
"eval": {
|
||||
op: true,
|
||||
description: "Evaluate javascript",
|
||||
usage: "<code>",
|
||||
aliases: ['>'],
|
||||
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);
|
||||
}
|
||||
)
|
||||
});
|
||||
client.on("interactionCreate", interaction => {
|
||||
commands.find(x => x.name == interaction.commandName)?.exec?.(interaction);
|
||||
});
|
||||
|
||||
client.once("ready", () => {
|
||||
client.guilds.resolve(config.guildID)?.commands.set(commands);
|
||||
});
|
|
@ -12,7 +12,6 @@ module.exports = {
|
|||
},
|
||||
|
||||
"opID": "707359017252683896",
|
||||
"opIDs": ["707359017252683896", "330499035419115522"], //TODO i dont need multiple ops anymore
|
||||
"guildID": testmode ? "467473467634089985" : "321819041348190249",
|
||||
|
||||
"channels": { // includes voice channels & category channels
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
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.once('ready', () => {
|
||||
dClient.on('ready', () => {
|
||||
console.log('Discord Client Ready');
|
||||
|
||||
require('./commands');
|
||||
require('./mppbridger');
|
||||
require('./misc');
|
||||
require('./ddpbridge');
|
||||
require('./prbridge');
|
||||
|
||||
});
|
||||
|
||||
require('./eval-exec');
|
||||
require("./commands");
|
||||
require('./mppbridger');
|
||||
require('./misc');
|
||||
require('./ddpbridge');
|
||||
require('./prbridge');
|
|
@ -97,6 +97,7 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||
|
||||
// MPP to Discord
|
||||
gClient.on('a', async msg => {
|
||||
if (msg.p._id == gClient.getOwnParticipant()._id) return;
|
||||
var id = msg.p._id.substr(0,6);
|
||||
var name = sanitizeName(msg.p.name);
|
||||
var content = msg.a;
|
||||
|
@ -106,26 +107,28 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||
|
||||
// Discord to MPP
|
||||
{
|
||||
//let msgQueue = [];
|
||||
let msgQueue = [];
|
||||
dClient.on('message', async message => {
|
||||
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.author.tag;
|
||||
//if (str.startsWith('/') || str.startsWith('\\'))
|
||||
// msgQueue.push(`⤹ ${aname}`);
|
||||
//else
|
||||
if (str.startsWith('/') || str.startsWith('\\'))
|
||||
msgQueue.push(`⤹ ${aname}`);
|
||||
else
|
||||
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 (str.length > 512) str = str.substr(0,511) + '…';
|
||||
//msgQueue.push(str);
|
||||
gClient.sendArray([{m:'a', message: str}]);
|
||||
if (gClient.isConnected()) message.delete();
|
||||
if (str.length > 512) {
|
||||
str = str.substr(0,511) + '…';
|
||||
message.react('⚠');
|
||||
}
|
||||
msgQueue.push(str);
|
||||
});
|
||||
//setInterval(()=>{
|
||||
// let message = msgQueue.shift();
|
||||
// if (message) gClient.sendArray([{m:'a', message}]);
|
||||
//}, 1600); // just about fastest without exceeding quota; I figured quota is 4 messages per 6 seconds in lobbies
|
||||
setInterval(()=>{
|
||||
let message = msgQueue.shift();
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,7 +205,7 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||
|
||||
|
||||
// start
|
||||
(async function () {
|
||||
client.once("ready", async function () {
|
||||
global.bridges = require("./bridges");
|
||||
for (let bridge of bridges) {
|
||||
try {
|
||||
|
@ -211,4 +214,4 @@ global.createMPPbridge = async function createMPPbridge({room, channel, uri}) {
|
|||
handleError(error, JSON.stringify(bridge));
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
Loading…
Reference in New Issue