{-# LANGUAGE QuasiQuotes, DeriveGeneric #-}
module Channel.Bitcoin where

import           Control.Monad ((>=>))
import           Data.List
import           Data.Traversable hiding (mapM)
import           GHC.Generics
import           Data.Aeson (FromJSON, Object)
import           Text.Regex.PCRE
import           Data.String.Interpolate

import           Channel.Traits
import qualified Channel.Match as Match
import           Channel.Command
import qualified Http
import           Http ((.:))

-- | Makes Alonzo convert from and to BTC
bitcoin :: Trait
bitcoin = Match.message $ \_ msg -> do
  me <- getMyNick
  case msg =~ ([i|#{me}|] ++ ": (\\d) BTC") of
    [[_, q]] -> do
      -- r <- Http.get ("http://gdata.youtube.com/feeds/api/videos?max-results=5&alt=json&q=" ++ q)
      -- let videos = r >>= extractLinks
      -- video <- traverse randomChoice videos
      say ("Fuck you! " ++ q)
    _ -> say "Foo"

-- extractLinks :: Object -> Maybe [Link]
-- extractLinks = (.: "feed") >=> (.: "entry") >=> mapM alternateLink
--   where
--     alternateLink :: Object -> Maybe Link
--     alternateLink = (.: "link") >=> find ((== "alternate") . rel)
