123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import Network
- import System.IO
- import Text.Printf
- import Data.List
- import System.Exit
-
- server = "irc.subtlefuge.com"
- port = 6667
- chan = "#subtlefuge"
- nick = "daskeb"
-
- main = do
- h <- connectTo server (PortNumber (fromIntegral port))
- hSetBuffering h NoBuffering
- write h "NICK" nick
- write h "USER" (nick++" 0 * :digitshaskellbot")
- write h "JOIN" chan
- listen h
-
- write :: Handle -> String -> String -> IO ()
- write h s t = do
- hPrintf h "%s %s\r\n" s t
- printf "> %s %s\n" s t
-
- listen :: Handle -> IO ()
- listen h = forever $ do
- t <- hGetLine h
- let s = init t
- if ping s then pong s else eval h (clean s)
- putStrLn s
- where
- forever a = a >> forever a
-
- clean = drop 1 . dropWhile (/= ':') . drop 1
-
- ping x = "PING :" `isPrefixOf` x
- pong x = write h "PONG" (':' : drop 6 x)
-
- eval :: Handle -> String -> IO ()
- eval h "!quit" = write h "QUIT" ":Exiting" >> exitWith ExitSuccess
- --eval h x | Just x <- stripPrefix "!id " x = privmsg h x
- --eval h (stripPrefix "!id " -> Just x) = privmsg h x
- eval h x | "!id " `isPrefixOf` x = privmsg h (drop 4 x)
- eval h "!search" = privmsg h "search yourself. :P"
- -- eval h "" = privmsg h ""
- -- these are some basic sample commands for u to try out to make your own ones.
- eval h "hello" = privmsg h "hello world"
- eval h "!testcommand" = privmsg h "this is the test responce."
- 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"
- -- eval h x | "!goog " `isPrefixOf` x = privmsg h (drop 4 x)
- eval _ _ = return () -- ignore everything else
- privmsg :: Handle -> String -> IO ()
- privmsg h s = write h "PRIVMSG" (chan ++ " :" ++ s)
|