Created
August 4, 2011 20:39
-
-
Save devyn/1126193 to your computer and use it in GitHub Desktop.
!sol command for oftn-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Flags(text) { | |
var m = text.match(/^-([^ ]+)( (.+))?/); | |
if (m) { | |
var s = m[1].split(""); | |
return {all: s, flags: s.reduce(function(o,i) { o[i] = true; return o; }, {}), args: m[2] ? m[3] : undefined}; | |
} else { | |
return null; | |
} | |
} | |
ΩF_0Bot.prototype.sol = function (context, text) { | |
if (text) { | |
var f = Flags(text); | |
if (f) { | |
if (f.flags.r && f.all.length == 2) { | |
if (f.flags.s && f.args) { | |
// to relative gregorian from relative sol | |
return context.channel.send_reply(context.intent, Sol.parseSol(f.args, false).toStupidString()); | |
} else if (f.flags.g && f.args) { | |
// to relative sol from relative gregorian | |
return context.channel.send_reply(context.intent, Sol.parseStupid(f.args, false).toString()); | |
} | |
} else if (f.flags.a && f.all.length == 2) { | |
if (f.flags.s && f.args) { | |
// add a relative UJD to the current time and return the result in gregorian time | |
return context.channel.send_reply(context.intent, new Sol(new Sol().floating + Sol.parseSol(f.args).floating).toStupidString()); | |
} else if (f.flags.g && f.args) { | |
// add a relative gregorian time to the current time and return the result as a UJD | |
return context.channel.send_reply(context.intent, new Sol(new Sol().floating + Sol.parseStupid(f.args).floating).toString()); | |
} | |
} else if (f.all.length == 1) { | |
if (f.flags.s && f.args) { | |
// to absolute gregorian from absolute sol | |
return context.channel.send_reply(context.intent, Sol.parseSol(f.args, true).toStupidString()); | |
} else if (f.flags.g && f.args) { | |
// to absolute sol from absolute gregorian | |
return context.channel.send_reply(context.intent, Sol.parseStupid(f.args, true).toString()); | |
} else if (f.flags.h) { | |
var s = context.sender; | |
s.send("----------------------------[ !sol command usage ]-----------------------------"); | |
s.send("!sol"); | |
s.send(" Outputs the current time in the Unix-Julian Date format."); | |
s.send("!sol -g <time>"); | |
s.send(" Converts an ISO 8601 Gregorian time to UJD."); | |
s.send("!sol -gr <amount>"); | |
s.send(" Converts a relative Gregorian amount (e.g. 8 months) to the equivalent"); | |
s.send(" measurement in sols (ſ)."); | |
s.send("!sol -ga <amount>"); | |
s.send(" Outputs the current time in UJD, advanced by <amount> specified in Gregorian"); | |
s.send(" measurements."); | |
s.send("!sol -s <time>"); | |
s.send(" Converts a Unix-Julian Date to the conventional Gregorian format."); | |
s.send("!sol -sr <amount>"); | |
s.send(" Converts an amount measured in sols (ſ) to a Gregorian-based amount."); | |
s.send("!sol -sa <amount>"); | |
s.send(" Outputs the current UTC time in Gregorian, advanced by <amount> sols (ſ)."); | |
s.send("-------------------------------------------------------------------------------"); | |
return; | |
} | |
} | |
} | |
context.channel.send_reply(context.sender, | |
"Invalid usage. If you invoke `!sol -h`, I'll PM you with instructions on how to use !sol."); | |
} else { | |
// current time in UJD | |
context.channel.send_reply(context.intent, new Sol().toString()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment