Beispiel #1
0
    def apply(self, lexed, first=False, last=False):
        prefix = [q for q in self.quirklist if q.type=='prefix']
        suffix = [q for q in self.quirklist if q.type=='suffix']

        newlist = []
        for (i, o) in enumerate(lexed):
            if type(o) not in [str, unicode]:
                if i == 0:
                    string = " "
                    for p in prefix:
                        string += p.apply(string)
                    newlist.append(string)
                newlist.append(o)
                continue
            lastStr = (i == len(lexed)-1)
            string = o
            for q in self.quirklist:
                if q.type != 'prefix' and q.type != 'suffix':
                    if q.type == 'regexp' or q.type == 'random':
                        string = q.apply(string, first=(i==0), last=lastStr)
                    else:
                        string = q.apply(string)
                elif q.type == 'prefix' and i == 0:
                    string = q.apply(string)
                elif q.type == 'suffix' and lastStr:
                    string = q.apply(string)
            newlist.append(string)

        final = []
        for n in newlist:
            if type(n) in [str, unicode]:
                final.extend(lexMessage(n))
            else:
                final.append(n)
        return final
Beispiel #2
0
    def sentMessage(self):
        text = unicode(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        self.history.add(text)
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd and self.applyquirks:
            try:
                lexmsg = quirks.apply(lexmsg)
            except:
                msgbox = QtGui.QMessageBox()
                msgbox.setText("Whoa there! There seems to be a problem.")
                msgbox.setInformativeText("A quirk seems to be having a problem. (Possibly you're trying to capture a non-existant group?)")
                msgbox.exec_()
                return
        lexmsgs = splitMessage(lexmsg)

        for lm in lexmsgs:
            serverMsg = copy(lm)
            self.addMessage(lm, True)
            # if ceased, rebegin
            if hasattr(self, 'chumopen') and not self.chumopen:
                self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
                self.setChumOpen(True)
            text = convertTags(serverMsg, "ctag")
            self.messageSent.emit(text, self.title())
        self.textInput.setText("")
    def apply(self, lexed, first=False, last=False):
        prefix = [q for q in self.quirklist if q.type=='prefix']
        suffix = [q for q in self.quirklist if q.type=='suffix']

        newlist = []
        for (i, o) in enumerate(lexed):
            if type(o) not in [str, unicode]:
                if i == 0:
                    string = " "
                    for p in prefix:
                        string += p.apply(string)
                    newlist.append(string)
                newlist.append(o)
                continue
            lastStr = (i == len(lexed)-1)
            string = o
            for q in self.quirklist:
                if q.type != 'prefix' and q.type != 'suffix':
                    if q.type == 'regexp' or q.type == 'random':
                        string = q.apply(string, first=(i==0), last=lastStr)
                    else:
                        string = q.apply(string)
                elif q.type == 'prefix' and i == 0:
                    string = q.apply(string)
                elif q.type == 'suffix' and lastStr:
                    string = q.apply(string)
            newlist.append(string)

        final = []
        for n in newlist:
            if type(n) in [str, unicode]:
                final.extend(lexMessage(n))
            else:
                final.append(n)
        return final
Beispiel #4
0
    def sentMessage(self):
        text = str(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        oocDetected = oocre.match(text.strip())
        if self.ooc and not oocDetected:
            text = "(( %s ))" % (text)
        self.history.add(text)
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd and self.applyquirks and not (self.ooc or oocDetected):
            try:
                lexmsg = quirks.apply(lexmsg)
            except:
                msgbox = QtWidgets.QMessageBox()
                msgbox.setText("Whoa there! There seems to be a problem.")
                msgbox.setInformativeText("A quirk seems to be having a problem. (Possibly you're trying to capture a non-existant group?)")
                msgbox.exec_()
                return
        lexmsgs = splitMessage(lexmsg)

        for lm in lexmsgs:
            serverMsg = copy(lm)
            self.addMessage(lm, True)
            # if ceased, rebegin
            if hasattr(self, 'chumopen') and not self.chumopen:
                self.mainwindow.newConvoStarted.emit(self.title(), True)
                self.setChumOpen(True)
            text = convertTags(serverMsg, "ctag")
            self.messageSent.emit(text, self.title())
        self.textInput.setText("")
Beispiel #5
0
    def sentMessage(self):
        text = unicode(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        self.history.add(text)
        if self.time.getTime() == None:
            self.sendtime()
        grammar = self.time.getGrammar()
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd:
            if self.applyquirks:
                lexmsg = quirks.apply(lexmsg)
            initials = self.mainwindow.profile().initials()
            colorcmd = self.mainwindow.profile().colorcmd()
            clientMsg = [colorBegin("<c=%s>" % (colorcmd), colorcmd),
                         "%s%s%s: " % (grammar.pcf, initials, grammar.number)] + lexmsg + [colorEnd("</c>")]
            # account for TC's parsing error
            serverMsg = [colorBegin("<c=%s>" % (colorcmd), colorcmd),
                         "%s: " % (initials)] + lexmsg + [colorEnd("</c>"), " "]
        else:
            clientMsg = copy(lexmsg)
            serverMsg = copy(lexmsg)

        self.addMessage(clientMsg, True)
        serverText = convertTags(serverMsg, "ctag")
        self.messageSent.emit(serverText, self.title())

        self.textInput.setText("")
Beispiel #6
0
 def addMessage(self, msg, me=True):
     if type(msg) in [str, unicode]:
         lexmsg = lexMessage(msg)
     else:
         lexmsg = msg
     if me:
         chum = self.mainwindow.profile()
     else:
         chum = self.chum
         self.notifyNewMessage()
     self.textArea.addMessage(lexmsg, chum)
Beispiel #7
0
 def addMessage(self, msg, me=True):
     if type(msg) in [str, unicode]:
         lexmsg = lexMessage(msg)
     else:
         lexmsg = msg
     if me:
         chum = self.mainwindow.profile()
     else:
         chum = self.chum
         self.notifyNewMessage()
     self.textArea.addMessage(lexmsg, chum)
Beispiel #8
0
    def addMessage(self, msg, chum):
        if type(msg) in [str, unicode]:
            lexmsg = lexMessage(msg)
        else:
            lexmsg = msg
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        chumdb = window.chumdb
        if chum is not me: # SO MUCH WH1T3SP4C3 >:]
            if type(lexmsg[0]) is colorBegin: # get color tag
                colortag = lexmsg[0]
                try:
                    color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
                except ValueError:
                    color = QtGui.QColor("black")
                else:
                    chumdb.setColor(chum.handle, color)
                    parent.updateColor(chum.handle, color)
            else:
                color = chumdb.getColor(chum.handle)
        else:
            color = me.color

        chum.color = color
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        if chum is not me:
            if parent.times.has_key(chum.handle):
                time = parent.times[chum.handle]
                if time.getTime() is None:
                    # MY WAY OR THE HIGHWAY
                    time.addTime(timedelta(0))
            else:
                # new chum! time current
                newtime = timedelta(0)
                time = TimeTracker(newtime)
                parent.times[handle] = time
        else:
            time = parent.time

        if time.isFirstTime():
            grammar = time.getGrammar()
            joinmsg = chum.memojoinmsg(systemColor, time.getTime(), grammar, window.theme["convo/text/joinmemo"])
            self.append(convertTags(joinmsg))
            parent.mainwindow.chatlog.log(parent.channel, joinmsg)
            time.openCurrentTime()

        if type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar())
            window.chatlog.log(parent.channel, memsg)
            self.append(convertTags(memsg))
        else:
            self.append(convertTags(lexmsg))
            window.chatlog.log(parent.channel, lexmsg)
Beispiel #9
0
 def sentMessage(self):
     text = unicode(self.textInput.text())
     if text == "" or text[0:11] == "PESTERCHUM:":
         return
     self.history.add(text)
     quirks = self.mainwindow.userprofile.quirks
     lexmsg = lexMessage(text)
     if type(lexmsg[0]) is not mecmd and self.applyquirks:
         lexmsg = quirks.apply(lexmsg)
     serverMsg = copy(lexmsg)
     self.addMessage(lexmsg, True)
     # if ceased, rebegin
     if hasattr(self, 'chumopen') and not self.chumopen:
         self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
     text = convertTags(serverMsg, "ctag")
     self.messageSent.emit(text, self.title())
     self.textInput.setText("")
Beispiel #10
0
    def apply(self, lexed, first=False, last=False):
        prefix = [q for q in self.quirklist if q.type == 'prefix']
        suffix = [q for q in self.quirklist if q.type == 'suffix']
        replace = [
            q for q in self.quirklist
            if q.type == 'replace' or q.type == 'regexp'
        ]
        randomrep = [q for q in self.quirklist if q.type == 'random']
        spelling = [q for q in self.quirklist if q.type == 'spelling']

        newlist = []
        for (i, o) in enumerate(lexed):
            if type(o) not in [str, unicode]:
                if i == 0:
                    string = " "
                    for p in prefix:
                        string += p.apply(string)
                    newlist.append(string)
                newlist.append(o)
                continue
            lastStr = (i == len(lexed) - 1)
            string = o
            for s in spelling:
                string = s.apply(string)
            for r in randomrep:
                string = r.apply(string, first=(i == 0), last=lastStr)
            for r in replace:
                string = r.apply(string, first=(i == 0), last=lastStr)
            if i == 0:
                if len(prefix) >= 1:
                    myprefix = random.choice(prefix)
                    string = myprefix.apply(string)
            if lastStr:
                if len(suffix) >= 1:
                    mysuffix = random.choice(suffix)
                    string = mysuffix.apply(string)
            newlist.append(string)

        final = []
        for n in newlist:
            if type(n) in [str, unicode]:
                final.extend(lexMessage(n))
            else:
                final.append(n)
        return final
Beispiel #11
0
    def apply(self, lexed, first=False, last=False):
        prefix = [q for q in self.quirklist if q.type=='prefix']
        suffix = [q for q in self.quirklist if q.type=='suffix']
        replace = [q for q in self.quirklist if
                   q.type=='replace' or q.type=='regexp']
        randomrep = [q for q in self.quirklist if q.type=='random']
        spelling = [q for q in self.quirklist if q.type=='spelling']
        
        newlist = []
        for (i, o) in enumerate(lexed):
            if type(o) not in [str, unicode]:
                if i == 0:
                    string = " "
                    for p in prefix:
                        string += p.apply(string)
                    newlist.append(string)
                newlist.append(o)
                continue
            lastStr = (i == len(lexed)-1)
            string = o
            for s in spelling:
                string = s.apply(string)
            for r in randomrep:
                string = r.apply(string, first=(i==0), last=lastStr)
            for r in replace:
                string = r.apply(string, first=(i==0), last=lastStr)
            if i == 0:
                if len(prefix) >= 1:
                    myprefix = random.choice(prefix)
                    string = myprefix.apply(string)
            if lastStr:
                if len(suffix) >= 1:
                    mysuffix = random.choice(suffix)
                    string = mysuffix.apply(string)
            newlist.append(string)

        final = []
        for n in newlist:
            if type(n) in [str, unicode]:
                final.extend(lexMessage(n))
            else:
                final.append(n)
        return final
Beispiel #12
0
    def addMessage(self, msg, chum):
        if type(msg) in [str, unicode]:
            lexmsg = lexMessage(msg)
        else:
            lexmsg = msg
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        if self.mainwindow.config.animations():
            for m in self.urls:
                if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
                    if m.state() == QtGui.QMovie.NotRunning:
                        m.start()
        chumdb = window.chumdb
        if chum is not me: # SO MUCH WH1T3SP4C3 >:]
            if type(lexmsg[0]) is colorBegin: # get color tag
                colortag = lexmsg[0]
                try:
                    color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
                except ValueError:
                    color = QtGui.QColor("black")
                else:
                    chumdb.setColor(chum.handle, color)
                    parent.updateColor(chum.handle, color)
            else:
                color = chumdb.getColor(chum.handle)
        else:
            color = me.color

        chum.color = color
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        if chum is not me:
            if parent.times.has_key(chum.handle):
                time = parent.times[chum.handle]
                if time.getTime() is None:
                    # MY WAY OR THE HIGHWAY
                    time.addTime(timedelta(0))
            else:
                # new chum! time current
                newtime = timedelta(0)
                time = TimeTracker(newtime)
                parent.times[handle] = time
        else:
            time = parent.time

        if time.isFirstTime():
            grammar = time.getGrammar()
            joinmsg = chum.memojoinmsg(systemColor, time.getTime(), grammar, window.theme["convo/text/joinmemo"])
            self.append(convertTags(joinmsg))
            parent.mainwindow.chatlog.log(parent.channel, joinmsg)
            time.openCurrentTime()

        def makeSafe(msg):
            if msg.count("<c") > msg.count("</c>"):
                for i in range(msg.count("<c") - msg.count("</c>")):
                    msg = msg + "</c>"
            return "<span style=\"color:#000000\">" + msg + "</span>"
        if type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar())
            window.chatlog.log(parent.channel, memsg)
            self.append(convertTags(memsg))
        else:
            self.append(makeSafe(convertTags(lexmsg)))
            window.chatlog.log(parent.channel, lexmsg)