From c00ba3c03d3099f59c8e5a5a65539307b956f24a Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sat, 27 Aug 2016 03:25:39 -0400 Subject: [PATCH] Report on infrastructure. --- newsflash/index.js | 33 +------------ opsreport/index.js | 121 +++++++++++++++++++++++++++++++++++++++++++++ randomtext.js | 38 ++++++++++++++ server.js | 7 +++ 4 files changed, 167 insertions(+), 32 deletions(-) create mode 100644 opsreport/index.js create mode 100644 randomtext.js diff --git a/newsflash/index.js b/newsflash/index.js index adb68a4..86b2e99 100644 --- a/newsflash/index.js +++ b/newsflash/index.js @@ -1,6 +1,4 @@ -function choose(list) { - return list[Math.floor(Math.random() * list.length)]; -} +let { choose, combine, reduce, whole_number, percentage } = require("../randomtext"); var opener = [ "BREAKING NEWS:", @@ -146,14 +144,6 @@ var negative_verb = [ "outperformed" ]; -function whole_number() { - return Math.floor(Math.random() * 100); -} - -function percentage() { - return whole_number() + "%"; -} - function range_percentage() { var first = whole_number(); var second = whole_number(); @@ -232,27 +222,6 @@ var ending = [ "" ]; -function reduce(item) { - if (Array.isArray(item)) { - return reduce(choose(item)); - } - if (typeof item === "function") { - return reduce(item()); - } - return item; -} - -function combine(list) { - if (!Array.isArray(list)) { - list = [list]; - } - var combined = ""; - for (var i = 0; i < list.length; i++) { - combined += reduce(list[i]) + ' '; - } - return combined.slice(0, combined.length - 1); -} - function newsflash() { var pattern = choose(patterns); var combined = combine(pattern); diff --git a/opsreport/index.js b/opsreport/index.js new file mode 100644 index 0000000..93b1ad4 --- /dev/null +++ b/opsreport/index.js @@ -0,0 +1,121 @@ +let { choose, combine, reduce, percentage, whole_number } = require("../randomtext"); + +var opener = [ + "RED ALERT:", + "Here's the deal:", + "Well,", + "What do you know?", + "The usual:", + "How odd -", + "Surprise!", + "fyi", + "in case you missed it,", + "you should probably be aware that", + "unchanged -", + "hard to complain:" +]; + +var platform = [ + 'ARM32', + 'ARM64', + 'android', + 'windows', + 'mac', + 'linux64', + 'linux32', + 'cortex-m4', + 'haiku', + 'redox', +] + +function builder() { + return 'the ' + choose(platform) + ' builder'; +} + +var tech = [ + 'AWS', + 'macstadium', + 'github', + builder, + 'larsbors', + 'homu', + 'crates.io', + 'servo.org', + 'reviewable', + 'TravisCI', + 'appveyor', + 'buildbot', + 'irccloud', + 'bors', + 'cloudflare', + 'pypi', + 'hg.mozilla.org' +]; + +var problem = [ + "stopped responding", + "can't be pinged since", + "started installing a system upgrade", + "had to be restarted", + "no longer accepts SSH connections since", + "stopped running tests", + "is under a DDoS attack since", + "ran out of disk space", + "began renegotiating our contract", + "locked me out", + "enabled 2fa", +]; + +function duration() { + var units = [ + "milliseconds", + "seconds", + "minutes", + "hours", + "days", + "weeks", + "months" + ]; + return whole_number + ' ' + choose(units); +} + +var comparison = [ + "above", + "below" +]; + +var patterns = [ + [tech, problem, duration, "ago"], + ["no problems detected"], + [tech, "is", "running", percentage, comparison, "capacity"], + [tech, "is", "taking", whole_number, "times", "longer", "than", "usual"], + ["only", whole_number, "interruptions", "for", tech, "so", "far"], + [tech, "is", "under", "heavy", "load"], + ["no", "issues", "with", tech, "in", duration], + [tech, "was", "taken", "down", "for", "maintenance", duration, "ago"], + ["switching", "to", tech, "was", "a", "good", "choice"], + ["it", "has", "been", duration, "since", "the", "last", "incident"] +]; + +var ending = [ + "", + ".", + "...", + "!", + "!!", + " :/", + " :<", + " :(", + "; so far so good!", +]; + +function report() { + var pattern = choose(patterns); + var combined = combine(pattern); + if (Math.random() > 0.5) { + combined = choose(opener) + ' ' + combined; + } + return combined + choose(ending); +} + +exports.report = report; diff --git a/randomtext.js b/randomtext.js new file mode 100644 index 0000000..602ad78 --- /dev/null +++ b/randomtext.js @@ -0,0 +1,38 @@ +function reduce(item) { + if (Array.isArray(item)) { + return reduce(choose(item)); + } + if (typeof item === "function") { + return reduce(item()); + } + return item; +} + +function combine(list) { + if (!Array.isArray(list)) { + list = [list]; + } + var combined = ""; + for (var i = 0; i < list.length; i++) { + combined += reduce(list[i]) + ' '; + } + return combined.slice(0, combined.length - 1); +} + +function choose(list) { + return list[Math.floor(Math.random() * list.length)]; +} + +function whole_number() { + return Math.floor(Math.random() * 100); +} + +function percentage() { + return whole_number() + "%"; +} + +exports.reduce = reduce; +exports.choose = choose; +exports.combine = combine; +exports.whole_number = whole_number; +exports.percentage = percentage; diff --git a/server.js b/server.js index 1a46acb..0cfda7b 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,7 @@ var irc = require("irc"), notes = require("./notes"), config = require("./config"), newsflash = require("./newsflash"), + opsreport = require("./opsreport"), storage = require('node-persist'); function githubRequest(endpoint, callback) { @@ -295,6 +296,12 @@ var handlerWrapper = module.exports.handlerWrapper = function handlerWrapper(pin return; } + if (message.indexOf("infrastructure report") > -1) { + var rumour = opsreport.report(); + bot.say(to, rumour); + return; + } + if (message.indexOf("what does the fox say") > -1) { findIssue(from, to, "?labels=A-stylo", bot); return;