diff options
| author | Teddy Wing | 2017-09-14 03:44:38 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-09-14 03:44:38 +0200 | 
| commit | ea190de02cea99347ae125d86cc22bf8cd926c88 (patch) | |
| tree | 2c5756af9a7fe86128f12117f5948282d0be4103 /src/Plugin | |
| parent | cd366dc004b82f0ea937da231cbc1c9abfdca934 (diff) | |
| download | sorbot-ea190de02cea99347ae125d86cc22bf8cd926c88.tar.bz2 | |
Add `Bot` to rest of plugins
Add our `Bot` monad to the rest of the plugins:
* Factorial
* GitRemoteSetOrigin
* Help
The only problem is with the Help plugin. Still trying to figure out how
to set up my list comprehension so that it works with the `Bot`-wrapped
`Plugin` list.
Diffstat (limited to 'src/Plugin')
| -rw-r--r-- | src/Plugin/Factorial.hs | 20 | ||||
| -rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 7 | ||||
| -rw-r--r-- | src/Plugin/Help.hs | 32 | 
3 files changed, 37 insertions, 22 deletions
| diff --git a/src/Plugin/Factorial.hs b/src/Plugin/Factorial.hs index 9284fe7..9d7a169 100644 --- a/src/Plugin/Factorial.hs +++ b/src/Plugin/Factorial.hs @@ -7,20 +7,24 @@ module Plugin.Factorial  import Text.Regex.TDFA ((=~))  import TextShow (showt) +import Bot (Bot)  import qualified Message as M  import Plugin.Base -factorial = defaultPlugin -    { matchRegex  = "^([0-9]+)!$" -    , perform     = factorialAction -    , command     = "<integer>!" -    , description = "Calculate the factorial of <integer> for whole numbers \ -        \up to 35000." -    } +factorial :: Bot Plugin +factorial = do +    return defaultPlugin +        { matchRegex  = "^([0-9]+)!$" +        , perform     = factorialAction +        , command     = "<integer>!" +        , description = "Calculate the factorial of <integer> for whole numbers \ +            \up to 35000." +        }  factorialAction :: PluginAction  factorialAction message = do -    case M.textStr message =~ matchRegex factorial :: [[String]] of +    plugin <- factorial +    case M.textStr message =~ matchRegex plugin :: [[String]] of          []    -> return $ Left "I didn't understand"          (m:_) -> do              let number = last m diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs index 0fdb4ef..7d46e46 100644 --- a/src/Plugin/GitRemoteSetOrigin.hs +++ b/src/Plugin/GitRemoteSetOrigin.hs @@ -10,10 +10,12 @@ import qualified Data.Text as T  import Database.SQLite.Simple  import Text.Regex.TDFA ((=~)) +import Bot (Bot)  import qualified Message as M  import Plugin.Base -gitRemoteSetOrigin = defaultPlugin +gitRemoteSetOrigin :: Bot Plugin +gitRemoteSetOrigin = return defaultPlugin      { matchRegex  = "^git remote set origin ([^ ]+)$"      , perform     = gitRemoteSetOriginAction      , command     = "git remote set origin <url>" @@ -22,7 +24,8 @@ gitRemoteSetOrigin = defaultPlugin  gitRemoteSetOriginAction :: PluginAction  gitRemoteSetOriginAction message = do -    case M.textStr message =~ matchRegex gitRemoteSetOrigin :: [[String]] of +    plugin <- gitRemoteSetOrigin +    case M.textStr message =~ matchRegex plugin :: [[String]] of          []    -> return $ Left "blast"          (m:_) -> do              let url = last m diff --git a/src/Plugin/Help.hs b/src/Plugin/Help.hs index 63143b1..b29d1b9 100644 --- a/src/Plugin/Help.hs +++ b/src/Plugin/Help.hs @@ -4,28 +4,36 @@ module Plugin.Help      ( help      ) where +import Control.Monad (sequence)  import qualified Data.Text as T +import Bot (Bot)  import qualified PluginList as PL (plugins)  import Plugin.Base -help = defaultPlugin -    { matchRegex  = "^help$" -    , perform     = helpAction -    , command     = "help" -    , description = "Show a list of available bot commands." -    , queryOnly   = True -    } +help :: Bot Plugin +help = do +    return defaultPlugin +        { matchRegex  = "^help$" +        , perform     = helpAction +        , command     = "help" +        , description = "Show a list of available bot commands." +        , queryOnly   = True +        }  helpAction :: PluginAction  helpAction _ = do      return $ Right $ T.intercalate "\n" -        [T.justifyRight longestCommandLen ' ' (command p) -            `T.append` " – " -            `T.append` description p -        | p <- plugins] +        -- [T.justifyRight longestCommandLen ' ' (command p) +        --     `T.append` " – " +        --     `T.append` description p +        -- | p <- plugins']    where      longestCommandLen = foldr (max) 0 (map (T.length . command) plugins) -plugins :: [Plugin] +    helpText plugin = T.justifyRight longestCommandLen ' ' (command plugin) +        `T.append` " – " +        `T.append` description plugin + +plugins :: [Bot Plugin]  plugins = PL.plugins ++ [help] | 
