-- | Simple template module
-- Contains many constant bot commands.
module Lambdabot.Plugin.Misc.Dummy (dummyPlugin) where

import Lambdabot.Plugin
import Lambdabot.Plugin.Misc.Dummy.DocAssocs (docAssocs)
import Lambdabot.Util

import Data.Char
import qualified Data.ByteString.Char8 as P
import qualified Data.Map as M
import System.FilePath

dummyPlugin :: Module ()
dummyPlugin :: Module ()
dummyPlugin = forall st. Module st
newModule
    { moduleCmds :: ModuleT () LB [Command (ModuleT () LB)]
moduleCmds = forall (m :: * -> *) a. Monad m => a -> m a
return
        forall a b. (a -> b) -> a -> b
$ (String -> Command Identity
command String
"eval")
            { help :: Cmd (ModuleT () LB) ()
help = forall (m :: * -> *). Monad m => String -> Cmd m ()
say String
"eval. Do nothing (perversely)"
            , process :: String -> Cmd (ModuleT () LB) ()
process = forall a b. a -> b -> a
const (forall (m :: * -> *) a. Monad m => a -> m a
return ())
            }
        forall a. a -> [a] -> [a]
: (String -> Command Identity
command String
"choose")
            { help :: Cmd (ModuleT () LB) ()
help = forall (m :: * -> *). Monad m => String -> Cmd m ()
say String
"choose. Lambdabot featuring AI power"
            , process :: String -> Cmd (ModuleT () LB) ()
process = \String
args ->
                if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
args then forall (m :: * -> *). Monad m => String -> Cmd m ()
say String
"Choose between what?"
                    else forall (m :: * -> *). Monad m => String -> Cmd m ()
say forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => [a] -> m a
random forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
words forall a b. (a -> b) -> a -> b
$ String
args)
            }
        forall a. a -> [a] -> [a]
: [ (String -> Command Identity
command String
cmd)
            { help :: Cmd (ModuleT () LB) ()
help = forall (m :: * -> *). Monad m => String -> Cmd m ()
say (String -> String
dummyHelp String
cmd)
            , process :: String -> Cmd (ModuleT () LB) ()
process = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ forall (m :: * -> *). Monad m => String -> Cmd m ()
say forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
op
            }
          | (String
cmd, String -> String
op) <- [(String, String -> String)]
dummylst
          ]
    }

dummyHelp :: String -> String
dummyHelp :: String -> String
dummyHelp String
s = case String
s of
    String
"dummy"       -> String
"dummy. Print a string constant"
    String
"bug"         -> String
"bug. Submit a bug to GHC's trac"
    String
"id"          -> String
"id <arg>. The identity plugin"
    String
"show"        -> String
"show <foo>. Print \"<foo>\""
    String
"wiki"        -> String
"wiki <page>. URLs of Haskell wiki pages"
    String
"paste"       -> String
"paste. Paste page url"
    String
"docs"        -> String
"docs <lib>. Lookup the url for this library's documentation"
    String
"learn"       -> String
"learn. The learning page url"
    String
"haskellers"  -> String
"haskellers. Find other Haskell users"
    String
"botsnack"    -> String
"botsnack. Feeds the bot a snack"
    String
"get-shapr"   -> String
"get-shapr. Summon shapr instantly"
    String
"shootout"    -> String
"shootout. The debian language shootout"
    String
"faq"         -> String
"faq. Answer frequently asked questions about Haskell"
    String
"googleit"    -> String
"letmegooglethatforyou."
    String
"hackage"     -> String
"find stuff on hackage"
    String
_             -> String
"I'm sorry Dave, I'm afraid I don't know that command"

