Last active
January 17, 2024 03:38
-
-
Save donpdonp/a20f31a85dc33a32f3213ed34a69075d to your computer and use it in GitHub Desktop.
gluon bigpipe
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
(function() { | |
return { | |
name: "bigpipe" | |
} | |
}) | |
var old_percent = 0 | |
var announce_channel = "#pdxbots" | |
function go(msg) { | |
if (msg.method == "clocktower") { | |
var time = new Date(Date.parse(msg.params.time)) | |
if (time.getMinutes() == 0) { | |
pipe_watch() | |
} | |
} | |
if(msg.method == "irc.privmsg") { | |
var match_bp = /^\!bigpipe(\s+(.+))?$/.exec(msg.params.message) | |
var match_ap = /^\!ansipoop(\s+(.+))?$/.exec(msg.params.message) | |
if(match_bp || match_ap) { | |
var percent = pipe_percent() | |
if(match_bp){ | |
bot.say(msg.params.channel, "bigpipe is at "+percent+"% capacity") | |
} | |
if(match_ap){ | |
var ap = '' | |
var poop = '💩' | |
for(var x = 0; x < 10; x++) { | |
if (x < percent/10) { | |
ap += poop | |
} else { | |
ap += '_' | |
} | |
} | |
bot.say(msg.params.channel, '|'+ap+'| '+percent+'%') | |
} | |
} | |
} | |
} | |
function pipe_watch() { | |
var percent = pipe_percent() | |
var diff = Math.abs(percent - old_percent) | |
if (diff > 5) { | |
bot.say(announce_channel, "bigpipe is at "+percent+"% capacity (was "+old_percent+"%)") | |
old_percent = percent | |
} | |
} | |
function pipe_percent() { | |
var url = "https://www.portlandoregon.gov/bes/bigpipe/gauge.cfm" | |
var doc = http.get({url: url}) | |
if (doc.status == 200) { | |
var html_no_cr = doc.body.replace(/(\r\n|\n|\r)/gm, ""); | |
var match = /percent__number..(\d+)/.exec(html_no_cr) | |
return parseFloat(match[1]) | |
} else { | |
bot.say(bot.admin_channel, doc.status+" loading "+url) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment