Last active
June 26, 2023 07:10
-
-
Save donpdonp/cbb7590ab60f2e96f3801f1b361c426c to your computer and use it in GitHub Desktop.
gluon kernel
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() { | |
kernel_cache() | |
return {name:"kernel"} | |
}) | |
var db_key = "kernel:cache" | |
var kver = {} | |
var alert_channel = "#pdxtech" | |
function kernel_cache() { | |
db.get(db_key, function(json){ | |
if(json) { | |
kver = JSON.parse(json) | |
} | |
bot.say(bot.admin_channel, "kernel: "+JSON.stringify(kver)) | |
}) | |
} | |
function go(msg) { | |
if (msg.method == "clocktower") { | |
var time = new Date(Date.parse(msg.params.time)) | |
if(time.getMinutes() == 30) { | |
var kold = kver | |
kver = kernelorg() | |
dbsave() | |
Object.keys(kver).forEach(function(key){ | |
//bot.say(bot.admin_channel, "linux kernel prev "+key+" "+kold[key].version+" <> new "+kver[key].version) | |
// 'mainline' 'stable' 'longterm' | |
if(key != 'longterm') { | |
//bot.say(bot.admin_channel, "kver compare "+kold[key].version+" "+is_rc(kold[key].version)+" ... "+ | |
// kver[key].version +" "+is_rc(kver[key].version)) | |
if(is_rc(kold[key].version) && !is_rc(kver[key].version)) { | |
bot.say(alert_channel, "kernel.org reports linux kernel "+kver[key].version+" is here! https://kernelnewbies.org/Linux_"+kver[key].version) | |
} | |
} | |
}) | |
} | |
} | |
if (msg.method == "irc.privmsg") { | |
var match = /^!?kernel(\s+([A-Za-z-]+))?$/.exec(msg.params.message) | |
if(match) { | |
kver = kernelorg() | |
dbsave() | |
var names = match[2] ? [match[2]] : ["mainline", "stable"] | |
var say = names.map(function(name){ | |
var kdata = kver[name] | |
if (kdata) { | |
return name+" "+kdata.version+" "+kdata.date+"." | |
} else { | |
return name+" not found"+"." | |
} | |
}) | |
bot.say(msg.params.channel, "linux kernel "+say.join(' ')) | |
} | |
} | |
} | |
function is_rc(ver) { | |
return ver.indexOf('-rc') > -1 | |
} | |
function kernelorg() { | |
var ver = {} | |
var kurl = "https://www.kernel.org" | |
var html = http.get(kurl).replace(/\n/g,"").replace(/\r/g,"") | |
if(html.length > 0) { | |
var parts = html.split('table id="releases"')[1].split('tr align="left"') | |
parts.forEach(function(part){ | |
var match = /<td>(\w+):<\/td>.*?(\d+\.\d+[^<]*).*?(\d\d\d\d-\d\d-\d\d)/.exec(part) | |
if (match) { | |
if(!ver[match[1]]) { | |
ver[match[1]] = {version: match[2], date: match[3]} | |
//bot.say(bot.admin_channel, "K: "+JSON.stringify(kver[match[1]])) | |
} | |
} | |
}) | |
return ver | |
} else { | |
bot.say(bot.admin_channel, kurl+" empty "+html.length+" len") | |
} | |
} | |
function dbsave() { | |
var json = JSON.stringify(kver) | |
db.set(db_key, json) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment