From 37abc729b0069477c0dc0c6cd7bb39d3f05b0ff8 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Sat, 9 Feb 2008 15:27:25 -0600 Subject: [PATCH] Join & Part abilities now require you to be an admin --- Infinity/Core.hs | 18 ++++++++++++------ Infinity/Main.hs | 10 +++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Infinity/Core.hs b/Infinity/Core.hs index 5fefd39..b01a98f 100644 --- a/Infinity/Core.hs +++ b/Infinity/Core.hs @@ -3,13 +3,14 @@ module Infinity.Core ( Bot(..), Server(..), -- * Functions on 'Bot' newbot, -- :: Bot - joinchan, partchan, -- :: Channel -> Serv -> Serv - joinserv, partserv, -- :: Serv -> Bot -> Bot + joinchan, partchan, -- :: Channel -> Server -> Server + joinserv, partserv, -- :: Server -> Bot -> Bot joinservs, -- :: [(Server,Handle)] -> Bot -> Bot - updateserv, -- :: Server -> Bot -> Bot - newadmin, deladmin, -- :: Nick -> Serv -> Serv - servexists, -- :: Serv -> Bot -> Bool - servnum -- :: Bot -> Int + updateserv, -- :: Server -> Bot -> Bot + newadmin, deladmin, -- :: Nick -> Server -> Server + isadmin, -- :: Nick -> Server -> Bool + servexists, -- :: Server -> Bot -> Bool + servnum -- :: Bot -> Int ) where import Infinity.Util import System.IO @@ -98,6 +99,11 @@ deladmin n serv = if n `S.notMember` x then serv else newserv (S.delete n x) where x = administrators serv newserv y = serv{administrators=y} +-- | Checks if a user is an administrator +isadmin :: Nick -> Server -> Bool +isadmin n serv = n `S.member` x + where x = administrators serv + -- | Number of currently connected servers servnum :: Bot -> Int servnum (Bot x) = M.size x diff --git a/Infinity/Main.hs b/Infinity/Main.hs index 35dd5b2..3f9efd0 100644 --- a/Infinity/Main.hs +++ b/Infinity/Main.hs @@ -61,7 +61,7 @@ data RemoteLine -- | The bot\'s static entry point; used --- when built with -fstatic +-- when not built with -fdynamic staticmain :: IO () staticmain = do -- connect to all servers @@ -177,12 +177,12 @@ listener plugins rchan rebootvar x@(serv,handle) = infinity $ do case av of Nothing -> irclog (address serv) (u,c,cmd) Just args -> irclog (address serv) (u,c,unwords [cmd,args]) - unless (null cmd') (parseCmds cmd' av c $ IContext (Just serv) plugins (Just handle)) - parseCmds c av chan ctx - | "join" == c = case av of + unless (null cmd') (parseCmds u cmd' av c $ IContext (Just serv) plugins (Just handle)) + parseCmds u c av chan ctx + | "join" == c = when (isadmin u serv) $ case av of Just av' -> joinC handle av' >> writeChan rchan (Join (serv,av')) Nothing -> privmsg handle chan "Need a channel to join..." - | "part" == c = case av of + | "part" == c = when (isadmin u serv) $ case av of Just av' -> partC handle av' >> writeChan rchan (Part (serv,av')) Nothing -> partC handle chan >> writeChan rchan (Part (serv,chan)) -- | "quit" == c = writeChan rchan (Quit (serv,handle)) -- 2.11.4.GIT