| | 587 | def irc_cmd_PRIVMSG(self,prefix,command,params): |
|---|
| | 588 | self.debug("Message from %r" % (prefix,)) |
|---|
| | 589 | if len(params)<2: |
|---|
| | 590 | self.debug("ignoring it") |
|---|
| | 591 | return |
|---|
| | 592 | user=self.get_user(prefix) |
|---|
| | 593 | if user.current_thread: |
|---|
| | 594 | typ,thread,fr=user.current_thread |
|---|
| | 595 | else: |
|---|
| | 596 | typ="chat" |
|---|
| | 597 | thread=str(random.random()) |
|---|
| | 598 | fr=None |
|---|
| | 599 | user.current_thread=typ,thread,None |
|---|
| | 600 | if not fr: |
|---|
| | 601 | fr=user.jid() |
|---|
| | 602 | body=unicode(params[1],self.default_encoding,"replace") |
|---|
| | 603 | m=Message(type=typ,fr=fr,to=self.jid,body=remove_evil_characters(body)) |
|---|
| | 604 | self.component.send(m) |
|---|
| | 605 | |
|---|
| | 680 | |
|---|
| | 681 | def message_to_user(self,stanza): |
|---|
| | 682 | if not self.ready: |
|---|
| | 683 | return |
|---|
| | 684 | to=stanza.get_to() |
|---|
| | 685 | if to.resource and (to.node[0] in "#+!" or to.node.startswith(",amp,")): |
|---|
| | 686 | nick=to.resource |
|---|
| | 687 | thread_fr=stanza.get_to() |
|---|
| | 688 | else: |
|---|
| | 689 | nick=to.node |
|---|
| | 690 | thread_fr=None |
|---|
| | 691 | nick=node_to_nick(nick,self.default_encoding) |
|---|
| | 692 | if not nick_re.match(nick): |
|---|
| | 693 | debug("Bad nick: %r" % (nick,)) |
|---|
| | 694 | return |
|---|
| | 695 | self.debug("Nick: %r" % (nick,)) |
|---|
| | 696 | user=self.get_user(nick) |
|---|
| | 697 | user.current_thread=stanza.get_type(),stanza.get_thread(),thread_fr |
|---|
| | 698 | body=stanza.get_body().encode(self.default_encoding,"replace") |
|---|
| | 699 | body=body.replace("\n"," ").replace("\r"," ") |
|---|
| | 700 | if body.startswith("/me "): |
|---|
| | 701 | body="\001ACTION "+body[4:]+"\001" |
|---|
| | 702 | self.send("PRIVMSG %s :%s" % (nick,body)) |
|---|
| | 803 | def message(self,stanza): |
|---|
| | 804 | to=stanza.get_to() |
|---|
| | 805 | fr=stanza.get_from() |
|---|
| | 806 | typ=stanza.get_type() |
|---|
| | 807 | if typ not in (None,"chat"): |
|---|
| | 808 | typ=None |
|---|
| | 809 | sess=self.irc_sessions.get(fr.as_unicode()) |
|---|
| | 810 | if not to.node: |
|---|
| | 811 | if sess: |
|---|
| | 812 | m=Message(to=fr,fr=to,body="Connected to: %s" % (sess.server,),type=typ) |
|---|
| | 813 | else: |
|---|
| | 814 | m=Message(to=fr,fr=to,body="Not connected",type=typ) |
|---|
| | 815 | return 1 |
|---|
| | 816 | if not to.resource and (to.node[0] in "#+!" or to.node.startswith(",amp,")): |
|---|
| | 817 | self.groupchat_message(stanza) |
|---|
| | 818 | sess=self.irc_sessions.get(fr.as_unicode()) |
|---|
| | 819 | if sess: |
|---|
| | 820 | sess.message_to_user(stanza) |
|---|
| | 821 | else: |
|---|
| | 822 | m=stanza.make_error_response("recipient-unavailable") |
|---|
| | 823 | self.send(m) |
|---|
| | 824 | return 1 |
|---|
| | 825 | |
|---|
| | 826 | |
|---|