Created
October 3, 2015 22:22
-
-
Save andychase/247a16c9d5c1c5eace3f to your computer and use it in GitHub Desktop.
Minecraft Users Online Skype Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minecraft Server status poster | |
// License: MIT | |
// Andy Chase | |
// Note: You MUST disable CSP on your web client for this to work | |
// Configuration | |
// ----------------------------------------------- | |
// Change this (capture from a /message request in the skype web client) | |
var regToken = "registrationToken=?"; | |
// Change this (capture from a /message request in the skype web client) | |
var url = "https://client-s.gateway.messenger.live.com/v1/users/ME/conversations/<???>/messages"; | |
// Change this to your minecraft server address | |
var minecraft_url = "?.?.?.?"; | |
// Customize these messages | |
var bot_name = "[MINEBOT] "; | |
var part_msg = " is no longer playing Minecraft."; | |
var join_msg = " is now playing Minecraft!"; | |
// Poll server every 5 minutes | |
var poll_time = 5 * 60 * 1000; | |
// Posting Javascript | |
// ----------------------------------------------- | |
// Inject jQuery | |
document.createElement( 'script' ); | |
script.type = 'text/javascript'; | |
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"; | |
$("head").append( script ); | |
function sendMessage(messageText, time) { | |
jQuery.ajax(url, { | |
method: "POST", | |
headers: {RegistrationToken: regToken}, | |
data: JSON.stringify({ | |
"content": messageText, | |
"messagetype": "RichText", | |
"contenttype": "text", | |
"clientmessageid": time.toString() | |
}) | |
}) | |
} | |
var peopleOnline = {}; | |
function updatePlayers() { | |
jQuery.get("https://mcapi.ca/query/" + minecraft_url + "/list", function (playerData) { | |
var playerList = []; | |
var time = Date.now(); | |
if (playerData.Players.list !== false) { | |
playerList = playerData.Players.list; | |
} | |
for (var person in peopleOnline) { | |
if (playerList.indexOf(person) == -1) { | |
sendMessage(bot_name + person + part_msg, time++); | |
delete peopleOnline[person]; | |
} | |
} | |
jQuery.each(playerList, function (index, player) { | |
if (peopleOnline[player] === undefined) { | |
peopleOnline[player] = true; | |
sendMessage(bot_name + player + join_msg, time++); | |
} | |
}); | |
}); | |
} | |
setInterval(updatePlayers, poll_time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qwe