dummylst :: [(String, String -> String)]
dummylst :: [(String, String -> String)]
dummylst =
    [(String
"dummy"      , forall a b. a -> b -> a
const String
"dummy")
    ,(String
"bug"        , forall a b. a -> b -> a
const String
"https://gitlab.haskell.org/ghc/ghc/issues")
    ,(String
"id"         , (Char
' ' forall a. a -> [a] -> [a]
:) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> a
id)
    ,(String
"show"       , forall a. Show a => a -> String
show)
    ,(String
"wiki"       , String -> String
lookupWiki)
    ,(String
"paste"      , forall a b. a -> b -> a
const String
"A pastebin: https://paste.debian.net/")
    ,(String
"docs"       , \String
x -> if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
x
                           then String
docPrefix String -> String -> String
</> String
"index.html"
                           else String -> Char -> String -> String -> String
lookupPackage String
docPrefix Char
'-' String
"html" String
x)
    ,(String
"learn"      , forall a b. a -> b -> a
const String
"https://wiki.haskell.org/Learning_Haskell")
    ,(String
"haskellers" , forall a b. a -> b -> a
const String
"https://www.haskellers.com/")
    ,(String
"botsnack"   , forall a b. a -> b -> a
const String
":)")
    ,(String
"get-shapr"  , forall a b. a -> b -> a
const String
"shapr!!")
    ,(String
"shootout"   , forall a b. a -> b -> a
const String
"https://benchmarksgame-team.pages.debian.net/benchmarksgame/")
    ,(String
"faq"        , forall a b. a -> b -> a
const String
"The answer is: Yes! Haskell can do that.")
    ,(String
"googleit"   , String -> String
lookupGoogle)
    ,(String
"hackage"    , String -> String
lookupHackage)
    ,(String
"thanks"     , forall a b. a -> b -> a
const String
"you are welcome")
    ,(String
"thx"        , forall a b. a -> b -> a
const String
"you are welcome")
    ,(String
"thank you"  , forall a b. a -> b -> a
const String
"you are welcome")
    ,(String
"ping"       , forall a b. a -> b -> a
const String
"pong")
    ,(String
"tic-tac-toe", forall a b. a -> b -> a
const String
"how about a nice game of chess?")
    ]

lookupWiki :: String -> String
lookupWiki :: String -> String
lookupWiki String
page = String
"https://wiki.haskell.org" String -> String -> String
</> String -> String
spacesToUnderscores String
page
  where spacesToUnderscores :: String -> String
spacesToUnderscores = forall a b. (a -> b) -> [a] -> [b]
map (\Char
c -> if Char
c forall a. Eq a => a -> a -> Bool
== Char
' ' then Char
'_' else Char
c)

lookupHackage :: String -> String
lookupHackage :: String -> String
lookupHackage String
"" = String
"https://hackage.haskell.org"
lookupHackage String
xs = String
"https://hackage.haskell.org/package" String -> String -> String
</> String
xs

googlePrefix :: String
googlePrefix :: String
googlePrefix = String
"https://lmgtfy.com"

lookupGoogle :: String -> String
lookupGoogle :: String -> String
lookupGoogle String
"" = String
googlePrefix
lookupGoogle String
xs = String
googlePrefix String -> String -> String
</> String
"?q=" forall a. [a] -> [a] -> [a]
++ String -> String
quote String
xs
 where
    quote :: String -> String
quote = forall a b. (a -> b) -> [a] -> [b]
map (\Char
x -> if Char
x forall a. Eq a => a -> a -> Bool
== Char
' ' then Char
'+' else Char
x)

docPrefix :: String
docPrefix :: String
docPrefix = String
"https://haskell.org/ghc/docs/latest/html/libraries"

lookupPackage :: String -> Char -> String -> String -> String
lookupPackage :: String -> Char -> String -> String -> String
lookupPackage String
begin Char
sep String
end String
x'' = 
    case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (String -> ByteString
P.pack String
x') Map ByteString (ByteString, ByteString)
docAssocs of
        Maybe (ByteString, ByteString)
Nothing -> forall a. (a -> Bool) -> [a] -> [a]
strip Char -> Bool
isSpace String
x'' forall a. [a] -> [a] -> [a]
++ String
" not available"
        Just (ByteString
x, ByteString
m)  -> String
begin
               String -> String -> String
</> ByteString -> String
P.unpack ByteString
m
               String -> String -> String
</> forall a b. (a -> b) -> [a] -> [b]
map (forall {m :: * -> *} {b}. Monad m => m Bool -> m b -> m b -> m b
choice (forall a. Eq a => a -> a -> Bool
==Char
'.') (forall a b. a -> b -> a
const Char
sep) forall a. a -> a
id) (ByteString -> String
P.unpack ByteString
x)
               String -> String -> String
<.> String
end
    where 
        choice :: m Bool -> m b -> m b -> m b
choice m Bool
p m b
f m b
g = m Bool
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
b -> if Bool
b then m b
f else m b
g
        x' :: String
x'  = forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (forall a. (a -> Bool) -> [a] -> [a]
strip Char -> Bool
isSpace String
x'')