Permalink
Browse files

Add Celsius-to-Fahrenheit (and vice versa) converter

  • Loading branch information...
1 parent 47e6d7e commit ab95aad22ddd8679809a9b8130222bc737e37143 @dsamarin dsamarin committed May 30, 2012
Showing with 28 additions and 4 deletions.
  1. +6 −3 oftnbot-factoids.json
  2. +22 −1 oftnbot.js
View
@@ -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/>.",
@@ -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",
@@ -309,6 +309,9 @@
"gods": {
"value": "locks",
"popularity": 0
+ },
+ "webhook": {
+ "alias": "post hook"
}
}
}
View
@@ -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) {

0 comments on commit ab95aad

Please sign in to comment.