Skip to content

Commit

Permalink
Merge pull request #7 from swamp-agr/free-plugin-commands
Browse files Browse the repository at this point in the history
Add `/free` command from `free` plugin
  • Loading branch information
swamp-agr committed Feb 19, 2022
2 parents c37ccaf + ff31d2a commit 032f5cc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Lambdabot/Plugin/Telegram/Bot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ type Model = TelegramState

data Action = SendEverything Msg | SendModule ModuleCmd | SendBack Msg

data ModuleCmd = EvalModule EvalCmd | CheckModule CheckCmd | DjinnModule DjinnCmd
data ModuleCmd
= EvalModule EvalCmd
| CheckModule CheckCmd
| DjinnModule DjinnCmd
| FreeModule FreeCmd

data EvalCmd = Let Msg | Undefine Msg | Run Msg
deriving (Generic, FromCommand)
Expand All @@ -36,6 +40,9 @@ data CheckCmd = Check Msg
data DjinnCmd = Djinn Msg | DjinnAdd Msg | DjinnDel Msg | DjinnEnv Msg | DjinnNames Msg | DjinnClr Msg | DjinnVer Msg
deriving (Generic, FromCommand)

data FreeCmd = Free Msg
deriving (Generic, FromCommand)

telegramLambdaBot :: TelegramState -> BotApp Model Action
telegramLambdaBot tgstate = BotApp
{ botInitialModel = tgstate
Expand Down Expand Up @@ -69,6 +76,8 @@ updateToAction _ update
= SendModule <$> (DjinnModule <$> (DjinnClr <$> updateToMsg update))
| isCommand "djinnver" update
= SendModule <$> (DjinnModule <$> (DjinnVer <$> updateToMsg update))
-- free commands
| isCommand "free" update = SendModule <$> (FreeModule <$> (Free <$> updateToMsg update))
| otherwise = Nothing
where
isCommand cmd = isJust . parseUpdate (Update.command cmd)
Expand All @@ -86,6 +95,7 @@ handleModuleAction :: ModuleCmd -> Model -> Eff Action Model
handleModuleAction (EvalModule cmd) model = handlePluginCommand cmd model
handleModuleAction (CheckModule cmd) model = handlePluginCommand cmd model
handleModuleAction (DjinnModule cmd) model = handlePluginCommand cmd model
handleModuleAction (FreeModule cmd) model = handlePluginCommand cmd model

handleAction :: Action -> Model -> Eff Action Model
handleAction (SendEverything msg) model = model <# do
Expand Down

0 comments on commit 032f5cc

Please sign in to comment.