-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelpCore.hs
34 lines (30 loc) · 1.71 KB
/
HelpCore.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE OverloadedStrings #-}
module HelpCore
( run
) where
import Data.Maybe(fromJust)
import Data.List(find)
import qualified Data.Text as T(Text, intercalate, isPrefixOf, words, concat, unwords)
import IrcUtilities(IrcMsg(Privmsg), Bot(Bot), Plugin(Plugin), bNick, msgTo, helpAvailableModCmds, helpAvailableUserCmds, helpCmd)
import MyUtils(when)
import PluginsCore(enabledPlugins)
import Redirection(unwrapRedirectFromMsg)
run :: IrcMsg -> Bot -> IO [T.Text]
run (Privmsg author channel message) bot@(Bot h config _) = when (",help" `T.isPrefixOf` message') $ do
if (length args <= 1) then
return [msgTo channel target $ T.concat ["Komendy: ", T.unwords userCmds, " | Moderatorskie: ", T.unwords modCmds]]
else
return [msgTo channel target (T.intercalate " | " correctHelpCmd)]
where
(message', target) = unwrapRedirectFromMsg message author (bNick config)
args = T.words message'
searchCmd = args !! 1 -- cmd which we want help, is second arg: ",help <cmd>"
enabledPlugins' = enabledPlugins config
userCmds = concatMap helpAvailableUserCmds enabledPlugins'
modCmds = concatMap helpAvailableModCmds enabledPlugins'
correctHelpCmd :: [T.Text]
correctHelpCmd
| searchCmd `elem` userCmds = helpCmd (fromJust $ find (\p -> searchCmd `elem` helpAvailableUserCmds p) enabledPlugins') searchCmd
| searchCmd `elem` modCmds = helpCmd (fromJust $ find (\p -> searchCmd `elem` helpAvailableModCmds p) enabledPlugins') searchCmd
| otherwise = ["Nie znaleziono takiej komendy"]
run _ _ = return []