|
- {-# LANGUAGE MultiWayIf #-}
-
- module IrcBot.BotActions where
-
-
- import Network.Connection
- import Network.Socket hiding (send, sendTo, recv, recvFrom)
- import qualified Data.ByteString.Char8 as C
- import IrcBot.BotNetwork
- import IrcBot.BotNetworkCommands
- import IrcBot.MessageParser
- import IrcBot.BotCustomCommands
-
- messageParse:: Connection -> C.ByteString -> IO()
-
-
- -- its kind of interface for actionFunctions
- callActionFunction :: (IServerResponse -> IO()) -> IServerResponse -> IO ()
- callActionFunction myFunc parameter1 = myFunc parameter1
-
-
- messageParse sock stringData =
- do
- let unpackedByteString = C.unpack stringData
- let debugData = "READ DATA FROM SOCKET: " ++ unpackedByteString
- let userNick = parseNick unpackedByteString
- let channelName = parseChannelName unpackedByteString
- let messageText = parseMessageText unpackedByteString
- let newServerResponse = IServerResponse {
- readDataString = unpackedByteString,
- readDataByteString = stringData,
- sock = sock,
- channelName = channelName,
- nick = userNick,
- messageText = messageText
- }
- mapM (\x -> callActionFunction (x) newServerResponse) (methods myMethodList)
- let d = "PARSE PURSE MESASGE: " ++ messageText
- print d
- print debugData
- -- if | hasStringExist "PING " stringData -> pong sock unpackedByteString
- -- | hasStringExist ".sup" stringData -> sendMessage sock channelName ("sup " ++ userNick)
- -- | hasStringExist " KICK #" stringData -> joinChannel sock channelName >> {-- auto connect in case of kick --} sendMessage sock channelName "fuck you"
- -- | hasStringExist ".random" stringData -> basicRandomImplementation unpackedByteString >>= \commandOutput -> sendMessage sock channelName commandOutput
- -- | hasStringExist ".quit" stringData -> quitFromServer sock channelName
- -- | hasStringExist ".leave" stringData -> disconnectFromChannel sock channelName
- -- | otherwise -> print "NO CONDITION FOUND TO PARSE"
-
- connectToServer :: String -> PortNumber -> Bool -> IO Connection
- connectToServer server port ssl = do
- open server port ssl
-
- connectionLoop :: Connection -> IO Connection
- connectionLoop sock =
- do
- stringData <- readFromSocket sock
- messageParse sock stringData
- case stringData == C.empty of
- False -> do
- connectionLoop sock
- True -> do
- return sock
|