daskeb.hs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import Network
  2. import System.IO
  3. import Text.Printf
  4. import Data.List
  5. import System.Exit
  6. server = "irc.subtlefuge.com"
  7. port = 6667
  8. chan = "#subtlefuge"
  9. nick = "daskeb"
  10. main = do
  11. h <- connectTo server (PortNumber (fromIntegral port))
  12. hSetBuffering h NoBuffering
  13. write h "NICK" nick
  14. write h "USER" (nick++" 0 * :digitshaskellbot")
  15. write h "JOIN" chan
  16. listen h
  17. write :: Handle -> String -> String -> IO ()
  18. write h s t = do
  19. hPrintf h "%s %s\r\n" s t
  20. printf "> %s %s\n" s t
  21. listen :: Handle -> IO ()
  22. listen h = forever $ do
  23. t <- hGetLine h
  24. let s = init t
  25. if ping s then pong s else eval h (clean s)
  26. putStrLn s
  27. where
  28. forever a = a >> forever a
  29. clean = drop 1 . dropWhile (/= ':') . drop 1
  30. ping x = "PING :" `isPrefixOf` x
  31. pong x = write h "PONG" (':' : drop 6 x)
  32. eval :: Handle -> String -> IO ()
  33. eval h "!quit" = write h "QUIT" ":Exiting" >> exitWith ExitSuccess
  34. --eval h x | Just x <- stripPrefix "!id " x = privmsg h x
  35. --eval h (stripPrefix "!id " -> Just x) = privmsg h x
  36. eval h x | "!id " `isPrefixOf` x = privmsg h (drop 4 x)
  37. eval h "!search" = privmsg h "search yourself. :P"
  38. -- eval h "" = privmsg h ""
  39. -- these are some basic sample commands for u to try out to make your own ones.
  40. eval h "hello" = privmsg h "hello world"
  41. eval h "!testcommand" = privmsg h "this is the test responce."
  42. eval h "!daskeb" = privmsg h "hello, i am daskeb, digit's haskell bot. of course, i'm just a basic starter template. you might want to look up http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot just for starters. i came from half of that. i now have my own web presence at http://wastedartist.com/scripts/daskeb/daskeb.html"
  43. -- eval h x | "!goog " `isPrefixOf` x = privmsg h (drop 4 x)
  44. eval _ _ = return () -- ignore everything else
  45. privmsg :: Handle -> String -> IO ()
  46. privmsg h s = write h "PRIVMSG" (chan ++ " :" ++ s)