Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Report on infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Aug 27, 2016
1 parent 7d4456c commit c00ba3c
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 32 deletions.
33 changes: 1 addition & 32 deletions newsflash/index.js
Original file line number Diff line number Diff line change
@@ -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:",
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
121 changes: 121 additions & 0 deletions opsreport/index.js
Original file line number Diff line number Diff line change
@@ -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;
38 changes: 38 additions & 0 deletions randomtext.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c00ba3c

Please sign in to comment.