diff --git a/haboli-infobot/src/Haboli/Bots/InfoBot.hs b/haboli-infobot/src/Haboli/Bots/InfoBot.hs index 26a66d2..5634c84 100644 --- a/haboli-infobot/src/Haboli/Bots/InfoBot.hs +++ b/haboli-infobot/src/Haboli/Bots/InfoBot.hs @@ -38,7 +38,7 @@ infoBot mPasswd = do botMain :: MVar BotState -> Client T.Text () botMain stateVar = forever $ do - event <- respondingToCommands (getCommands stateVar) $ + event <- respondingToCommand (getCommand stateVar) $ respondingToPing nextEvent updateFromEventVia botListing stateVar event updateNick stateVar @@ -61,11 +61,11 @@ longHelp = T.concat , "Source code available at https://github.com/Garmelon/haboli-bot-collection." ] -getCommands :: MVar BotState -> Client e [Command T.Text] -getCommands stateVar = do +getCommand :: MVar BotState -> Client e (Command T.Text) +getCommand stateVar = do state <- liftIO $ readMVar stateVar let name = state ^. botListing . lsSelfL . svNickL - pure + pure $ cmdSequential [ botrulezPingGeneral , botrulezPingSpecific name , botrulezPingSpecific "InfoBot" diff --git a/haboli-testbot/haboli-testbot.cabal b/haboli-testbot/haboli-testbot.cabal index 47778a5..579d733 100644 --- a/haboli-testbot/haboli-testbot.cabal +++ b/haboli-testbot/haboli-testbot.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: c59191837f2f234376576136c23122cdc5288703e37b782ee1908d225e22dcee +-- hash: d5c030fa8dd9717353e88856ef71c7e7c92cc984be5d40a99a071c221cf9c1e5 name: haboli-testbot version: 0.1.0.0 @@ -35,6 +35,7 @@ library base >=4.7 && <5 , containers , haboli + , megaparsec , microlens-platform , text , time @@ -52,6 +53,7 @@ executable haboli-testbot , containers , haboli , haboli-testbot + , megaparsec , microlens-platform , text , time diff --git a/haboli-testbot/package.yaml b/haboli-testbot/package.yaml index d3a76d6..87077fb 100644 --- a/haboli-testbot/package.yaml +++ b/haboli-testbot/package.yaml @@ -15,6 +15,7 @@ dependencies: - base >= 4.7 && < 5 - containers - haboli + - megaparsec - microlens-platform - text - time diff --git a/haboli-testbot/src/Haboli/Bots/TestBot.hs b/haboli-testbot/src/Haboli/Bots/TestBot.hs index 7211fdc..33ec2ac 100644 --- a/haboli-testbot/src/Haboli/Bots/TestBot.hs +++ b/haboli-testbot/src/Haboli/Bots/TestBot.hs @@ -8,12 +8,15 @@ module Haboli.Bots.TestBot import Control.Concurrent import Control.Monad import Control.Monad.IO.Class -import qualified Data.Text as T +import qualified Data.Text as T import Data.Time import Lens.Micro.Platform +import Text.Megaparsec +import Text.Megaparsec.Char import Haboli.Euphoria import Haboli.Euphoria.Botrulez +import Haboli.Euphoria.Command.Megaparsec data BotState = BotState { _botStartTime :: UTCTime @@ -35,7 +38,7 @@ testBot mPasswd = do botMain :: MVar BotState -> Client T.Text () botMain stateVar = forever $ do - event <- respondingToCommands (getCommands stateVar) $ + event <- respondingToCommand (getCommand stateVar) $ respondingToPing nextEvent updateFromEventVia botListing stateVar event @@ -49,14 +52,21 @@ longHelp = T.concat , "Source code available at https://github.com/Garmelon/haboli-bot-collection." ] -getCommands :: MVar BotState -> Client e [Command T.Text] -getCommands stateVar = do +getCommand :: MVar BotState -> Client e (Command T.Text) +getCommand stateVar = do state <- liftIO $ readMVar stateVar let name = state ^. botListing . lsSelfL . svNickL - pure + pure $ cmdSequential [ botrulezPingGeneral , botrulezPingSpecific name , botrulezHelpSpecific name longHelp , botrulezUptimeSpecific name $ state ^. botStartTime , botrulezKillSpecific name + , cmdEcho name ] + +cmdEcho :: T.Text -> Command e +cmdEcho name = cmdMega parser $ \msg text -> void $ reply msg text + where + parser :: Parsec () T.Text T.Text + parser = pNick name *> space1 *> pUntilEof diff --git a/stack.yaml b/stack.yaml index fcb4392..d4623f3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -6,4 +6,4 @@ packages: extra-deps: - github: Garmelon/haboli - commit: 86b6134c00d23b0e2e80208079a1975ac0c91f9a + commit: 46dc9242cf643b59a3f9f3b2cad3dfd538f44898 diff --git a/stack.yaml.lock b/stack.yaml.lock index 29aa7cf..80fb77d 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -5,19 +5,19 @@ packages: - completed: - size: 19510 - url: https://github.com/Garmelon/haboli/archive/86b6134c00d23b0e2e80208079a1975ac0c91f9a.tar.gz + size: 19868 + url: https://github.com/Garmelon/haboli/archive/46dc9242cf643b59a3f9f3b2cad3dfd538f44898.tar.gz cabal-file: size: 1576 sha256: d3dea9408d036abe5aa663343b63ffd39cb5fbf14d80773248dab42c607b69b6 name: haboli version: 0.3.1.0 - sha256: c137c08d5ccb6c55c6cd3f03b6d50cc073cb885050e4f5815242b11fb2da2307 + sha256: 86664c11fbea686271664f1e764985ee47c632497519e3d666198c5a258b17cc pantry-tree: size: 1193 - sha256: 7d7f3fe4fdd753fd6022c1c5f56b30333318130e40b53e0c202f3ea897ff6e79 + sha256: 69e998d628007ca4f8143e57b8c7c1342215653646d38a1bd2dd4356f50bfc0e original: - url: https://github.com/Garmelon/haboli/archive/86b6134c00d23b0e2e80208079a1975ac0c91f9a.tar.gz + url: https://github.com/Garmelon/haboli/archive/46dc9242cf643b59a3f9f3b2cad3dfd538f44898.tar.gz snapshots: - completed: size: 491389