Skip to content

Instantly share code, notes, and snippets.

@AngusP
Last active October 29, 2019 19:52
Show Gist options
  • Save AngusP/b45bd2c5143e8fa230a6 to your computer and use it in GitHub Desktop.
Save AngusP/b45bd2c5143e8fa230a6 to your computer and use it in GitHub Desktop.
rfcToEntry :: String -> String -> Maybe Entry
rfcToEntry t str
| " PRIVMSG" `isPrefixOf` (dropWhile (/=' ') str) && ":ACTION" `isPrefixOf` (dropWhile (/=':') $ dropWhile (/=' ') str)
= Just ( t , takeWhile (/='!') $ drop 1 str ,
(takeWhile (/='!') $ drop 1 str) ++ (dropWhile (/=' ') $ dropWhile (/=':') $ tail $ dropWhile (/=' ') $ tail str) )
| " PRIVMSG" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , takeWhile (/='!') $ drop 1 str ,
tail $ dropWhile (/=':') $ dropWhile (/=' ') $ tail str )
| " PART" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , takeWhile (/='!') $ drop 1 str , "$left" )
| " QUIT" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , takeWhile (/='!') $ drop 1 str , "$left" )
| " JOIN" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , takeWhile (/='!') $ drop 1 str , "$joined" )
| " KICK" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , "$kick" ,
(takeWhile (/='!') $ drop 1 str) ++ " kicked " ++ (last (splitByDelim " " $ takeWhile (/=':') $ dropWhile (/=' ') $ tail str)) )
| " NICK" `isPrefixOf` (dropWhile (/=' ') str) = Just ( t , takeWhile (/='!') $ drop 1 str ,
head $ words $ tail $ dropWhile (/=':') $ tail str )
| otherwise = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment