Skip to content

Instantly share code, notes, and snippets.

@donpdonp donpdonp/kernel.js

Last active Mar 1, 2020
Embed
What would you like to do?
gluon kernel
(function() {
kernel_cache()
return {name:"kernel"}
})
var db_key = "kernel:cache"
var kver = {}
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)
if(kold[key].version != kver[key].version) {
bot.say("#pdxbots", "linux kernel "+key+" "+kold[key].version+" -> "+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, "kernel "+say.join(' '))
}
}
}
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
You can’t perform that action at this time.