Skip to content

Commit 59c80d9

Browse files
authored
Merge pull request #818 from tsoding/friday-count-on-next-video
Friday count on next video
2 parents a2f2265 + 3b895b8 commit 59c80d9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Bot/Friday.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ fridayCommand =
134134
[qms|Could not check friday video
135135
duplicates because there is no YouTube
136136
id in the message.|]) $
137-
liftR
138-
(\ytId ->
139-
selectEntities (Proxy :: Proxy FridayVideo) $
140-
Filter (PropertyTextLike "name" ("%" <> ytId <> "%")) All) $
137+
liftR fridayVideosByYtId $
141138
cmapR
142139
(\dups ->
143140
[qms|Added to the suggested video.
@@ -216,11 +213,13 @@ videoCommand =
216213
liftR (const currentVideo) $
217214
replyOnNothing "No videos in the queue" $
218215
cmapR entityPayload $
216+
liftFst (fmap length . fridayVideosByYtId . fridayVideoName) $
219217
cmapR
220-
(\video ->
218+
(\(video, times) ->
221219
[qms|{fridayVideoDate video}
222220
<{fridayVideoAuthor video}>
223-
{fridayVideoName video}|]) $
221+
{fridayVideoName video} —
222+
This video was suggested {times} times.|]) $
224223
Reaction replyMessage
225224

226225
currentFridayState :: Effect (Entity FridayState)
@@ -323,13 +322,15 @@ videoQueueCommand =
323322
cmapR (const "Freshness invalidated 👌") $ Reaction replyMessage)
324323
]
325324

325+
fridayVideosByYtId :: T.Text -> Effect [Entity FridayVideo]
326+
fridayVideosByYtId ytId =
327+
selectEntities Proxy $
328+
Filter (PropertyTextLike "name" ("%" <> ytId <> "%")) All
329+
326330
fridayCountCommand :: Reaction Message T.Text
327331
fridayCountCommand =
328332
cmapR ytLinkId $
329333
replyOnNothing "Please submit a YouTube link" $
330-
liftR
331-
(\ytId ->
332-
selectEntities (Proxy :: Proxy FridayVideo) $
333-
Filter (PropertyTextLike "name" ("%" <> ytId <> "%")) All) $
334+
liftR fridayVideosByYtId $
334335
cmapR (\dups -> [qms|This video was suggested {length dups} times|]) $
335336
Reaction replyMessage

0 commit comments

Comments
 (0)