By | fr33domlover |
At | 2016-01-25 |
Title | Add puppet say/echo commands, completing puppet system basics |
Description |
Edit file src/FunBot/Commands.hs 33188 → 33188
74 74 , cmdRemoveWhereLocal
75 75 , cmdAddWhereGlobal
76 76 , cmdRemoveWhereGlobal
77 77 , cmdPuppetStart
78 78 , cmdPuppetEnd
+ 79 , cmdPuppetSay
+ 80 , cmdPuppetEcho
79 81 ]
80 82 }
… … … … Edit file src/FunBot/Commands/Puppet.hs 33188 → 33188
17 17 18 18 module FunBot.Commands.Puppet
19 19 ( cmdPuppetStart
20 20 , cmdPuppetEnd
21 21 --, cmdPuppetStatus
- 22 --, cmdPuppetSay
+ 22 , cmdPuppetSay
+ 23 , cmdPuppetEcho
23 24 )
24 25 where
25 26 26 27 import Formatting ((%))
27 28 import FunBot.Puppet
… … … … 31 32 import Network.IRC.Fun.Bot.Types
32 33 import Network.IRC.Fun.Color.Format (formatMsg)
33 34 import Network.IRC.Fun.Color.Format.Long
34 35 import Network.IRC.Fun.Types.Base
35 36 + 37 import qualified Data.Text as T
+ 38 36 39 start :: Channel -> Nickname -> (MsgContent -> BotSession ()) -> BotSession ()
37 40 start chan nick send = do
38 41 result <- puppetStart chan nick
39 42 send $ case result of
40 43 Just False ->
… … … … 119 122 "‘puppet-end’ - stop puppet mode in the current channel\n\
120 123 \‘puppet-end <channel>’ - stop puppet mode in the given channel"
121 124 , cmdExamples =
122 125 [ "puppet-end"
123 126 , "puppet-end #freepost-bot"
+ 127 ]
+ 128 }
+ 129 + 130 respondPuppetSay :: Bool -> Respond
+ 131 respondPuppetSay reveal _mchan nick (chant : ws@(_:_)) send =
+ 132 let chan = Channel chant
+ 133 in if looksLikeChan chan
+ 134 then do
+ 135 let msg = MsgContent $ T.unwords ws
+ 136 result <- puppetSay chan nick msg reveal
+ 137 send $ case result of
+ 138 Just False ->
+ 139 formatMsg
+ 140 ( nickname
+ 141 % ", I don’t have "
+ 142 % channel
+ 143 % " in puppet mode."
+ 144 )
+ 145 nick chan
+ 146 Just True ->
+ 147 formatMsg
+ 148 ( nickname
+ 149 % ", you didn’t start puppet mode for "
+ 150 % channel
+ 151 )
+ 152 nick chan
+ 153 Nothing ->
+ 154 formatMsg
+ 155 (nickname % ", I sent the message to " % channel)
+ 156 nick chan
+ 157 else send $ notchan chan
+ 158 respondPuppetSay _reveal mchan nick args _send =
+ 159 failBack mchan nick $ WrongNumArgsN (Just $ length args) (Just 2)
+ 160 + 161 cmdPuppetSay :: BotCmd
+ 162 cmdPuppetSay = Command
+ 163 { cmdNames = cmds ["puppet-say"]
+ 164 , cmdRespond = respondPuppetSay True
+ 165 , cmdHelp =
+ 166 "‘puppet-say <channel> <message>’ - While in puppet mode, ask me to \
+ 167 \say something in the channel. I will reveal the message comes from \
+ 168 \you. If you don’t want that, see the puppet-echo command."
+ 169 , cmdExamples =
+ 170 [ "puppet-say #freepost Hello world!"
+ 171 ]
+ 172 }
+ 173 + 174 cmdPuppetEcho :: BotCmd
+ 175 cmdPuppetEcho = Command
+ 176 { cmdNames = cmds ["puppet-echo"]
+ 177 , cmdRespond = respondPuppetSay False
+ 178 , cmdHelp =
+ 179 "‘puppet-echo <channel> <message>’ - While in puppet mode, ask me to \
+ 180 \say something in the channel. I won’t reveal the message comes from \
+ 181 \you. Also see the puppet-say command."
+ 182 , cmdExamples =
+ 183 [ "puppet-echo #freepost Hello world!"
124 184 ]
125 185 }
… … … …