diff options
author | Colin <dscdsouza@outlook.com> | 2016-08-29 15:13:02 +0000 |
---|---|---|
committer | Colin <dscdsouza@outlook.com> | 2016-08-29 15:13:02 +0000 |
commit | fdefdb1d98b24bff2b275fb1b68acfa10bed99ae (patch) | |
tree | 1d5fb9d0d8beaae87bb1567e4086c71b4411c6e5 /index.js | |
parent | Update discord.js version (diff) | |
download | shulker-fdefdb1d98b24bff2b275fb1b68acfa10bed99ae.tar.gz shulker-fdefdb1d98b24bff2b275fb1b68acfa10bed99ae.zip |
Fixes
Diffstat (limited to '')
-rw-r--r-- | index.js | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/index.js b/index.js index 435ac15..8dcff4d 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ 'use strict'; var Discord = require("discord.js"); -var Rcon = require("rcon"); +var Rcon = require("./lib/rcon.js"); var express = require("express"); var app = express(); var http = require("http").Server(app); @@ -10,29 +10,8 @@ var c = require("./config.json"); var debug = c.DEBUG; var shulker = new Discord.Client(); -var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT, c.MINECRAFT_SERVER_RCON_PASSWORD); var rconTimeout; -client.on("auth", function() { - console.log("[INFO] Authenticated with " + c.MINECRAFT_SERVER_RCON_IP + ":" + c.MINECRAFT_SERVER_RCON_PORT); -}).on("response", function(str) { - if (debug && str) { - console.log("[DEBUG] Got response: " + str); - } -}).on("end", function() { - console.log("[INFO] Rcon closed!"); -}).on("error", function() { - if (typeof rconTimeout === 'undefined') { - client.disconnect(); - rconTimeout = setTimeout(function() { - client.connect(); - rconTimeout = undefined; - }, c.RCON_RECONNECT_DELAY * 1000); - } -}); - -client.connect(); - app.use(function(request, response, next) { request.rawBody = ""; request.setEncoding("utf8"); @@ -47,7 +26,7 @@ app.use(function(request, response, next) { }); shulker.on("ready", function() { - var channel = shulker.channels.get("name", c.DISCORD_CHANNEL).id; + var channel = c.DISCORD_CHANNEL_ID; app.post(c.WEBHOOK, function(request, response) { var body = request.rawBody; console.log("[INFO] Recieved " + body); @@ -59,7 +38,7 @@ shulker.on("ready", function() { console.log("[DEBUG] Username: " + bodymatch[1]); console.log("[DEBUG] Text: " + bodymatch[2]); } - var message = "**" + bodymatch[1] + "**: " + bodymatch[2]; + var message = "`" + bodymatch[1].replace(/(\ยง[A-Z-a-z-0-9])/g, "") + "`:" + bodymatch[2]; shulker.channels.get("id", channel).sendMessage(message); } response.send(""); @@ -70,14 +49,19 @@ shulker.on("message", function(message) { if (message.channel.id === shulker.channels.get("name", c.DISCORD_CHANNEL).id) { if (message.author.id !== shulker.user.id) { var data = { - text: "<" + message.author.username + "> " + message.content + text: "<" + message.author.username + "> " + message.cleanContent }; - client.send('tellraw @a ["",' + JSON.stringify(data) + ']'); + var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT); // create rcon client + client.auth(c.MINECRAFT_SERVER_RCON_PASSWORD, function(err){ // only authenticate when needed + client.command('tellraw @a ["",' + JSON.stringify(data) + ']', function(err, resp) { + client.close(); // close the rcon connection + }); + }) } } }); -shulker.login(c.DISCORD_EMAIL, c.DISCORD_PASSWORD); +shulker.loginWithToken(c.DISCORD_TOKEN); var ipaddress = process.env.OPENSHIFT_NODEJS_IP || process.env.IP || "127.0.0.1"; var serverport = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || c.PORT; |