module M_moin where

import Mdl
import System.Random


moin :: Mdl
moin log inp out = react f inp out
  where
  f (Msg u _ _ "PRIVMSG" (c@('#':_):"moin":_))
    = do log 2 (u++" said moin in "++c)
         x <- randomRIO (0,99 :: Int)
	 log 2 ("antworten? gewuerfelt: "++show x++" => "++show (x<70))
         if (x<50) then do d <- randomRIO (2,10)
	                   log 2 ("antwort in "++show d++"s")
                           threadDelay (d * 1000000)
                           atomically flushinput
                           return ["PRIVMSG "++c++" :moin"]
                   else return []

  flushinput = do isempty <- isEmptyTChan inp
                  unless isempty $ do readTChan inp
                                      flushinput
