Skip to content

Instantly share code, notes, and snippets.

@ScalaWilliam
Forked from lucasgautheron/irc.js
Created April 12, 2016 01:01
Show Gist options
  • Save ScalaWilliam/3d63132db72fa6198935e6c3fe2b27af to your computer and use it in GitHub Desktop.
Save ScalaWilliam/3d63132db72fa6198935e6c3fe2b27af to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var EventSource = require('eventsource');
var cfgPath = require('confortable')('stream.json', process.cwd());
if (!cfgPath) {
throw new Error("Could not load stream.json");
}
var cfg = require(cfgPath);
var ircStream = require('irc-stream')(cfg.irc.server, cfg.irc.name, {
userName: 'ActionFPS_Bot',
realName: 'actionfps.com',
debug: false,
channels: cfg.irc.chan
}, { conversationMode: true });
function countPlayers(server)
{
var playerCount = 0;
if('game' in server)
{
if('teams' in server['game']) for(var team_index in server['game']['teams']) {
var team = server['game']['teams'][team_index];
playerCount += team['players'].length;
if('spectators' in team) playerCount += team['spectators'].length;
}
if('players' in server['game'])
playerCount += server['game']['players'].length;
if('spectators' in server['game'])
playerCount += server['game']['spectators'].length;
}
return playerCount;
}
var es = new EventSource(cfg.source);
var ses = new EventSource(cfg.servers_source);
var servers = new Array();
es.addEventListener("inter", function(event) {
var inter = JSON.parse(event.data);
console.log(inter['playerName'] + ' ' + inter['serverConnect']);
var msg = '';
if(inter['serverConnect'] in servers)
{
var server = servers[inter['serverConnect']];
var playerCount = countPlayers(server);
msg = inter['playerName'] + ' started an inter and is looking for players on ' + inter['serverName'] + ' (/connect ' + server['connectName'] + '), ' + playerCount + ' players online';
}
else
msg = inter['playerName'] + ' started an inter and is looking for players on ' + inter['serverName'];
ircStream.write({ message: msg, user: cfg.irc.chan });
});
ses.addEventListener("server-status", function(event) {
var server = JSON.parse(event.data);
//console.log(server['canonicalName']);
servers['assaultcube://' + server['canonicalName']] = server;
});

ActionFPS IRC Bot

Run

nodejs irc.js

TODO

  • discard old messages
  • make it a proper nodejs pacakge with dependencies
{
"irc": {
"name": "ActionFPS",
"server": "irc.gamesurge.net",
"chan": [ "#woop-clan", "#paradoxinfinity" ]
},
"source": "http://actionfps.com/inters/",
"servers_source": "http://actionfps.com/server-updates/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment