From 3510a515296d41d5e1cb8d414ed7fd7112a638b8 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Wed, 31 Mar 2021 21:59:22 -0600 Subject: [PATCH] websocket loggers test --- bot.js | 3 ++- commands/dev/logger.js | 20 ++++++++++++++++++++ events/message.js | 1 + loggers/cmds.js | 13 +++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 commands/dev/logger.js create mode 100644 loggers/cmds.js diff --git a/bot.js b/bot.js index 2122a88..b74f905 100644 --- a/bot.js +++ b/bot.js @@ -23,7 +23,8 @@ client.misc = { xp: {}, hasLevelRoles: [] } - } + }, + loggers: {} }; //const config = require('./config.js'); diff --git a/commands/dev/logger.js b/commands/dev/logger.js new file mode 100644 index 0000000..3812d86 --- /dev/null +++ b/commands/dev/logger.js @@ -0,0 +1,20 @@ +const Discord = require('discord.js'); + +const ws = require('ws'); + +module.exports = { + name: "logger", + aliases: [], + meta: { + category: 'Developer', + description: "Websocket logs cause im cool", + syntax: '`nonya`', + extra: null + }, + help: "Websocket logs cause im cool", + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!client.developers.includes(message.author.id)) {return message.channel.send("Fuck off");} + client.misc.loggers[args[0]] = new ws(`ws://${args[1]}:${args[2]}`); + return message.channel.send("Logger set"); + } +}; \ No newline at end of file diff --git a/events/message.js b/events/message.js index 0a2290d..85882fe 100644 --- a/events/message.js +++ b/events/message.js @@ -82,6 +82,7 @@ module.exports = async (client, message) => { message.channel.stopTyping(); if (command.meta && command.meta.guildOnly && !message.guild) {return message.channel.send("You must be in a server to use this command!");} require('../util/oncommand')(message, msg, args, cmd, prefix, mention, client); + if (client.misc.loggers.cmds) {client.misc.loggers.cmds.send(`${chalk.gray("[CMDL]")} >> ${chalk.white("Command")} ${chalk.blue(command.name)} ${message.guild ? `|| ${chalk.blue("Guild ID: ")} ${chalk.blueBright(message.guild.id)}` : ''} || ${chalk.blue("User ID: ")} ${chalk.blueBright(message.author.id)}`);} return command.execute(message, msg, args, cmd, prefix, mention, client); } let trigger; for (trigger of client.responses.triggers) {if (await trigger[1](message, msg, args, cmd, prefix, mention, client)) {await client.responses.commands.get(trigger[0]).execute(message, msg, args, cmd, prefix, mention, client); break;}} diff --git a/loggers/cmds.js b/loggers/cmds.js new file mode 100644 index 0000000..e7ef816 --- /dev/null +++ b/loggers/cmds.js @@ -0,0 +1,13 @@ +const ws = require('ws'); +const chalk = require('chalk'); + +const port = 1029; + +const wss = new ws.Server({port: port}); + +console.log(`\n${chalk.white("[BOOT]")} >> ${chalk.greenBright(`Initialized Websocket on`)} ${chalk.white(`port ${port}`)}\n`); + +wss.on('connection', (ws) => { + console.log(`\n${chalk.white("[SCKT]")} >> ${chalk.blue("Received new websocket connection")}\n`); + ws.on('message', (msg) => {console.log(msg);}); +}); \ No newline at end of file