By | fr33domlover |
At | 2016-01-21 |
Title | Allow adding lwhere when there are no channel settings |
Description | Most channels don't have channel settings (the ones stored by FunBot and not irc-fun-bot), and use the default values. But when settings an option, the channel is added to the hashmap. This didn't happen for lwhere. Now it does, but it's limited to selected (autojoin) channels since other channels don't make sense anyway. |
Edit file src/FunBot/Settings/Sections/Channels.hs 33188 → 33188
146 146 let sec = chanSec chan []
147 147 ins = insertSub route sec
148 148 modifyState $ \ s -> s { bsSTree = ins $ bsSTree s }
149 149 150 150 -- | Add a new location item to a channel's settings and tree. Return 'Nothing'
- 151 -- on success. Otherwise return whether the channel doesn't exist ('False') or
+ 151 -- on success. Otherwise return whether the channel isn't selected ('False') or
152 152 -- the location label already exists ('True').
153 153 addLocalLocation
154 154 :: Channel
155 155 -> LocationLabel
156 156 -> Location
157 157 -> BotSession (Maybe Bool)
158 158 addLocalLocation chan label location = do
- 159 chans <- fmap stChannels getSettings
- 160 case M.lookup chan chans of
- 161 Nothing -> return $ Just False
- 162 Just cs ->
- 163 let locs = csLocations cs
- 164 in case M.lookup label locs of
- 165 Just _ -> return $ Just True
- 166 Nothing -> do
- 167 let locs' = M.insert label location locs
- 168 cs' = cs { csLocations = locs' }
- 169 chans' = M.insert chan cs' chans
- 170 modifySettings $ \ s -> s { stChannels = chans' }
- 171 saveBotSettings
- 172 let (t, opt) = locationOption chan label
- 173 path = ["channels", unChannel chan, "locations", t]
- 174 ins = insertOpt path opt
- 175 modifyState $ \ s -> s { bsSTree = ins $ bsSTree s }
- 176 return Nothing
+ 159 sel <- channelSelected chan
+ 160 if sel
+ 161 then do
+ 162 chans <- fmap stChannels getSettings
+ 163 let cs = M.lookupDefault defChan chan chans
+ 164 locs = csLocations cs
+ 165 case M.lookup label locs of
+ 166 Just _ -> return $ Just True
+ 167 Nothing -> do
+ 168 let locs' = M.insert label location locs
+ 169 cs' = cs { csLocations = locs' }
+ 170 chans' = M.insert chan cs' chans
+ 171 modifySettings $ \ s -> s { stChannels = chans' }
+ 172 saveBotSettings
+ 173 let (t, opt) = locationOption chan label
+ 174 path = ["channels", unChannel chan, "locations", t]
+ 175 ins = insertOpt path opt
+ 176 modifyState $ \ s -> s { bsSTree = ins $ bsSTree s }
+ 177 return Nothing
+ 178 else return $ Just False
177 179 178 180 -- | Remove a channel-specific location from settings and tree. Return whether
179 181 -- success, i.e. whether the location did exist and indeed has been deleted.
180 182 removeLocalLocation :: Channel -> LocationLabel -> BotSession Bool
181 183 removeLocalLocation chan label = do
… … … … Edit file src/FunBot/Commands/Locations.hs 33188 → 33188
207 207 send $ formatMsg
208 208 ("Location ‘" % text % "’ registered for " % channel)
209 209 labelt chan
210 210 Just False ->
211 211 send $ formatMsg
- 212 ( nickname % ", I’m not holding settings for " % channel %
- 213 ". If that’s unexpected, please talk to my maintainer."
+ 212 ( nickname % ", " % channel % " isn’t one of my autojoin \
+ 213 \channels. If you’d like to add it to my list, you should \
+ 214 \probably talk to my maintainer. Once added, you can define \
+ 215 \locations for this channel."
214 216 )
215 217 nick chan
216 218 Just True -> send $ formatMsg
217 219 ( nickname % ", location ‘" % text % "’ is already registered \
218 220 \for " % channel % ". You can use ‘!set’ to modify it."
… … … …