Commit 57e5fb6c authored by Nicolas Lenz's avatar Nicolas Lenz

Update help message.

parent 0019d804
......@@ -8,7 +8,6 @@ import Control.Applicative
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Encoding as T
import Data.ByteArray (convert)
import Data.Char
import qualified Telegram.Bot.API as Telegram
import Telegram.Bot.Simple
......@@ -16,7 +15,6 @@ import Telegram.Bot.Simple.Debug
import Telegram.Bot.Simple.UpdateParser
import Telegram.Bot.API.InlineMode
import Control.Monad.Reader
import Crypto.Hash
import Mock (styles, mockRandom)
import Mock.Help (styleHelp)
......@@ -28,7 +26,7 @@ data Model = Model deriving (Show)
data Action
= NoAction -- ^ Perform no action.
| Reply Text -- ^ Reply some text.
| InlineReply [(Text, Text)]
| InlineReply [(Text, Text, Text)]
| SendHelp -- ^Send help text.
deriving (Show)
......@@ -50,7 +48,9 @@ mockify = UpdateParser f where
if length styleNames > 5 then
return $ Reply "Only concatenations of up to 5 styles are allowed."
else case concatMaybeFunctions . map (\s -> lookup s styles) $ styleNames of
Nothing -> return $ SendHelp
Nothing -> case Telegram.chatType (Telegram.messageChat message) of
Telegram.ChatTypePrivate -> return SendHelp
_ -> return NoAction
Just f -> return $ Reply $ f (T.unwords $ tail $ T.words txt)
replyToInline :: UpdateParser Action
......@@ -59,9 +59,10 @@ replyToInline = UpdateParser f where
f update = do
inlineQuery <- Telegram.updateInlineQuery update
let txt = Telegram.inlineQueryQuery inlineQuery
let id = Telegram.inlineQueryId inlineQuery
if T.empty == txt
then return $ InlineReply []
else return $ InlineReply $ map (\(name, f) -> (name, f txt)) styles
else return $ InlineReply $ map (\(name, f) -> (name, f txt, name <> id)) styles
-- |Concatenates a list of Maybe functions. Execution goes from left to right.
......@@ -85,16 +86,13 @@ handleAction (Reply message) model = model <# do
replyText message
pure NoAction
handleAction (InlineReply msgs) model = model <# do
let results = map (\(title, message) -> Telegram.InlineQueryResultArticle "article" (getInlineReplyId title message) title (Telegram.InputTextMessageContent message) message) msgs
let results = map (\(title, message, id) -> Telegram.InlineQueryResultArticle "article" id title (Telegram.InputTextMessageContent message) message) msgs
answerInlineQuery results
pure NoAction
handleAction SendHelp model = model <# do
reply $ (toReplyMessage help) {replyMessageParseMode = Just Telegram.Markdown, replyMessageDisableWebPagePreview = Just True}
pure NoAction
getInlineReplyId :: Text -> Text -> Text
getInlineReplyId title message = T.decodeUtf8 $ convert $ hashWith Keccak_512 $ T.encodeUtf8 $ title <> "\n" <> message
-- | Run bot with a given 'Telegram.Token'.
run :: Text -> IO ()
run token = do
......@@ -112,6 +110,8 @@ help = T.unlines [
"A Great BoT tO TRANsFoRM TEXt, wRiTten iN HaSKeLL.",
"By Nicolas Lenz. [Free and open source under the WTFPL.](https://git.eisfunke.com/software/mock-telegram-bot)",
"",
"*Inline usage:* Just type `@truemockbot` and the text you want to stylize in any chat. Telegram will show you a selection of the styles available.",
"",
"*Usage:* \\[STYLE] \\[TEXT]",
"*Example:* `random Cool Text`",
"",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment