Beispiel #1
0
    def msgFromWords(self, toNick, sender, message, metadata=None):
        """Deliver a directMessage as a privmsg over IRC.
        """
        if message[0] != irc.X_DELIM:
            if metadata and metadata.has_key('style'):
                # Damn.  What am I supposed to do with this?
                message = "[%s] %s" % (metadata['style'], message)

            self.irc.msg(toNick, '<%s> %s' % (sender, message))
        else:
            # If there is a CTCP delimeter at the beginning of the
            # message, let's leave it there to accomidate not-so-
            # tolerant clients.
            dcc_data = None
            if message[1:5] == 'DCC ':
                dcc_query = irc.ctcpExtract(message)['extended'][0]
                dcc_data = dcc_query[1]

            if dcc_data:
                desc = "DCC " + irc.dccDescribe(dcc_data)
            else:
                desc = "CTCP request"

            self.irc.msg(toNick, 'The following %s is from %s'
                     % (desc, sender))
            self.irc.msg(toNick, '%s' % (message,))
Beispiel #2
0
    def receiveGroupMessage(self, sender, group, message, metadata=None):
        """Pass a message from the Words group on to IRC.

        Or, if it's in our errorGroup, recognize some debugging commands.
        """
        if not (group == self.errorGroup):
            channel = groupToChannelName(group)
            if not self.isThisMine(sender):
                # Test for Special case:
                # got CTCP, probably through words.ircservice
                #      (you SUCK!)
                # ACTION is the only case we'll support here.
                if message[:8] == irc.X_DELIM + 'ACTION ':
                    c = irc.ctcpExtract(message)
                    for tag, data in c['extended']:
                        if tag == 'ACTION':
                            self.irc.say(channel, "* %s %s" % (sender, data))
                        else:
                            # Not an action.  Repackage the chunk,
                            msg = "%(X)s%(tag)s %(data)s%(X)s" % {
                                'X': irc.X_DELIM,
                                'tag': tag,
                                'data': data
                                }
                            # ctcpQuote it to render it harmless,
                            msg = irc.ctcpQuote(msg)
                            # and let it continue on.
                            c['normal'].append(msg)

                    for msg in c['normal']:
                        self.irc.say(channel, "<%s> %s" % (sender, msg))
                    return

                elif irc.X_DELIM in message:
                    message = irc.ctcpQuote(message)

                if metadata and metadata.has_key('style'):
                    if metadata['style'] == "emote":
                        self.irc.say(channel, "* %s %s" % (sender, message))
                        return

                self.irc.say(channel, "<%s> %s" % (sender, message))
        else:
            # A message in our errorGroup.
            if message == "participants":
                s = map(lambda i: str(i[0]), self.participants.values())
                s = string.join(s, ", ")
            elif message == "groups":
                s = map(str, self.perspective.groups)
                s = string.join(s, ", ")
            elif message == "transport":
                s = "%s connected: %s" %\
                    (self.transport, getattr(self.transport, "connected"))
            else:
                s = None

            if s:
                self.groupMessage(group, s)
Beispiel #3
0
    def receiveGroupMessage(self, sender, group, message):
        """Pass a message from the Words group on to IRC.

        Or, if it's in our errorGroup, recognize some debugging commands.
        """
        if not (group == self.errorGroup):
            channel = groupToChannelName(group)
            if not self.isThisMine(sender):
                # Test for Special case:
                # got CTCP, probably through words.ircservice
                #      (you SUCK!)
                # ACTION is the only case we'll support here.
                if message[:8] == irc.X_DELIM + 'ACTION ':
                    c = irc.ctcpExtract(message)
                    for tag, data in c['extended']:
                        if tag == 'ACTION':
                            self.say(channel, "* %s %s" % (sender, data))
                        else:
                            # Not an action.  Repackage the chunk,
                            msg = "%(X)s%(tag)s %(data)s%(X)s" % {
                                'X': irc.X_DELIM,
                                'tag': tag,
                                'data': data
                            }
                            # ctcpQuote it to render it harmless,
                            msg = irc.ctcpQuote(msg)
                            # and let it continue on.
                            c['normal'].append(msg)

                    for msg in c['normal']:
                        self.say(channel, "<%s> %s" % (sender, msg))
                    return

                elif irc.X_DELIM in message:
                    message = irc.ctcpQuote(message)

                self.say(channel, "<%s> %s" % (sender, message))
        else:
            # A message in our errorGroup.
            if message == "participants":
                s = map(lambda i: str(i[0]), self.participants.values())
                s = string.join(s, ", ")
            elif message == "groups":
                s = map(str, self.perspective.groups)
                s = string.join(s, ", ")
            elif message == "transport":
                s = "%s connected: %s" %\
                    (self.transport, getattr(self.transport, "connected"))
            else:
                s = None

            if s:
                self.groupMessage(group, s)
Beispiel #4
0
    def irc_PRIVMSG(self, prefix, params):
        """Send a (private) message.

        Parameters: <msgtarget> <text to be sent>

        [REQUIRED]
        """

        name = params[0]
        text = params[-1]
        if self.participant:
            # CTCP -> Words.metadata conversion
            if text[0]==irc.X_DELIM:
                if name[0] == '#':
                    name_ = name[1:]
                    msgMethod = self.participant.groupMessage
                else:
                    name_ = name
                    msgMethod = self.participant.directMessage

                m = irc.ctcpExtract(text)
                for tag, data in m['extended']:
                    metadata = {'style': ctcpToWords(tag)}
                    try:
                        msgMethod(name_, data, metadata)
                    except pb.Error, e:
                        self.receiveDirectMessage("*error*", str(e))
                        log.msg('error sending CTCP query:',str(e))

                if not m['normal']:
                    return

                text = string.join(m['normal'], ' ')

            ## 'bot' handling
            if string.lower(name) == 'contactserv':
                # crude contacts interface
                cmds = string.split(text, ' ', 1)
                if cmds[0] == 'add':
                    self.participant.addContact(cmds[1])
                elif cmds[0] == 'remove':
                    self.participant.removeContact(cmds[1])
                else:
                    self.receiveDirectMessage("ContactServ", "unknown command")
            elif name[0] == '#':
                log.msg( 'talking to channel %s %s %s ' % (self.nickname, prefix, params ))
                channame = name[1:]
                try:
                    self.participant.groupMessage(channame, text)
                except pb.Error, e:
                    self.receiveDirectMessage("*error*", str(e))
                    log.msg('error chatting to channel:',str(e))
Beispiel #5
0
    def msgFromWords(self, toNick, sender, message):
        """Deliver a directMessage as a privmsg over IRC.
        """
        if message[0] != irc.X_DELIM:
            self.msg(toNick, '<%s> %s' % (sender, message))
        else:
            # If there is a CTCP delimeter at the beginning of the
            # message, let's leave it there to accomidate not-so-
            # tolerant clients.
            dcc_data = None
            if message[1:5] == 'DCC ':
                dcc_query = irc.ctcpExtract(message)['extended'][0]
                dcc_data = dcc_query[1]

            if dcc_data:
                desc = "DCC " + irc.dccDescribe(dcc_data)
            else:
                desc = "CTCP request"

            self.msg(toNick, 'The following %s is from %s' % (desc, sender))
            self.msg(toNick, '%s' % (message, ))