Update to new yaboli version

[testbot] Add echo command that works like Sumairu's
This commit is contained in:
Joscha 2020-04-09 19:18:49 +00:00
parent 6c28d16a6e
commit b93f7f38ec
6 changed files with 29 additions and 16 deletions

View file

@ -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

View file

@ -15,6 +15,7 @@ dependencies:
- base >= 4.7 && < 5
- containers
- haboli
- megaparsec
- microlens-platform
- text
- time

View file

@ -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