Last active
December 28, 2015 23:08
-
-
Save dvdsgl/7576229 to your computer and use it in GitHub Desktop.
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
module MonkeyBot.Plugins.WhatsForLunch | |
open System | |
open DDay.iCal | |
open MonkeyBot | |
let ZeroCaterId = "..." | |
type LunchResponse = | |
| Lunch of string | |
| NoLunch | |
| Error of exn | |
let getTodaysLunch () = | |
try | |
let calendar = | |
sprintf "http://www.zerocater.com/calendar?id=%s" ZeroCaterId | |
|> fun url -> iCalendar.LoadFromUri (Uri url) | |
|> Seq.head | |
let today = calendar.GetOccurrences DateTime.Today | |
if Seq.isEmpty today then NoLunch else | |
let event = today.[0].Source :?> RecurringComponent | |
Lunch event.Description | |
with e -> Error e | |
[<RespondTo("what(.*) lunch")>] | |
let ``what's for lunch?`` (bot: IBot) = | |
match getTodaysLunch () with | |
| Lunch description -> bot.Send description | |
| NoLunch -> bot.Send "You're on your own for lunch today." | |
| Error e -> | |
sprintf "I can't figure out what's for lunch (%s)" e.Message | |
|> bot.Send |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment