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"
This commit is contained in:
Joscha 2018-02-25 21:44:06 +00:00
parent f7b012259c
commit ca3abbd93d
2 changed files with 11 additions and 6 deletions

View file

@ -81,6 +81,7 @@ module EuphApi.Bot (
, restart , restart
, send , send
, reply , reply
, replyTo
, nick , nick
, getMessage , getMessage
, messageLog , messageLog
@ -397,12 +398,16 @@ send content = do
con <- asks bConnection con <- asks bConnection
liftIO $ E.send con Nothing content 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 :: E.Snowflake -> T.Text -> Bot b c E.Message
reply parentID content = do reply parentID content = do
con <- asks bConnection con <- asks bConnection
liftIO $ E.send con (Just parentID) content 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. -- | Change the bot's nick.
nick :: T.Text -> Bot b c (T.Text, T.Text) nick :: T.Text -> Bot b c (T.Text, T.Text)
nick newNick = do nick newNick = do

View file

@ -34,14 +34,14 @@ import qualified EuphApi.Utils.Misc as E
-- Bots __should implement__ this command. -- Bots __should implement__ this command.
pingCommand :: T.Text -> E.Command b c pingCommand :: T.Text -> E.Command b c
pingCommand pingText = E.specificCommand "ping" $ \msg -> pingCommand pingText = E.specificCommand "ping" $ \msg ->
void $ E.reply (E.msgID msg) pingText void $ E.replyTo msg pingText
-- | General version of 'pingCommand': @!ping@ -- | General version of 'pingCommand': @!ping@
-- --
-- Bots __should implement__ this command. -- Bots __should implement__ this command.
generalPingCommand :: T.Text -> E.Command b c generalPingCommand :: T.Text -> E.Command b c
generalPingCommand pingText = E.command "ping" $ \msg -> generalPingCommand pingText = E.command "ping" $ \msg ->
void $ E.reply (E.msgID msg) pingText void $ E.replyTo msg pingText
-- | Specific help command: @!help \@botname@ -- | 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 :: (T.Text -> T.Text) -> E.Command b c
helpCommand f = E.specificCommand "help" $ \msg -> do helpCommand f = E.specificCommand "help" $ \msg -> do
s <- E.sessName <$> E.getOwnView s <- E.sessName <$> E.getOwnView
void $ E.reply (E.msgID msg) (f s) void $ E.replyTo msg (f s)
-- | General version of 'helpCommand': @!help@ -- | 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 :: (T.Text -> T.Text) -> E.Command b c
generalHelpCommand f = E.command "help" $ \msg -> do generalHelpCommand f = E.command "help" $ \msg -> do
s <- E.sessName <$> E.getOwnView 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 :: E.Message -> E.Bot b c ()
uptime msg = do uptime msg = do
startTime <- E.getStartTime startTime <- E.getStartTime
curTime <- liftIO getCurrentTime 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@ -- | Specific uptime command: @!uptime \@botname@
-- --