Skip to content

Commit

Permalink
Add Celsius-to-Fahrenheit (and vice versa) converter
Browse files Browse the repository at this point in the history
  • Loading branch information
dsamarin committed May 30, 2012
1 parent 47e6d7e commit ab95aad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 6 additions & 3 deletions oftnbot-factoids.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"eboyjr": {
"value": "Have you seen my obscure interest lately?",
"popularity": 8
"popularity": 9
},
"collab": {
"value": "For real-time collaboration, we use Gobby 0.5. The server is eboyjr.oftn.org, run by eboyjr. If that's not available, we use <http://oftn.titanpad.com/>.",
Expand Down Expand Up @@ -241,8 +241,8 @@
"popularity": 1
},
"post hook": {
"value": "The Github Post-Receive Hook URL for oftn-bot is: http://eboyjr.oftn.org:9370/<uri-escaped-channel>",
"popularity": 3
"value": "The Github Post-Receive WebHook URL for oftn-bot is: http://eboyjr.oftn.org:9370/<uri-escaped-channel>",
"popularity": 4
},
"donate": {
"value": "https://www.wepay.com/donate/oftn",
Expand Down Expand Up @@ -309,6 +309,9 @@
"gods": {
"value": "locks",
"popularity": 0
},
"webhook": {
"alias": "post hook"
}
}
}
23 changes: 22 additions & 1 deletion oftnbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,34 @@ util.inherits(ΩF_0Bot, Bot);
if (context.sender.name === "sephr") {
context.client.raw ("PRIVMSG ChanServ :OP #oftn");
setTimeout (function() {
context.client.raw ("KICK #oftn sephr :You're not allowed to tell people to wait.");
context.client.raw ("KICK #oftn sephr :You're not allowed to use wait in that way.");
context.client.raw ("MODE #oftn +b *!*@unaffiliated/sephr :");
context.client.raw ("PRIVMSG ChanServ :DEOP #oftn");
}, 2 * 1000);
}
});

this.register_listener(/(-?\b\d+(?:\.\d*)?)\s+°?\s*([FC])\b/i, function(context, text, value, unit) {
var celsius, result;

value = parseFloat (value);
celsius = (unit === "C" || unit === "c");

if (celsius) {
converted = value * (9/5) + 32;
result = fmt(value) + " °C is " + fmt(converted) + " °F";
} else {
converted = (value - 32) * (5/9);
result = fmt(value) + " °F is " + fmt(converted) + " °C";
}

context.channel.send (result);

function fmt(value) {
return String(Math.round(value*100)/100);
}
});

this.password = "I solemnly swear that I am up to no evil";

this.register_command("access", function(context, text) {
Expand Down

0 comments on commit ab95aad

Please sign in to comment.