lambdabot-telegram-plugins-0.2.0: Lambdabot for Telegram
Safe HaskellNone
LanguageHaskell2010

Lambdabot.Plugin.Telegram

Synopsis

Lambdabot state

lambdabotVersion :: String Source #

Lambdabot version from 'lambdabot-core' package.

telegramPlugins :: [String] Source #

Exported plugin(s).

telegramPlugin :: Module TelegramState Source #

Telegram plugin for Lambdabot. Here we redefined eval plugin to provide multiple sandboxes for different chats.

customHaskellPlugins :: [String] Source #

Eval excluded because we provide it by ourselves.

newTelegramState :: LB TelegramState Source #

Initialise TelegramState from Lambdabot config and with defaults. Current defaults are:

  • Input queue size: 1000000.
  • Output queue size: 1000000.

feed :: Text -> Text -> Text -> Telegram () Source #

Commands preprocessing. Commands started with >, ! would be replaced with (from Lambdabot config) + "run ". Resulted command would be passed to IRC system plugin.

handleMsg :: IrcMessage -> Telegram () Source #

Transcoding the response from IRC system plugin and sending message back to Telegram.

lockRC :: Telegram () Source #

Register telegram plugin in lambdabot core.

unlockRC :: Telegram () Source #

Unregister telegram plugin in lambdabot core.

Eval

Functions above came from eval plugin from lambdabot-haskell-plugins package. Instead of registering multiple "servers" for each Telegram chat and introducing new entities to manage multiple "servers", we decided to keep a single "server" and to modify "sandboxes". Sandbox is a basically single file "L.hs" that populated once IRC received "@let" command. For every chat used exactly the same file. It means that it was possible to share all definitions across different Telegram chats. To overcome these limitations we decided to create a separate file and associate it with a chat.

args :: String -> String -> [String] -> [String] -> [String] Source #

Concatenate all input into list of strings to pass to GHC:

args filesToLoad sourceExpressionToEvaluate ghcExtensions trustedPackages

isEval :: MonadLB m => String -> m Bool Source #

Determine whether command belongs to eval plugin or not.

dropPrefix :: String -> String Source #

Drop command prefix.

runGHC :: MonadLB m => String -> m String Source #

Represents "run" command. Actually run GHC. Response would be handled separately via callbacks.

define :: MonadLB m => String -> m String Source #

"define" command. Define a new binding. It would be stored in corresponding sandbox.

mergeModules :: Module -> Module -> Module Source #

Merge the second module _into_ the first - meaning where merging doesn't make sense, the field from the first will be used.

moduleProblems :: Module -> Maybe [Char] Source #

Import validations.

moveFile :: FilePath -> FilePath -> IO () Source #

Helper for sandboxes. Used to move temporary file.

customComp :: MonadLB m => ChatInfo -> Module -> m String Source #

Custom compilation of temporary files for binding. Used as part of "define" command.

resetCustomL_hs :: MonadLB m => ChatInfo -> m () Source #

Reset sandbox. Associated "L.hs" file would be reset to defaults.

findPristine_hs :: MonadLB m => m FilePath Source #

Find "Pristine.hs"; if not found, we try to install a compiler-specific version from lambdabot's data directory, and finally the default one.

findCustomL_hs :: MonadLB m => ChatInfo -> m FilePath Source #

Find associated with a chat "L.hs" file; if not found, we copy it from "Pristine.hs".

Since Lambdabot is passing String inside one plugin (see process for more details), Telegram chat information rendered as String and attached to every command to pass between commands and callbacks inside a plugin.

data ChatInfo Source #

ChatInfo represents an associated Telegram chat. Currently supports private and public chats.

Constructors

ChatInfo 

data ChatType Source #

ChatType represents whether chat is public or private.

Constructors

Public 
Private 

renderChatType :: ChatType -> String Source #

Since it's not possible to define module with "L-1000" name and private chats in Telegram are usually represented by negative digits, we simple encode it with a character.

readChatInfoFromSource :: String -> ChatInfo Source #

Read ChatInfo from command string.

dropChatInfoFromSource :: ChatInfo -> String -> String Source #

Drop ChatInfo from command string. Original command is returned.

getDotFilename :: ChatInfo -> String -> FilePath Source #

Generate temporary filename for given ChatInfo and file extension.

getLFilename :: ChatInfo -> FilePath Source #

Generate "L.hs" filename for given ChatInfo.

editModuleName :: ChatInfo -> String -> String Source #

Replace module L where with module L<chatId> where where <chatId> is a telegram chat ID.