Loading app/Main.hs +9 −9 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -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) Loading @@ -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 Loading @@ -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. Loading @@ -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 Loading @@ -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`", "", Loading Loading
app/Main.hs +9 −9 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -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) Loading @@ -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 Loading @@ -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. Loading @@ -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 Loading @@ -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`", "", Loading