By | fr33domlover |
At | 2016-01-26 |
Title | Create helper for command help formatting |
Description |
Edit file src/FunBot/Util.hs 33188 → 33188
21 21 , passes
22 22 , passesBy
23 23 , getTimeStr
24 24 , getHistoryLines
25 25 , cmds
+ 26 , helps
26 27 , looksLikeChan
27 28 , notchan
28 29 , looksLikeNick
29 30 , notnick
30 31 , unsnoc
… … … … 38 39 import Data.Monoid ((<>))
39 40 import Data.Text (Text)
40 41 import FunBot.Types
41 42 import Network.IRC.Fun.Bot.State (askTimeGetter, getChanInfo)
42 43 import Network.IRC.Fun.Bot.Types (ChanInfo (ciHistoryLines), CommandName (..))
+ 44 import Network.IRC.Fun.Color.Style
43 45 import Network.IRC.Fun.Types.Base
44 46 45 47 import qualified Data.CaseInsensitive as CI (mk)
46 48 import qualified Data.HashMap.Lazy as M (lookup)
47 49 import qualified Data.Text as T
… … … … 89 91 return $ maybe 0 ciHistoryLines $ M.lookup chan cs
90 92 91 93 -- | Helper for specifying command names
92 94 cmds :: [Text] -> [CommandName]
93 95 cmds = map $ CommandName . CI.mk
+ 96 + 97 -- | Helper for specifying command help
+ 98 helps :: [(Text, Text)] -> Text
+ 99 helps l = T.intercalate "\n" $ map (uncurry f) l
+ 100 where
+ 101 maxlen = maximum $ map (T.length . fst) l
+ 102 nspaces spec = maxlen - T.length spec
+ 103 spaces spec = T.replicate (nspaces spec) " "
+ 104 f spec desc = T.concat
+ 105 [ "‘"
+ 106 , encode $ Bold #> plain spec
+ 107 , "’"
+ 108 , spaces spec
+ 109 , " - "
+ 110 , desc
+ 111 ]
94 112 95 113 looksLikeChan (Channel chan) =
96 114 case T.uncons chan of
97 115 Nothing -> False
98 116 Just (c, _) -> c `elem` ("#+!&" :: String)
… … … … Edit file src/FunBot/Commands/Info.hs 33188 → 33188
37 37 import FunBot.Settings.Sections.Feeds (addFeed, deleteFeed)
38 38 import FunBot.Settings.Sections.Repos
39 39 import FunBot.Settings.Sections.Shortcuts (addShortcut, deleteShortcut)
40 40 import FunBot.Types
41 41 import FunBot.UserOptions
- 42 import FunBot.Util (getHistoryLines, cmds)
+ 42 import FunBot.Util
43 43 import Network.IRC.Fun.Bot.Behavior
44 44 import Network.IRC.Fun.Bot.Chat
45 45 import Network.IRC.Fun.Bot.State
46 46 import Network.IRC.Fun.Bot.Types
47 47 import Network.IRC.Fun.Client.IO (connNickname)
… … … … 265 265 failBack mchan nick $ WrongNumArgsN (Just $ length args) Nothing
266 266 267 267 cmdInfo = Command
268 268 { cmdNames = cmds ["info", "i"]
269 269 , cmdRespond = respondInfo
- 270 , cmdHelp = "‘info’ - list topics. Also see ‘help’.\n\
- 271 \‘info <topic>’ - display topic information."
+ 270 , cmdHelp = helps
+ 271 [ ("info" , "list topics. Also see ‘help’.")
+ 272 , ("info <topic>" , "display topic information.")
+ 273 ]
272 274 , cmdExamples =
273 275 [ "info"
274 276 , "info shortcuts"
275 277 ]
276 278 }
… … … …