예제 #1
0
파일: dc.py 프로젝트: LiPeK/dtella
    def d_PrivateMsg(self, nick, _1, _2, _3, text):

        text = remove_dc_escapes(text)
        
        if nick == self.bot.nick:

            # No ! is needed for commands in the private message context
            if text[:1] == '!':
                text = text[1:]

            def out(text):
                if text is not None:
                    self.bot.say(text)
            
            self.bot.commandInput(out, text)
            return

        if len(text) > 10:
            shorttext = text[:10] + '...'
        else:
            shorttext = text

        def fail_cb(detail):
            self.pushPrivMsg(
                nick,
                "*** Your message \"%s\" could not be sent: %s"
                % (shorttext, detail))

        if not self.isOnline():
            fail_cb("You're not online.")
            return

        try:
            n = self.main.osm.nkm.lookupNick(nick)
        except KeyError:
            fail_cb("User doesn't seem to exist.")
            return

        n.event_PrivateMessage(self.main, text, fail_cb)
예제 #2
0
    def d_PrivateMsg(self, nick, _1, _2, _3, text):

        text = remove_dc_escapes(text)

        if nick == self.bot.nick:

            # No ! is needed for commands in the private message context
            if text[:1] == '!':
                text = text[1:]

            def out(text):
                if text is not None:
                    self.bot.say(text)

            self.bot.commandInput(out, text)
            return

        if len(text) > 10:
            shorttext = text[:10] + '...'
        else:
            shorttext = text

        def fail_cb(detail):
            self.pushPrivMsg(
                nick, "*** Your message \"%s\" could not be sent: %s" %
                (shorttext, detail))

        if not self.isOnline():
            fail_cb("You're not online.")
            return

        try:
            n = self.main.osm.nkm.lookupNick(nick)
        except KeyError:
            fail_cb("User doesn't seem to exist.")
            return

        n.event_PrivateMessage(self.main, text, fail_cb)
예제 #3
0
파일: dc.py 프로젝트: LiPeK/dtella
    def d_PublicMsg(self, text):

        text = remove_dc_escapes(text)

        # Route commands to the bot
        if text[:1] == '!':

            def out(out_text, flag=[True]):

                # If the bot produces output, inject our text input before
                # the first line.
                if flag[0]:
                    self.pushStatus("You commanded: %s" % text)
                    flag[0] = False

                if out_text is not None:
                    self.pushStatus(out_text)
            
            if self.bot.commandInput(out, text[1:], '!'):
                return

        if not self.isOnline():
            self.pushStatus("*** You must be online to chat!")
            return

        if self.main.osm.isModerated():
            self.pushStatus(
                "*** Can't send text; the chat is currently moderated.")
            return

        text = text.replace('\r\n','\n').replace('\r','\n')

        for line in text.split('\n'):

            # Skip empty lines
            if not line:
                continue

            # Limit length
            if len(line) > 1024:
                line = line[:1024-12] + ' [Truncated]'

            flags = 0

            # Check for /me
            if len(line) > 4 and line[:4].lower() in ('/me ','+me ','!me '):
                line = line[4:]
                flags |= core.SLASHME_BIT

            # Check rate limiting
            if self.chat_counter > 0:

                # Send now
                self.chat_counter -= 1
                self.broadcastChatMessage(flags, line)

            else:
                # Put in a queue
                if len(self.chatq) < 5:
                    self.chatq.append( (flags, line) )
                else:
                    self.pushStatus(
                        "*** Chat throttled.  Stop typing so much!")
                    break
예제 #4
0
    def d_PublicMsg(self, text):

        text = remove_dc_escapes(text)

        # Route commands to the bot
        if text[:1] == '!':

            def out(out_text, flag=[True]):

                # If the bot produces output, inject our text input before
                # the first line.
                if flag[0]:
                    self.pushStatus("You commanded: %s" % text)
                    flag[0] = False

                if out_text is not None:
                    self.pushStatus(out_text)

            if self.bot.commandInput(out, text[1:], '!'):
                return

        if not self.isOnline():
            self.pushStatus("*** You must be online to chat!")
            return

        if self.main.osm.isModerated():
            self.pushStatus(
                "*** Can't send text; the chat is currently moderated.")
            return

        text = text.replace('\r\n', '\n').replace('\r', '\n')

        for line in text.split('\n'):

            # Skip empty lines
            if not line:
                continue

            # Limit length
            if len(line) > 1024:
                line = line[:1024 - 12] + ' [Truncated]'

            flags = 0

            # Check for /me
            if len(line) > 4 and line[:4].lower() in ('/me ', '+me ', '!me '):
                line = line[4:]
                flags |= core.SLASHME_BIT

            # Check rate limiting
            if self.chat_counter > 0:

                # Send now
                self.chat_counter -= 1
                self.broadcastChatMessage(flags, line)

            else:
                # Put in a queue
                if len(self.chatq) < 5:
                    self.chatq.append((flags, line))
                else:
                    self.pushStatus(
                        "*** Chat throttled.  Stop typing so much!")
                    break