Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Last active December 28, 2015 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdsgl/7576229 to your computer and use it in GitHub Desktop.
Save dvdsgl/7576229 to your computer and use it in GitHub Desktop.
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