25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.9KB

  1. {-# LANGUAGE MultiParamTypeClasses #-}
  2. module IrcBot.IrcBot where
  3. import Network.Socket
  4. import IrcBot.BotNetworkCommands
  5. import IrcBot.BotActions
  6. import IrcBot.BotNetwork
  7. import Network.Connection
  8. import qualified Control.Concurrent as T
  9. import qualified Data.ByteString.Char8 as C
  10. import IrcBot.Definitions.ServerAddress
  11. connectToIRCServer :: IServerAddress -> IO ()
  12. connectToIRCServer serverAddress = do
  13. newSock <- connectToServer (server serverAddress) (fromIntegral (port serverAddress)) (ssl serverAddress)
  14. print "[connected to server]"
  15. initBotName newSock (nickname serverAddress)
  16. initBotNick newSock (nickname serverAddress)
  17. initAuthNickServ newSock (nickname serverAddress) (password serverAddress)
  18. print "waiting for identification with very stupid way"
  19. T.threadDelay (1000000 * 15) --wait wait
  20. let channelsToJoin = channels serverAddress
  21. mapM (\x -> joinChannel newSock x) channelsToJoin
  22. connectionLoop newSock serverAddress
  23. print "sleeping 15 sec for reconnect"
  24. -- 1000000 is 1 second
  25. T.threadDelay (1000000 * 15)
  26. print "reconnecting sequence initializing"
  27. -- this is a recursive function and its maintaining own connectivity
  28. -- how deep can i call this function? or just compiler optimizes for me? no idea
  29. connectToIRCServer (serverAddress)