Skip to content

Commit

Permalink
Wrote User plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-sky committed Aug 5, 2014
1 parent 0a43ffc commit b41fc22
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
36 changes: 36 additions & 0 deletions plugins/User.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{- Copyright 2014 David Farrell <[email protected]>
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-}

module User (plugin) where

import Control.Monad.State
import IRCD.Types
import IRCD.Env
import IRCD.Clients
import IRCD.Helper
import Hoist

plugin :: Plugin
plugin = defaultPlugin {handlers=[CommandHandler "USER" userHandler]}

userHandler :: HandlerSpec
userHandler src@(ClientSrc client) (Message _ _ _ (user':_:_:realname:_))
| registered client = return [GenericAction $ reply_ src "You may not reregister"]
| otherwise = return [ UserChangeAction src (user client) user' ioUser
, RealNameChangeAction src (realName client) realname ioRealName
]
where ioUser = hoistState $ modify $ mapEnvClients (replaceClient client client {user=Just user'})
ioRealName = hoistState $ modify $ mapEnvClients (replaceClient client client {realName=Just realname})
userHandler src _ = return [GenericAction $ reply_ src "Not enough parameters"]
6 changes: 5 additions & 1 deletion src/IRCD/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ instance Ord Transformer where
type ActionSpec = StateT Env IO ()
data Action = GenericAction ActionSpec
| PrivmsgAction Source Destination Message ActionSpec
| NickChangeAction Source String String ActionSpec
| NickChangeAction Source (Maybe String) String ActionSpec
| UserChangeAction Source (Maybe String) String ActionSpec
| RealNameChangeAction Source (Maybe String) String ActionSpec

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

defaultClient :: Client
defaultClient = Client
Expand Down
2 changes: 1 addition & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import IRCD.Server
import IRCD.Plugin.Load

main :: IO ()
main = loadPlugins ["Ping", "Nick"{-, "NoExternal"-}] >>= serveIRC
main = loadPlugins ["Ping", "Nick", "User"{-, "NoExternal"-}] >>= serveIRC

loadPlugins :: [String] -> IO [Plugin]
loadPlugins names = do
Expand Down

0 comments on commit b41fc22

Please sign in to comment.