From ca3abbd93dbad2dc7556ed656f3364fc6bd4bf07 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 25 Feb 2018 21:44:06 +0000 Subject: [PATCH] Add replyTo for easier replying The old way: \msg -> E.reply (E.msgID msg) "some message" The new way: \msg -> E.replyTo msg "some message" --- src/EuphApi/Bot.hs | 7 ++++++- src/EuphApi/Utils/Botrulez.hs | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/EuphApi/Bot.hs b/src/EuphApi/Bot.hs index bf89fe1..0c257b2 100644 --- a/src/EuphApi/Bot.hs +++ b/src/EuphApi/Bot.hs @@ -81,6 +81,7 @@ module EuphApi.Bot ( , restart , send , reply + , replyTo , nick , getMessage , messageLog @@ -397,12 +398,16 @@ send content = do con <- asks bConnection liftIO $ E.send con Nothing content --- | Reply to a message. +-- | Reply to a message with a certain ID. reply :: E.Snowflake -> T.Text -> Bot b c E.Message reply parentID content = do con <- asks bConnection liftIO $ E.send con (Just parentID) content +-- | Reply to a message. +replyTo :: E.Message -> T.Text -> Bot b c E.Message +replyTo msg = reply (E.msgID msg) + -- | Change the bot's nick. nick :: T.Text -> Bot b c (T.Text, T.Text) nick newNick = do diff --git a/src/EuphApi/Utils/Botrulez.hs b/src/EuphApi/Utils/Botrulez.hs index 8f21cbd..a4560cb 100644 --- a/src/EuphApi/Utils/Botrulez.hs +++ b/src/EuphApi/Utils/Botrulez.hs @@ -34,14 +34,14 @@ import qualified EuphApi.Utils.Misc as E -- Bots __should implement__ this command. pingCommand :: T.Text -> E.Command b c pingCommand pingText = E.specificCommand "ping" $ \msg -> - void $ E.reply (E.msgID msg) pingText + void $ E.replyTo msg pingText -- | General version of 'pingCommand': @!ping@ -- -- Bots __should implement__ this command. generalPingCommand :: T.Text -> E.Command b c generalPingCommand pingText = E.command "ping" $ \msg -> - void $ E.reply (E.msgID msg) pingText + void $ E.replyTo msg pingText -- | Specific help command: @!help \@botname@ -- @@ -53,7 +53,7 @@ generalPingCommand pingText = E.command "ping" $ \msg -> helpCommand :: (T.Text -> T.Text) -> E.Command b c helpCommand f = E.specificCommand "help" $ \msg -> do s <- E.sessName <$> E.getOwnView - void $ E.reply (E.msgID msg) (f s) + void $ E.replyTo msg (f s) -- | General version of 'helpCommand': @!help@ -- @@ -65,13 +65,13 @@ helpCommand f = E.specificCommand "help" $ \msg -> do generalHelpCommand :: (T.Text -> T.Text) -> E.Command b c generalHelpCommand f = E.command "help" $ \msg -> do s <- E.sessName <$> E.getOwnView - void $ E.reply (E.msgID msg) (f s) + void $ E.replyTo msg (f s) uptime :: E.Message -> E.Bot b c () uptime msg = do startTime <- E.getStartTime curTime <- liftIO getCurrentTime - void $ E.reply (E.msgID msg) (T.pack $ E.printUptime startTime curTime) + void $ E.replyTo msg (T.pack $ E.printUptime startTime curTime) -- | Specific uptime command: @!uptime \@botname@ --