Changeset 62

Show
Ignore:
Timestamp:
02/16/04 19:46:59 (5 years ago)
Author:
jajcus
Message:

- /OP (moderator privileges granting in MUC)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/jjigw.py

    r60 r62  
    8787def normalize(s): 
    8888    return s.translate(irc_translate_table) 
    89  
    9089 
    9190class ConnectConfig: 
     
    263262        channel,user,host,server,nick,flags,rest=params 
    264263        fullname=rest.split(None,1)[1] 
    265         self.debug("Channel: %r" % (channel,)) 
    266264        if channel and channel!="*": 
    267265            channel=self.session.channels.get(normalize(channel)) 
     
    277275            self.user=user 
    278276            if channel: 
    279                 self.debug("Channel: %r" % (channel,)) 
    280277                self.join_channel(channel) 
    281278                if "@" in flags: 
     
    395392        else: 
    396393            p=MucPresence(type="unavailable",fr=self.nick_to_jid(user.nick),to=self.session.jid) 
    397         self.debug("%r modes: %r" % (self.name,self.modes)) 
    398394        if self.muc: 
    399395            if user in self.modes.get("o",[]): 
     
    406402                aff="none" 
    407403                role="visitor" 
     404            elif user in self.users: 
     405                aff="none" 
     406                role="participant" 
    408407            else: 
    409408                aff="none" 
    410                 role="participant
     409                role="none
    411410            ui=p.make_muc_userinfo() 
    412411            if nick: 
     
    465464         
    466465    def irc_cmd_482(self,prefix,command,params): # ERR_CHANOPRIVSNEEDED 
    467         self.irc_error_response(prefix,command,params,["TOPIC","KICK"],"forbidden") 
     466        self.irc_error_response(prefix,command,params,["TOPIC","KICK","MODE"],"forbidden") 
    468467 
    469468    def irc_cmd_461(self,prefix,command,params): # ERR_NEEDMOREPARAMS 
    470         self.irc_error_response(prefix,command,params,["TOPIC","KICK"],"bad-request") 
     469        self.irc_error_response(prefix,command,params,["TOPIC","KICK","MODE"],"bad-request") 
    471470 
    472471    def irc_cmd_403(self,prefix,command,params): # ERR_NOSUCHCHANNEL 
     
    477476     
    478477    def irc_cmd_441(self,prefix,command,params): # ERR_USERNOTINCHANNEL 
    479         self.irc_error_response(prefix,command,params,["KICK"],"item-not-found") 
     478        self.irc_error_response(prefix,command,params,["KICK","MODE"],"item-not-found") 
    480479         
    481480    def irc_cmd_442(self,prefix,command,params): # ERR_NOTONCHANNEL 
    482481        self.irc_error_response(prefix,command,params,["TOPIC","KICK"],"forbidden") 
    483482 
     483    def irc_cmd_472(self,prefix,command,params): # ERR_UNKNOWNMODE 
     484        self.irc_error_response(prefix,command,params,["MODE"],"feature-not-implemented") 
     485 
    484486    def irc_cmd_477(self,prefix,command,params): # ERR_NOCHANMODES 
    485         self.irc_error_response(prefix,command,params,["TOPIC"],"not-acceptable") 
     487        self.irc_error_response(prefix,command,params,["TOPIC","MODE"],"not-acceptable") 
    486488 
    487489    def irc_error_response(self,prefix,command,params,requests,condition): 
     
    529531                        unicode(iuser,self.encoding,"replace")), 
    530532                0) 
     533        if self.session.check_prefix(prefix) and len(params)>=3: 
     534            r=self.requests.get("MODE",(params[1],normalize(params[2]))) 
     535            if r: 
     536                reply=r.stanza.make_result_response() 
     537                self.session.component.send(reply) 
    531538        self.irc_mode_changed(prefix,command,params) 
    532539 
     
    568575 
    569576    def user_mode_changed(self,user,actor,mode): 
    570         self.debug("user_mode_changed(%r,%r,%r)" % (user,actor,mode)) 
    571577        if actor: 
    572578            actor_jid=self.nick_to_jid(actor.nick) 
     
    640646 
    641647    def irc_cmd_PRIVMSG(self,prefix,command,params): 
    642         self.debug("Message on channel %r" % (self.name,)) 
     648        self.irc_message(prefix,command,params) 
     649 
     650    def irc_cmd_NOTICE(self,prefix,command,params): 
     651        self.irc_message(prefix,command,params) 
     652 
     653    def irc_message(self,prefix,command,params): 
    643654        if not self.state or len(params)<2: 
    644655            self.debug("ignoring it") 
     
    671682 
    672683    def kick_user(self,nick,reason,stanza): 
     684        nick=nick.encode(self.encoding,"strict") 
    673685        self.session.send("KICK %s %s :%s" % (self.name,nick,reason)) 
    674686        self.requests.add("KICK",stanza,nick) 
    675     
     687  
     688    def op_user(self,nick,stanza): 
     689        nick=nick.encode(self.encoding,"strict") 
     690        user=self.session.users.get(normalize(nick)) 
     691        if not user in self.users: 
     692           r=stanza.make_error_response("item-not-found") 
     693           self.session.component.send(r) 
     694           return 
     695        if user in self.modes.get("o",[]): 
     696           r=stanza.make_result_response() 
     697           self.session.component.send(r) 
     698           return 
     699        self.session.send("MODE %s +o %s" % (self.name,nick)) 
     700        self.requests.add("MODE",stanza,("+o",normalize(nick))) 
     701 
    676702    def __repr__(self): 
    677703        return "<IRCChannel %r>" % (self.name,) 
     
    930956        if command and numeric_re.match(command): 
    931957            params=params[1:] 
    932         self.debug("Prefix: %r Command: %r params: %r" % (prefix,command,params)) 
    933958        self.lock.release() 
    934959        try: 
     
    945970            else: 
    946971                for u in self.used_for: 
    947                     self.debug("u: %r" % (u,)) 
    948972                    if u.bare()==self.network.jid: 
    949973                        self.pass_input_to_user(prefix,command,params) 
     
    966990 
    967991    def irc_cmd_PRIVMSG(self,prefix,command,params): 
    968         self.debug("Message from %r" % (prefix,)) 
     992        self.irc_message(prefix,command,params) 
     993 
     994    def irc_cmd_NOTICE(self,prefix,command,params): 
     995        self.irc_message(prefix,command,params) 
     996 
     997    def irc_message(self,prefix,command,params): 
    969998        if len(params)<2: 
    970999            self.debug("ignoring it") 
     
    10761105            return 
    10771106        user=self.get_user(params[4]) 
    1078         self.debug("Got user %r" % (user.nick,)) 
    10791107        user.whoreply(params) 
    1080         self.debug("%r on channels %r" % (user.nick,user.channels.keys())) 
    10811108        for c in user.channels.keys(): 
    1082             self.debug("announcing %r presence on channel %r" % (user.nick,c)) 
    10831109            channel=user.channels[c] 
    10841110            self.component.send(channel.get_user_presence(user)) 
    10851111    
    10861112    def send_error_message(self,source,cond,text): 
    1087         self.debug("send_error_message(self,%r,%r,%r)" % (source,cond,text)) 
    10881113        text=remove_evil_characters(text) 
    10891114        user=self.get_user(source) 
     
    10911116            self.unregister_user(user) 
    10921117        if user and user.current_thread: 
    1093             self.debug("user.current_thread: %r" % (user.current_thread,)) 
    10941118            typ,thread,fr=user.current_thread 
    10951119            if not fr: 
     
    10991123        else: 
    11001124            fr=self.prefix_to_jid(source) 
    1101             self.debug("from: %r" % (fr,)) 
    11021125            m=Message(type="error",error_cond=cond,error_text=text, 
    11031126                    to=self.jid,fr=fr) 
     
    11501173 
    11511174    def message_to_channel(self,stanza): 
    1152         self.debug("message_to_channel(%r)" % (stanza,)) 
    11531175        self.cond.acquire() 
    11541176        try: 
     
    11631185            self.component.send(e) 
    11641186            return 
    1165         self.debug("channel: %r" % (channel,)) 
    11661187        if channel: 
    11671188            encoding=channel.encoding 
    11681189        else: 
    11691190            encoding=self.default_encoding 
    1170         self.debug("encoding: %r" % (encoding,)) 
    11711191        subject=stanza.get_subject() 
    1172         self.debug("subject: %r" % (subject,)) 
    11731192        if subject and channel: 
    11741193            channel.change_topic(subject,stanza.copy()) 
    11751194        body=stanza.get_body() 
    1176         self.debug("body: %r" % (body,)) 
    11771195        if body: 
    11781196            body=body.encode(encoding,"replace") 
    11791197            body=body.replace("\n"," ").replace("\r"," ") 
    1180             self.debug("body: %r" % (body,)) 
    11811198            if body.startswith("/me "): 
    11821199                body="\001ACTION "+body[4:]+"\001" 
    11831200            self.send("PRIVMSG %s :%s" % (channel.name,body)) 
    11841201            channel.irc_cmd_PRIVMSG(self.nick,"PRIVMSG",[channel.name,body]) 
    1185         self.debug("message_to_channel: done") 
    11861202 
    11871203    def message_to_user(self,stanza): 
     
    12041220            debug("Bad nick: %r" % (nick,)) 
    12051221            return 
    1206         self.debug("Nick: %r" % (nick,)) 
    12071222        user=self.get_user(nick) 
    12081223        user.current_thread=stanza.get_type(),stanza.get_thread(),thread_fr 
     
    14061421        if item.role=="none": 
    14071422            channel.kick_user(item.nick,item.reason,iq) 
     1423        elif item.role=="moderator": 
     1424            channel.op_user(item.nick,iq) 
    14081425        else: 
    14091426            self.debug("Unknown admin action")