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
, 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

View file

@ -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@
--