Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parseMessage' :: ReadP (String, [UserId], Integer)
- parseMessage' = do
- skipSpaces
- client <- parseClient
- skipSpaces
- runners <- parseRunners
- skipSpaces
- hours <- parseHours
- pure (client, runners, hours)
- parseClient :: ReadP String
- parseClient = do
- string "client"
- skipSpaces
- char ':'
- skipSpaces
- many1 $ satisfy $ \char -> (not . (== '\n')) char
- parseRunners :: ReadP [UserId]
- parseRunners = do
- string "runners"
- skipSpaces
- char ':'
- many1 parseDiscordId
- -- If I replace 'skipSpaces' with a function that skips until I find the first '<' it seems to
- -- break everything
- parseDiscordId :: ReadP UserId
- parseDiscordId = do
- skipSpaces
- char '<'
- char '@'
- optional $ char '!'
- userid <- fmap (Snowflake . read) $ many1 $ satisfy isDigit
- char '>'
- skipSpaces
- pure userid
- parseHours :: ReadP Integer
- parseHours = do
- start <- helper "start"
- optional $ (helper "pause" :: ReadP Integer)
- optional $ (helper "resume" :: ReadP Integer) <++ helper "restart"
- end <- helper "end"
- -- hack to figure out if it was actually a 1.5 or 2 hour session
- -- TODO: make the hack actually work
- extraHour <- pure 0
- -- figures out whether it was an hour or half hour duration
- pure $ 1 + (1 - (round (abs (((realToFrac end) - (realToFrac start)) / 30)))) + extraHour
- where notColon char = not $ char == ':'
- helper s = do
- string s
- skipMany $ satisfy notColon
- char ':'
- skipMany $ satisfy notColon
- char ':'
- skipSpaces
- time <- fmap read $ count 2 $ satisfy isDigit
- skipSpaces
- return time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement