Changeset 62
- Timestamp:
- 02/16/04 19:46:59 (5 years ago)
- Files:
-
- trunk/jjigw.py (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jjigw.py
r60 r62 87 87 def normalize(s): 88 88 return s.translate(irc_translate_table) 89 90 89 91 90 class ConnectConfig: … … 263 262 channel,user,host,server,nick,flags,rest=params 264 263 fullname=rest.split(None,1)[1] 265 self.debug("Channel: %r" % (channel,))266 264 if channel and channel!="*": 267 265 channel=self.session.channels.get(normalize(channel)) … … 277 275 self.user=user 278 276 if channel: 279 self.debug("Channel: %r" % (channel,))280 277 self.join_channel(channel) 281 278 if "@" in flags: … … 395 392 else: 396 393 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))398 394 if self.muc: 399 395 if user in self.modes.get("o",[]): … … 406 402 aff="none" 407 403 role="visitor" 404 elif user in self.users: 405 aff="none" 406 role="participant" 408 407 else: 409 408 aff="none" 410 role=" participant"409 role="none" 411 410 ui=p.make_muc_userinfo() 412 411 if nick: … … 465 464 466 465 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") 468 467 469 468 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") 471 470 472 471 def irc_cmd_403(self,prefix,command,params): # ERR_NOSUCHCHANNEL … … 477 476 478 477 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") 480 479 481 480 def irc_cmd_442(self,prefix,command,params): # ERR_NOTONCHANNEL 482 481 self.irc_error_response(prefix,command,params,["TOPIC","KICK"],"forbidden") 483 482 483 def irc_cmd_472(self,prefix,command,params): # ERR_UNKNOWNMODE 484 self.irc_error_response(prefix,command,params,["MODE"],"feature-not-implemented") 485 484 486 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") 486 488 487 489 def irc_error_response(self,prefix,command,params,requests,condition): … … 529 531 unicode(iuser,self.encoding,"replace")), 530 532 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) 531 538 self.irc_mode_changed(prefix,command,params) 532 539 … … 568 575 569 576 def user_mode_changed(self,user,actor,mode): 570 self.debug("user_mode_changed(%r,%r,%r)" % (user,actor,mode))571 577 if actor: 572 578 actor_jid=self.nick_to_jid(actor.nick) … … 640 646 641 647 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): 643 654 if not self.state or len(params)<2: 644 655 self.debug("ignoring it") … … 671 682 672 683 def kick_user(self,nick,reason,stanza): 684 nick=nick.encode(self.encoding,"strict") 673 685 self.session.send("KICK %s %s :%s" % (self.name,nick,reason)) 674 686 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 676 702 def __repr__(self): 677 703 return "<IRCChannel %r>" % (self.name,) … … 930 956 if command and numeric_re.match(command): 931 957 params=params[1:] 932 self.debug("Prefix: %r Command: %r params: %r" % (prefix,command,params))933 958 self.lock.release() 934 959 try: … … 945 970 else: 946 971 for u in self.used_for: 947 self.debug("u: %r" % (u,))948 972 if u.bare()==self.network.jid: 949 973 self.pass_input_to_user(prefix,command,params) … … 966 990 967 991 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): 969 998 if len(params)<2: 970 999 self.debug("ignoring it") … … 1076 1105 return 1077 1106 user=self.get_user(params[4]) 1078 self.debug("Got user %r" % (user.nick,))1079 1107 user.whoreply(params) 1080 self.debug("%r on channels %r" % (user.nick,user.channels.keys()))1081 1108 for c in user.channels.keys(): 1082 self.debug("announcing %r presence on channel %r" % (user.nick,c))1083 1109 channel=user.channels[c] 1084 1110 self.component.send(channel.get_user_presence(user)) 1085 1111 1086 1112 def send_error_message(self,source,cond,text): 1087 self.debug("send_error_message(self,%r,%r,%r)" % (source,cond,text))1088 1113 text=remove_evil_characters(text) 1089 1114 user=self.get_user(source) … … 1091 1116 self.unregister_user(user) 1092 1117 if user and user.current_thread: 1093 self.debug("user.current_thread: %r" % (user.current_thread,))1094 1118 typ,thread,fr=user.current_thread 1095 1119 if not fr: … … 1099 1123 else: 1100 1124 fr=self.prefix_to_jid(source) 1101 self.debug("from: %r" % (fr,))1102 1125 m=Message(type="error",error_cond=cond,error_text=text, 1103 1126 to=self.jid,fr=fr) … … 1150 1173 1151 1174 def message_to_channel(self,stanza): 1152 self.debug("message_to_channel(%r)" % (stanza,))1153 1175 self.cond.acquire() 1154 1176 try: … … 1163 1185 self.component.send(e) 1164 1186 return 1165 self.debug("channel: %r" % (channel,))1166 1187 if channel: 1167 1188 encoding=channel.encoding 1168 1189 else: 1169 1190 encoding=self.default_encoding 1170 self.debug("encoding: %r" % (encoding,))1171 1191 subject=stanza.get_subject() 1172 self.debug("subject: %r" % (subject,))1173 1192 if subject and channel: 1174 1193 channel.change_topic(subject,stanza.copy()) 1175 1194 body=stanza.get_body() 1176 self.debug("body: %r" % (body,))1177 1195 if body: 1178 1196 body=body.encode(encoding,"replace") 1179 1197 body=body.replace("\n"," ").replace("\r"," ") 1180 self.debug("body: %r" % (body,))1181 1198 if body.startswith("/me "): 1182 1199 body="\001ACTION "+body[4:]+"\001" 1183 1200 self.send("PRIVMSG %s :%s" % (channel.name,body)) 1184 1201 channel.irc_cmd_PRIVMSG(self.nick,"PRIVMSG",[channel.name,body]) 1185 self.debug("message_to_channel: done")1186 1202 1187 1203 def message_to_user(self,stanza): … … 1204 1220 debug("Bad nick: %r" % (nick,)) 1205 1221 return 1206 self.debug("Nick: %r" % (nick,))1207 1222 user=self.get_user(nick) 1208 1223 user.current_thread=stanza.get_type(),stanza.get_thread(),thread_fr … … 1406 1421 if item.role=="none": 1407 1422 channel.kick_user(item.nick,item.reason,iq) 1423 elif item.role=="moderator": 1424 channel.op_user(item.nick,iq) 1408 1425 else: 1409 1426 self.debug("Unknown admin action")
