@@ -12,6 +12,7 @@ module Bot.Friday
1212 , videoQueueCommand
1313 , startRefreshFridayGistTimer
1414 , ytLinkId
15+ , fridayCountCommand
1516 ) where
1617
1718import Bot.GitHub
@@ -98,15 +99,16 @@ instance IsEntity FridayState where
9899containsYtLink :: T. Text -> Bool
99100containsYtLink = isJust . ytLinkId
100101
102+ ytLinkRegexp :: T. Text
103+ ytLinkRegexp =
104+ " https?:\\ /\\ /(www\\ .)?youtu(be\\ .com\\ /watch\\ ?v=|\\ .be\\ /)([a-zA-Z0-9_-]+)"
105+
101106ytLinkId :: T. Text -> Maybe T. Text
102107ytLinkId text =
103108 (\ case
104109 [_, _, ytId] -> return ytId
105110 _ -> Nothing ) =<<
106- rightToMaybe
107- (regexParseArgs
108- " https?:\\ /\\ /(www\\ .)?youtu(be\\ .com\\ /watch\\ ?v=|\\ .be\\ /)([a-zA-Z0-9_-]+)"
109- text)
111+ rightToMaybe (regexParseArgs ytLinkRegexp text)
110112
111113fridayCommand :: Reaction Message T. Text
112114fridayCommand =
@@ -116,13 +118,31 @@ fridayCommand =
116118 liftR
117119 (\ msg -> do
118120 markGistUnfresh
119- createEntity Proxy .
121+ void $
122+ createEntity Proxy .
120123 FridayVideo
121124 (messageContent msg)
122125 (senderName $ messageSender msg)
123126 Nothing =<<
124- now) $
125- cmapR (const " Added to the suggestions" ) $ Reaction replyMessage
127+ now
128+ return $ messageContent msg) $
129+ cmapR ytLinkId $
130+ maybeReaction
131+ (Reaction $
132+ const $
133+ logMsg
134+ [qms |Could not check friday video
135+ duplicates because there is no YouTube
136+ id in the message.|]) $
137+ liftR
138+ (\ ytId ->
139+ selectEntities (Proxy :: Proxy FridayVideo ) $
140+ Filter (PropertyTextLike " name" (" %" <> ytId <> " %" )) All ) $
141+ cmapR
142+ (\ dups ->
143+ [qms |Added to the suggested video.
144+ This video was suggested {length dups} times|]) $
145+ Reaction replyMessage
126146
127147unwatchedVideos :: Effect [Entity FridayVideo ]
128148unwatchedVideos =
@@ -302,3 +322,14 @@ videoQueueCommand =
302322 liftR updateEntityById $
303323 cmapR (const " Freshness invalidated 👌" ) $ Reaction replyMessage)
304324 ]
325+
326+ fridayCountCommand :: Reaction Message T. Text
327+ fridayCountCommand =
328+ cmapR ytLinkId $
329+ replyOnNothing " Please submit a YouTube link" $
330+ liftR
331+ (\ ytId ->
332+ selectEntities (Proxy :: Proxy FridayVideo ) $
333+ Filter (PropertyTextLike " name" (" %" <> ytId <> " %" )) All ) $
334+ cmapR (\ dups -> [qms |This video was suggested {length dups} times|]) $
335+ Reaction replyMessage
0 commit comments