Skip to content

Commit

Permalink
Added NickChangeAction and modified Nick to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-sky committed Aug 5, 2014
1 parent de1f8aa commit dce4e31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/Nick.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import IRCD.Types
import IRCD.Env
import IRCD.Clients
import IRCD.Helper
import Hoist

plugin :: Plugin
plugin = defaultPlugin {handlers=[CommandHandler "NICK" nickHandler]}
Expand All @@ -31,10 +32,11 @@ nickHandler :: HandlerSpec
nickHandler src@(ClientSrc client) (Message _ _ _ (nick':_)) = do
nicks <- gets (byNick . envClients)
if upperNick `M.notMember` nicks || (upperNick == map toUpper clientNick && nick' /= clientNick)
then do
modify $ mapEnvClients (replaceClient client client {nick=Just nick'})
return [GenericAction $ reply_ src ("NICK " ++ nick')]
then return [NickChangeAction src clientNick nick' ioChange]
else return [GenericAction $ reply_ src "Nickname is already in use"]
where upperNick = map toUpper nick'
clientNick = fromMaybe "" (nick client)
ioChange = do
hoistState $ modify $ mapEnvClients (replaceClient client client {nick=Just nick'})
reply_ src ("NICK " ++ nick')
nickHandler src@(ClientSrc client) _ = return [GenericAction $ reply_ src "No nickname given"]
2 changes: 2 additions & 0 deletions src/IRCD/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ instance Ord Transformer where
type ActionSpec = StateT Env IO ()
data Action = GenericAction ActionSpec
| PrivmsgAction Source Destination Message ActionSpec
| NickChangeAction Source String String ActionSpec

actionSpec :: Action -> ActionSpec
actionSpec (GenericAction spec) = spec
actionSpec (PrivmsgAction _ _ _ spec) = spec
actionSpec (NickChangeAction _ _ _ spec) = spec

defaultClient :: Client
defaultClient = Client
Expand Down

0 comments on commit dce4e31

Please sign in to comment.