From 46328ff345f1f944d19d9e455fa476b7d87438a8 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Mon, 25 Nov 2019 19:55:13 +0100 Subject: [PATCH 1/6] Update custom commands in help after they changed --- src/Bot/CustomCommand.hs | 32 ++++++++------------------------ src/Bot/CustomCommandType.hs | 34 ++++++++++++++++++++++++++++++++++ src/Bot/Help.hs | 2 +- 3 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 src/Bot/CustomCommandType.hs diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index d4f85b1..c10757f 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -8,11 +8,12 @@ module Bot.CustomCommand , updateCustomCommand , showCustomCommand , timesCustomCommand - , CustomCommand(..) ) where +import Bot.CustomCommandType import Bot.Expr import Bot.Flip +import Bot.Help import Bot.Replies import Command import Control.Monad @@ -32,35 +33,16 @@ import Reaction import Text.InterpolatedString.QM import Transport -data CustomCommand = CustomCommand - { customCommandName :: T.Text - , customCommandMessage :: T.Text - , customCommandTimes :: Int - } - -instance IsEntity CustomCommand where - nameOfEntity _ = "CustomCommand" - toProperties customCommand = - M.fromList - [ ("name", PropertyText $ customCommandName customCommand) - , ("message", PropertyText $ customCommandMessage customCommand) - , ("times", PropertyInt $ customCommandTimes customCommand) - ] - fromProperties properties = - CustomCommand <$> extractProperty "name" properties <*> - extractProperty "message" properties <*> - pure (fromMaybe 0 $ extractProperty "times" properties) - customCommandByName :: T.Text -> MaybeT Effect (Entity CustomCommand) customCommandByName name = MaybeT $ fmap listToMaybe $ selectEntities Proxy $ Filter (PropertyEquals "name" $ PropertyText name) All --- TODO(#815): CRUD custom command should update help page now they're listed there as well. addCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) addCustomCommand builtinCommands = - Reaction $ \Message {messageSender = sender, messageContent = (name, message)} -> do + Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do + runReaction refreshHelpGistId mesg customCommand <- runMaybeT $ customCommandByName name let builtinCommand = M.lookup name builtinCommands case (customCommand, builtinCommand) of @@ -85,7 +67,8 @@ addCustomCommand builtinCommands = deleteCustomCommand :: CommandTable -> Reaction Message T.Text deleteCustomCommand builtinCommands = - Reaction $ \Message {messageSender = sender, messageContent = name} -> do + Reaction $ \mesg@Message {messageSender = sender, messageContent = name} -> do + runReaction refreshHelpGistId mesg customCommand <- runMaybeT $ customCommandByName name let builtinCommand = M.lookup name builtinCommands case (customCommand, builtinCommand) of @@ -155,7 +138,8 @@ timesCustomCommand builtinCommands = updateCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) updateCustomCommand builtinCommands = - Reaction $ \Message {messageSender = sender, messageContent = (name, message)} -> do + Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do + runReaction refreshHelpGistId mesg customCommand <- runMaybeT $ customCommandByName name let builtinCommand = M.lookup name builtinCommands case (customCommand, builtinCommand) of diff --git a/src/Bot/CustomCommandType.hs b/src/Bot/CustomCommandType.hs new file mode 100644 index 0000000..b20efbb --- /dev/null +++ b/src/Bot/CustomCommandType.hs @@ -0,0 +1,34 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +-- | Moved out of CustomCommand to break dependency cycle: +-- Help depends on this type, but custom commands needs +-- to refresh Help and therefore also this type. +module Bot.CustomCommandType + (CustomCommand(..) + ) where + +import qualified Data.Map as M +import Data.Maybe +import qualified Data.Text as T +import Entity +import Property + +data CustomCommand = CustomCommand + { customCommandName :: T.Text + , customCommandMessage :: T.Text + , customCommandTimes :: Int + } + +instance IsEntity CustomCommand where + nameOfEntity _ = "CustomCommand" + toProperties customCommand = + M.fromList + [ ("name", PropertyText $ customCommandName customCommand) + , ("message", PropertyText $ customCommandMessage customCommand) + , ("times", PropertyInt $ customCommandTimes customCommand) + ] + fromProperties properties = + CustomCommand <$> extractProperty "name" properties <*> + extractProperty "message" properties <*> + pure (fromMaybe 0 $ extractProperty "times" properties) diff --git a/src/Bot/Help.hs b/src/Bot/Help.hs index 36ab08b..1a54bfb 100644 --- a/src/Bot/Help.hs +++ b/src/Bot/Help.hs @@ -8,7 +8,7 @@ module Bot.Help , startRefreshHelpGistTimer ) where -import Bot.CustomCommand +import Bot.CustomCommandType import Bot.GitHub import Bot.Replies import Command From c0a7787658e86e3e2353a3f1bf89b360b37a39ad Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Sun, 19 Jan 2020 18:33:20 +0100 Subject: [PATCH 2/6] Fix hlint issues --- src/Bot/CustomCommand.hs | 71 ++++++++++++++++++------------------ src/Bot/CustomCommandType.hs | 15 ++++---- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index c10757f..35286c7 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Bot.CustomCommand ( addCustomCommand @@ -10,28 +10,28 @@ module Bot.CustomCommand , timesCustomCommand ) where -import Bot.CustomCommandType -import Bot.Expr -import Bot.Flip -import Bot.Help -import Bot.Replies -import Command -import Control.Monad -import Control.Monad.Trans.Maybe -import Data.Functor.Compose -import qualified Data.Map as M -import Data.Maybe -import Data.Proxy -import qualified Data.Text as T -import Data.Time -import Effect -import Entity -import HyperNerd.Parser -import qualified Network.URI.Encode as URI -import Property -import Reaction -import Text.InterpolatedString.QM -import Transport +import Bot.CustomCommandType +import Bot.Expr +import Bot.Flip +import Bot.Help +import Bot.Replies +import Command +import Control.Monad +import Control.Monad.Trans.Maybe +import Data.Functor.Compose +import qualified Data.Map as M +import Data.Maybe +import Data.Proxy +import qualified Data.Text as T +import Data.Time +import Effect +import Entity +import HyperNerd.Parser +import qualified Network.URI.Encode as URI +import Property +import Reaction +import Text.InterpolatedString.QM +import Transport customCommandByName :: T.Text -> MaybeT Effect (Entity CustomCommand) customCommandByName name = @@ -42,10 +42,8 @@ customCommandByName name = addCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) addCustomCommand builtinCommands = Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do - runReaction refreshHelpGistId mesg - customCommand <- runMaybeT $ customCommandByName name - let builtinCommand = M.lookup name builtinCommands - case (customCommand, builtinCommand) of + res <- refreshHelpAndUnpack builtinCommands (fst <$> mesg) + case res of (Just _, Nothing) -> replyToSender sender [qms|Command '{name}' already exists|] (Nothing, Just _) -> @@ -65,13 +63,18 @@ addCustomCommand builtinCommands = } replyToSender sender [qms|Added command '{name}'|] -deleteCustomCommand :: CommandTable -> Reaction Message T.Text -deleteCustomCommand builtinCommands = - Reaction $ \mesg@Message {messageSender = sender, messageContent = name} -> do +refreshHelpAndUnpack :: CommandTable -> Message T.Text -> Effect (Maybe (Entity CustomCommand), Maybe BuiltinCommand) +refreshHelpAndUnpack builtinCommands mesg @Message{messageContent = name} = do runReaction refreshHelpGistId mesg customCommand <- runMaybeT $ customCommandByName name let builtinCommand = M.lookup name builtinCommands - case (customCommand, builtinCommand) of + pure (customCommand, builtinCommand) + +deleteCustomCommand :: CommandTable -> Reaction Message T.Text +deleteCustomCommand builtinCommands = + Reaction $ \mesg@Message {messageSender = sender, messageContent = name} -> do + res <- refreshHelpAndUnpack builtinCommands mesg + case res of (Just _, Nothing) -> do void $ deleteEntities (Proxy :: Proxy CustomCommand) $ @@ -139,10 +142,8 @@ timesCustomCommand builtinCommands = updateCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) updateCustomCommand builtinCommands = Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do - runReaction refreshHelpGistId mesg - customCommand <- runMaybeT $ customCommandByName name - let builtinCommand = M.lookup name builtinCommands - case (customCommand, builtinCommand) of + res <- refreshHelpAndUnpack builtinCommands (fst <$> mesg) + case res of (Just cmd, Nothing) -> do void $ updateEntityById (replaceCustomCommandMessage message <$> cmd) replyToSender sender [qms|Command '{name}' has been updated|] diff --git a/src/Bot/CustomCommandType.hs b/src/Bot/CustomCommandType.hs index b20efbb..916bde3 100644 --- a/src/Bot/CustomCommandType.hs +++ b/src/Bot/CustomCommandType.hs @@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} -- | Moved out of CustomCommand to break dependency cycle: -- Help depends on this type, but custom commands needs @@ -8,16 +7,16 @@ module Bot.CustomCommandType (CustomCommand(..) ) where -import qualified Data.Map as M -import Data.Maybe -import qualified Data.Text as T -import Entity -import Property +import qualified Data.Map as M +import Data.Maybe +import qualified Data.Text as T +import Entity +import Property data CustomCommand = CustomCommand - { customCommandName :: T.Text + { customCommandName :: T.Text , customCommandMessage :: T.Text - , customCommandTimes :: Int + , customCommandTimes :: Int } instance IsEntity CustomCommand where From 446b8a7327699a1b6232b1be7932b3e381ae2259 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Sun, 19 Jan 2020 19:20:01 +0100 Subject: [PATCH 3/6] Run hidindent on files --- src/Bot/CustomCommand.hs | 69 ++++++++++++++++++++---------------- src/Bot/CustomCommandType.hs | 23 ++++++------ 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/Bot/CustomCommand.hs b/src/Bot/CustomCommand.hs index 35286c7..b0fbcf9 100644 --- a/src/Bot/CustomCommand.hs +++ b/src/Bot/CustomCommand.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Bot.CustomCommand ( addCustomCommand @@ -10,28 +10,28 @@ module Bot.CustomCommand , timesCustomCommand ) where -import Bot.CustomCommandType -import Bot.Expr -import Bot.Flip -import Bot.Help -import Bot.Replies -import Command -import Control.Monad -import Control.Monad.Trans.Maybe -import Data.Functor.Compose -import qualified Data.Map as M -import Data.Maybe -import Data.Proxy -import qualified Data.Text as T -import Data.Time -import Effect -import Entity -import HyperNerd.Parser -import qualified Network.URI.Encode as URI -import Property -import Reaction -import Text.InterpolatedString.QM -import Transport +import Bot.CustomCommandType +import Bot.Expr +import Bot.Flip +import Bot.Help +import Bot.Replies +import Command +import Control.Monad +import Control.Monad.Trans.Maybe +import Data.Functor.Compose +import qualified Data.Map as M +import Data.Maybe +import Data.Proxy +import qualified Data.Text as T +import Data.Time +import Effect +import Entity +import HyperNerd.Parser +import qualified Network.URI.Encode as URI +import Property +import Reaction +import Text.InterpolatedString.QM +import Transport customCommandByName :: T.Text -> MaybeT Effect (Entity CustomCommand) customCommandByName name = @@ -41,7 +41,9 @@ customCommandByName name = addCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) addCustomCommand builtinCommands = - Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do + Reaction $ \mesg@Message { messageSender = sender + , messageContent = (name, message) + } -> do res <- refreshHelpAndUnpack builtinCommands (fst <$> mesg) case res of (Just _, Nothing) -> @@ -63,12 +65,15 @@ addCustomCommand builtinCommands = } replyToSender sender [qms|Added command '{name}'|] -refreshHelpAndUnpack :: CommandTable -> Message T.Text -> Effect (Maybe (Entity CustomCommand), Maybe BuiltinCommand) -refreshHelpAndUnpack builtinCommands mesg @Message{messageContent = name} = do - runReaction refreshHelpGistId mesg - customCommand <- runMaybeT $ customCommandByName name - let builtinCommand = M.lookup name builtinCommands - pure (customCommand, builtinCommand) +refreshHelpAndUnpack :: + CommandTable + -> Message T.Text + -> Effect (Maybe (Entity CustomCommand), Maybe BuiltinCommand) +refreshHelpAndUnpack builtinCommands mesg@Message {messageContent = name} = do + runReaction refreshHelpGistId mesg + customCommand <- runMaybeT $ customCommandByName name + let builtinCommand = M.lookup name builtinCommands + pure (customCommand, builtinCommand) deleteCustomCommand :: CommandTable -> Reaction Message T.Text deleteCustomCommand builtinCommands = @@ -141,7 +146,9 @@ timesCustomCommand builtinCommands = updateCustomCommand :: CommandTable -> Reaction Message (T.Text, T.Text) updateCustomCommand builtinCommands = - Reaction $ \mesg@Message {messageSender = sender, messageContent = (name, message)} -> do + Reaction $ \mesg@Message { messageSender = sender + , messageContent = (name, message) + } -> do res <- refreshHelpAndUnpack builtinCommands (fst <$> mesg) case res of (Just cmd, Nothing) -> do diff --git a/src/Bot/CustomCommandType.hs b/src/Bot/CustomCommandType.hs index 916bde3..d7720a9 100644 --- a/src/Bot/CustomCommandType.hs +++ b/src/Bot/CustomCommandType.hs @@ -4,20 +4,21 @@ -- Help depends on this type, but custom commands needs -- to refresh Help and therefore also this type. module Bot.CustomCommandType - (CustomCommand(..) + ( CustomCommand(..) ) where -import qualified Data.Map as M -import Data.Maybe -import qualified Data.Text as T -import Entity -import Property +import qualified Data.Map as M +import Data.Maybe +import qualified Data.Text as T +import Entity +import Property -data CustomCommand = CustomCommand - { customCommandName :: T.Text - , customCommandMessage :: T.Text - , customCommandTimes :: Int - } +data CustomCommand = + CustomCommand + { customCommandName :: T.Text + , customCommandMessage :: T.Text + , customCommandTimes :: Int + } instance IsEntity CustomCommand where nameOfEntity _ = "CustomCommand" From 6758ab14b06e81e61c4313bb692b11d3b3f283df Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Sun, 19 Jan 2020 19:20:18 +0100 Subject: [PATCH 4/6] Fix hlint issues in random files --- src/Bot/Poll.hs | 61 ++++++++++++++++++------------------ src/Schedule.hs | 83 ++++++++++++++++++++++++------------------------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Bot/Poll.hs b/src/Bot/Poll.hs index 568b2a0..67b7211 100644 --- a/src/Bot/Poll.hs +++ b/src/Bot/Poll.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Bot.Poll ( cancelPollCommand @@ -11,46 +11,47 @@ module Bot.Poll , announceRunningPoll ) where -import Bot.Log (LogRecord(..), Seconds, getRecentLogs) -import Bot.Replies -import Control.Monad -import Data.Bool.Extra -import Data.Foldable -import Data.Function -import Data.Functor.Compose -import Data.List -import qualified Data.Map as M -import Data.Maybe -import Data.Proxy -import qualified Data.Text as T -import Data.Time -import Effect -import Entity -import Property -import Reaction -import Safe -import Text.InterpolatedString.QM -import Text.Read -import Transport +import Bot.Log (LogRecord (..), Seconds, + getRecentLogs) +import Bot.Replies +import Control.Monad +import Data.Bool.Extra +import Data.Foldable +import Data.Function +import Data.Functor.Compose +import Data.List +import qualified Data.Map as M +import Data.Maybe +import Data.Proxy +import qualified Data.Text as T +import Data.Time +import Effect +import Entity +import Property +import Reaction +import Safe +import Text.InterpolatedString.QM +import Text.Read +import Transport data PollOption = PollOption { poPollId :: Int - , poName :: T.Text + , poName :: T.Text } data Poll = Poll - { pollAuthor :: T.Text + { pollAuthor :: T.Text , pollStartedAt :: UTCTime - , pollDuration :: Int + , pollDuration :: Int -- TODO(#299): Entity doesn't support boolean types , pollCancelled :: Bool - , pollChannel :: Maybe Channel + , pollChannel :: Maybe Channel } data Vote = Vote - { voteUser :: T.Text + { voteUser :: T.Text , voteOptionId :: Int - , votePoints :: Int + , votePoints :: Int } instance IsEntity Poll where @@ -118,7 +119,7 @@ rank = sortBy (flip compare `on` length) . group . sort where safeHead (x:_) = x - safeHead _ = error "Empty list" + safeHead _ = error "Empty list" -- TODO(#360): showRanks should format results exactly like announcePollResults to make Twitch emotes visible showRanks :: (Show a) => [(Int, a)] -> String @@ -204,7 +205,7 @@ currentPollCommand = currentPoll :: Effect (Maybe (Entity Poll)) currentPoll = do currentTime <- now - fmap (listToMaybe . filter (isPollAlive currentTime)) $ + fmap (find (isPollAlive currentTime)) $ selectEntities Proxy $ Take 1 $ SortBy "startedAt" Desc All startPoll :: Sender -> [T.Text] -> Int -> Effect Int diff --git a/src/Schedule.hs b/src/Schedule.hs index 3de88f7..4783ae0 100644 --- a/src/Schedule.hs +++ b/src/Schedule.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Schedule ( nextEvent @@ -8,24 +8,24 @@ module Schedule , Schedule(..) ) where -import Control.Monad -import Data.Aeson -import Data.Aeson.Types -import Data.Either.Extra -import Data.Function -import Data.List -import qualified Data.Map as M -import Data.Maybe -import Data.Maybe.Extra -import Data.Monoid -import qualified Data.Text as T -import Data.Time -import Data.Time.Calendar.WeekDate -import Data.Time.Clock.POSIX -import Data.Time.Extra -import Data.Time.LocalTime (TimeZone) -import Safe -import Text.InterpolatedString.QM +import Control.Monad +import Data.Aeson +import Data.Aeson.Types +import Data.Either.Extra +import Data.Function +import Data.List +import qualified Data.Map as M +import Data.Maybe +import Data.Maybe.Extra +import Data.Monoid +import qualified Data.Text as T +import Data.Time +import Data.Time.Calendar.WeekDate +import Data.Time.Clock.POSIX +import Data.Time.Extra +import Data.Time.LocalTime (TimeZone) +import Safe +import Text.InterpolatedString.QM data DayOfWeek = Monday @@ -51,23 +51,23 @@ newtype ScheduleTimeZone = deriving (Show) data Project = Project - { projectName :: T.Text + { projectName :: T.Text , projectDescription :: T.Text - , projectUrl :: T.Text - , projectDays :: [DayOfWeek] - , projectTime :: TimeOfDay - , projectChannel :: T.Text - , projectStarts :: Maybe Day - , projectEnds :: Maybe Day + , projectUrl :: T.Text + , projectDays :: [DayOfWeek] + , projectTime :: TimeOfDay + , projectChannel :: T.Text + , projectStarts :: Maybe Day + , projectEnds :: Maybe Day } deriving (Show) data Event = Event - { eventDate :: Day - , eventTime :: TimeOfDay - , eventTitle :: T.Text + { eventDate :: Day + , eventTime :: TimeOfDay + , eventTitle :: T.Text , eventDescription :: T.Text - , eventUrl :: T.Text - , eventChannel :: T.Text + , eventUrl :: T.Text + , eventChannel :: T.Text } deriving (Show) eventId :: ScheduleTimeZone -> Event -> EventId @@ -99,18 +99,18 @@ newtype EventId = deriving (Eq, Ord, Show) data EventPatch = EventPatch - { eventPatchTitle :: Maybe T.Text + { eventPatchTitle :: Maybe T.Text , eventPatchDescription :: Maybe T.Text - , eventPatchUrl :: Maybe T.Text - , eventPatchChannel :: Maybe T.Text + , eventPatchUrl :: Maybe T.Text + , eventPatchChannel :: Maybe T.Text } deriving (Show) data Schedule = Schedule - { scheduleProject :: [Project] - , scheduleExtraEvents :: [Event] + { scheduleProject :: [Project] + , scheduleExtraEvents :: [Event] , scheduleCancelledEvents :: [EventId] - , scheduleTimezone :: ScheduleTimeZone - , schedulePatches :: M.Map EventId EventPatch + , scheduleTimezone :: ScheduleTimeZone + , schedulePatches :: M.Map EventId EventPatch } deriving (Show) instance FromJSON Schedule where @@ -147,11 +147,11 @@ instance FromJSONKey EventId where parseTimeZone :: T.Text -> Parser TimeZone parseTimeZone "Asia/Novosibirsk" = return $ minutesToTimeZone 420 -parseTimeZone s = fail ("Unknown timezone: " ++ T.unpack s) +parseTimeZone s = fail ("Unknown timezone: " ++ T.unpack s) instance FromJSON ScheduleTimeZone where parseJSON (String s) = ScheduleTimeZone <$> parseTimeZone s - parseJSON invalid = typeMismatch "ScheduleTimeZone" invalid + parseJSON invalid = typeMismatch "ScheduleTimeZone" invalid instance FromJSON EventPatch where parseJSON (Object v) = @@ -230,6 +230,5 @@ eventsFrom day schedule@Schedule { scheduleTimezone = timezone nextEvent :: Schedule -> UTCTime -> Either String Event nextEvent schedule timePoint = maybeToEither "No events found" $ - listToMaybe $ - filter ((> timePoint) . eventUTCTime (scheduleTimezone schedule)) $ + find ((> timePoint) . eventUTCTime (scheduleTimezone schedule)) $ eventsFrom (utctDay timePoint) schedule From dec63955bd0acb06201da2ac1566b76399723eb7 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Sun, 19 Jan 2020 19:31:58 +0100 Subject: [PATCH 5/6] Format the files --- src/Bot/Poll.hs | 82 +++++++++++++++++----------------- src/Schedule.hs | 116 ++++++++++++++++++++++++++---------------------- 2 files changed, 104 insertions(+), 94 deletions(-) diff --git a/src/Bot/Poll.hs b/src/Bot/Poll.hs index 67b7211..1711899 100644 --- a/src/Bot/Poll.hs +++ b/src/Bot/Poll.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Bot.Poll ( cancelPollCommand @@ -11,48 +11,50 @@ module Bot.Poll , announceRunningPoll ) where -import Bot.Log (LogRecord (..), Seconds, - getRecentLogs) -import Bot.Replies -import Control.Monad -import Data.Bool.Extra -import Data.Foldable -import Data.Function -import Data.Functor.Compose -import Data.List -import qualified Data.Map as M -import Data.Maybe -import Data.Proxy -import qualified Data.Text as T -import Data.Time -import Effect -import Entity -import Property -import Reaction -import Safe -import Text.InterpolatedString.QM -import Text.Read -import Transport +import Bot.Log (LogRecord(..), Seconds, getRecentLogs) +import Bot.Replies +import Control.Monad +import Data.Bool.Extra +import Data.Foldable +import Data.Function +import Data.Functor.Compose +import Data.List +import qualified Data.Map as M +import Data.Maybe +import Data.Proxy +import qualified Data.Text as T +import Data.Time +import Effect +import Entity +import Property +import Reaction +import Safe +import Text.InterpolatedString.QM +import Text.Read +import Transport -data PollOption = PollOption - { poPollId :: Int - , poName :: T.Text - } +data PollOption = + PollOption + { poPollId :: Int + , poName :: T.Text + } -data Poll = Poll - { pollAuthor :: T.Text - , pollStartedAt :: UTCTime - , pollDuration :: Int +data Poll = + Poll + { pollAuthor :: T.Text + , pollStartedAt :: UTCTime + , pollDuration :: Int -- TODO(#299): Entity doesn't support boolean types - , pollCancelled :: Bool - , pollChannel :: Maybe Channel - } + , pollCancelled :: Bool + , pollChannel :: Maybe Channel + } -data Vote = Vote - { voteUser :: T.Text - , voteOptionId :: Int - , votePoints :: Int - } +data Vote = + Vote + { voteUser :: T.Text + , voteOptionId :: Int + , votePoints :: Int + } instance IsEntity Poll where nameOfEntity _ = "Poll" @@ -119,7 +121,7 @@ rank = sortBy (flip compare `on` length) . group . sort where safeHead (x:_) = x - safeHead _ = error "Empty list" + safeHead _ = error "Empty list" -- TODO(#360): showRanks should format results exactly like announcePollResults to make Twitch emotes visible showRanks :: (Show a) => [(Int, a)] -> String diff --git a/src/Schedule.hs b/src/Schedule.hs index 4783ae0..649816b 100644 --- a/src/Schedule.hs +++ b/src/Schedule.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE QuasiQuotes #-} module Schedule ( nextEvent @@ -8,24 +8,24 @@ module Schedule , Schedule(..) ) where -import Control.Monad -import Data.Aeson -import Data.Aeson.Types -import Data.Either.Extra -import Data.Function -import Data.List -import qualified Data.Map as M -import Data.Maybe -import Data.Maybe.Extra -import Data.Monoid -import qualified Data.Text as T -import Data.Time -import Data.Time.Calendar.WeekDate -import Data.Time.Clock.POSIX -import Data.Time.Extra -import Data.Time.LocalTime (TimeZone) -import Safe -import Text.InterpolatedString.QM +import Control.Monad +import Data.Aeson +import Data.Aeson.Types +import Data.Either.Extra +import Data.Function +import Data.List +import qualified Data.Map as M +import Data.Maybe +import Data.Maybe.Extra +import Data.Monoid +import qualified Data.Text as T +import Data.Time +import Data.Time.Calendar.WeekDate +import Data.Time.Clock.POSIX +import Data.Time.Extra +import Data.Time.LocalTime (TimeZone) +import Safe +import Text.InterpolatedString.QM data DayOfWeek = Monday @@ -50,25 +50,29 @@ newtype ScheduleTimeZone = ScheduleTimeZone TimeZone deriving (Show) -data Project = Project - { projectName :: T.Text - , projectDescription :: T.Text - , projectUrl :: T.Text - , projectDays :: [DayOfWeek] - , projectTime :: TimeOfDay - , projectChannel :: T.Text - , projectStarts :: Maybe Day - , projectEnds :: Maybe Day - } deriving (Show) - -data Event = Event - { eventDate :: Day - , eventTime :: TimeOfDay - , eventTitle :: T.Text - , eventDescription :: T.Text - , eventUrl :: T.Text - , eventChannel :: T.Text - } deriving (Show) +data Project = + Project + { projectName :: T.Text + , projectDescription :: T.Text + , projectUrl :: T.Text + , projectDays :: [DayOfWeek] + , projectTime :: TimeOfDay + , projectChannel :: T.Text + , projectStarts :: Maybe Day + , projectEnds :: Maybe Day + } + deriving (Show) + +data Event = + Event + { eventDate :: Day + , eventTime :: TimeOfDay + , eventTitle :: T.Text + , eventDescription :: T.Text + , eventUrl :: T.Text + , eventChannel :: T.Text + } + deriving (Show) eventId :: ScheduleTimeZone -> Event -> EventId eventId timeZone event = @@ -98,20 +102,24 @@ newtype EventId = EventId Int deriving (Eq, Ord, Show) -data EventPatch = EventPatch - { eventPatchTitle :: Maybe T.Text - , eventPatchDescription :: Maybe T.Text - , eventPatchUrl :: Maybe T.Text - , eventPatchChannel :: Maybe T.Text - } deriving (Show) - -data Schedule = Schedule - { scheduleProject :: [Project] - , scheduleExtraEvents :: [Event] - , scheduleCancelledEvents :: [EventId] - , scheduleTimezone :: ScheduleTimeZone - , schedulePatches :: M.Map EventId EventPatch - } deriving (Show) +data EventPatch = + EventPatch + { eventPatchTitle :: Maybe T.Text + , eventPatchDescription :: Maybe T.Text + , eventPatchUrl :: Maybe T.Text + , eventPatchChannel :: Maybe T.Text + } + deriving (Show) + +data Schedule = + Schedule + { scheduleProject :: [Project] + , scheduleExtraEvents :: [Event] + , scheduleCancelledEvents :: [EventId] + , scheduleTimezone :: ScheduleTimeZone + , schedulePatches :: M.Map EventId EventPatch + } + deriving (Show) instance FromJSON Schedule where parseJSON (Object v) = @@ -147,11 +155,11 @@ instance FromJSONKey EventId where parseTimeZone :: T.Text -> Parser TimeZone parseTimeZone "Asia/Novosibirsk" = return $ minutesToTimeZone 420 -parseTimeZone s = fail ("Unknown timezone: " ++ T.unpack s) +parseTimeZone s = fail ("Unknown timezone: " ++ T.unpack s) instance FromJSON ScheduleTimeZone where parseJSON (String s) = ScheduleTimeZone <$> parseTimeZone s - parseJSON invalid = typeMismatch "ScheduleTimeZone" invalid + parseJSON invalid = typeMismatch "ScheduleTimeZone" invalid instance FromJSON EventPatch where parseJSON (Object v) = From 34f2a86945d8b6aac6fce095dd48a7ec2534ab74 Mon Sep 17 00:00:00 2001 From: Jappie Klooster Date: Sun, 19 Jan 2020 20:13:57 +0100 Subject: [PATCH 6/6] Apply formatting --- src/Bot/CustomCommandType.hs | 11 +++--- src/Bot/Poll.hs | 35 ++++++++--------- src/Schedule.hs | 74 ++++++++++++++++-------------------- 3 files changed, 54 insertions(+), 66 deletions(-) diff --git a/src/Bot/CustomCommandType.hs b/src/Bot/CustomCommandType.hs index d7720a9..ab9f540 100644 --- a/src/Bot/CustomCommandType.hs +++ b/src/Bot/CustomCommandType.hs @@ -13,12 +13,11 @@ import qualified Data.Text as T import Entity import Property -data CustomCommand = - CustomCommand - { customCommandName :: T.Text - , customCommandMessage :: T.Text - , customCommandTimes :: Int - } +data CustomCommand = CustomCommand + { customCommandName :: T.Text + , customCommandMessage :: T.Text + , customCommandTimes :: Int + } instance IsEntity CustomCommand where nameOfEntity _ = "CustomCommand" diff --git a/src/Bot/Poll.hs b/src/Bot/Poll.hs index 1711899..36819bf 100644 --- a/src/Bot/Poll.hs +++ b/src/Bot/Poll.hs @@ -33,28 +33,25 @@ import Text.InterpolatedString.QM import Text.Read import Transport -data PollOption = - PollOption - { poPollId :: Int - , poName :: T.Text - } +data PollOption = PollOption + { poPollId :: Int + , poName :: T.Text + } -data Poll = - Poll - { pollAuthor :: T.Text - , pollStartedAt :: UTCTime - , pollDuration :: Int +data Poll = Poll + { pollAuthor :: T.Text + , pollStartedAt :: UTCTime + , pollDuration :: Int -- TODO(#299): Entity doesn't support boolean types - , pollCancelled :: Bool - , pollChannel :: Maybe Channel - } + , pollCancelled :: Bool + , pollChannel :: Maybe Channel + } -data Vote = - Vote - { voteUser :: T.Text - , voteOptionId :: Int - , votePoints :: Int - } +data Vote = Vote + { voteUser :: T.Text + , voteOptionId :: Int + , votePoints :: Int + } instance IsEntity Poll where nameOfEntity _ = "Poll" diff --git a/src/Schedule.hs b/src/Schedule.hs index 649816b..905e0eb 100644 --- a/src/Schedule.hs +++ b/src/Schedule.hs @@ -50,29 +50,25 @@ newtype ScheduleTimeZone = ScheduleTimeZone TimeZone deriving (Show) -data Project = - Project - { projectName :: T.Text - , projectDescription :: T.Text - , projectUrl :: T.Text - , projectDays :: [DayOfWeek] - , projectTime :: TimeOfDay - , projectChannel :: T.Text - , projectStarts :: Maybe Day - , projectEnds :: Maybe Day - } - deriving (Show) - -data Event = - Event - { eventDate :: Day - , eventTime :: TimeOfDay - , eventTitle :: T.Text - , eventDescription :: T.Text - , eventUrl :: T.Text - , eventChannel :: T.Text - } - deriving (Show) +data Project = Project + { projectName :: T.Text + , projectDescription :: T.Text + , projectUrl :: T.Text + , projectDays :: [DayOfWeek] + , projectTime :: TimeOfDay + , projectChannel :: T.Text + , projectStarts :: Maybe Day + , projectEnds :: Maybe Day + } deriving (Show) + +data Event = Event + { eventDate :: Day + , eventTime :: TimeOfDay + , eventTitle :: T.Text + , eventDescription :: T.Text + , eventUrl :: T.Text + , eventChannel :: T.Text + } deriving (Show) eventId :: ScheduleTimeZone -> Event -> EventId eventId timeZone event = @@ -102,24 +98,20 @@ newtype EventId = EventId Int deriving (Eq, Ord, Show) -data EventPatch = - EventPatch - { eventPatchTitle :: Maybe T.Text - , eventPatchDescription :: Maybe T.Text - , eventPatchUrl :: Maybe T.Text - , eventPatchChannel :: Maybe T.Text - } - deriving (Show) - -data Schedule = - Schedule - { scheduleProject :: [Project] - , scheduleExtraEvents :: [Event] - , scheduleCancelledEvents :: [EventId] - , scheduleTimezone :: ScheduleTimeZone - , schedulePatches :: M.Map EventId EventPatch - } - deriving (Show) +data EventPatch = EventPatch + { eventPatchTitle :: Maybe T.Text + , eventPatchDescription :: Maybe T.Text + , eventPatchUrl :: Maybe T.Text + , eventPatchChannel :: Maybe T.Text + } deriving (Show) + +data Schedule = Schedule + { scheduleProject :: [Project] + , scheduleExtraEvents :: [Event] + , scheduleCancelledEvents :: [EventId] + , scheduleTimezone :: ScheduleTimeZone + , schedulePatches :: M.Map EventId EventPatch + } deriving (Show) instance FromJSON Schedule where parseJSON (Object v) =