Example #1
0
        def passiveCorrector(self, server, line) -> "privmsg":
            msg = Message(line)
            nick = msg.address.nick
            if not self.dictionary.check(nick):
                self.dictionary.add(nick)
            nick = server.lower(nick)
            if msg.text and msg.text[0] in "@!.:`~/":
                return
            if msg.text.startswith("\x01ACTION") and msg.text.endswith("\x01"):
                data = self.spellcheck(msg.text[8:-1])
            else:
                data = self.spellcheck(msg.text)

            user = self.users.setdefault(nick, [0, 0])
            user[0] += len(data) if data else 0
            user[1] += len(line.split(" ")) - 3
            if user[1] > self.reset_at:
                user[0] /= self.reset_to
                user[1] /= self.reset_to

            if data:
                with sqlite3.connect(self.db) as typos:
                    for i in data:
                        typos.execute(
                            "INSERT INTO typos VALUES (?, ?, ?, ?, ?)",
                            (time.time(), nick, msg.context, self.name, i))

                threshhold_context = self.getSettings(msg.context)
                threshhold_user = self.getSettings(nick)
                if threshhold_user == threshhold_context == None:
                    return

                threshhold = min(threshhold_context,
                                 threshhold_user,
                                 key=lambda x: float("inf")
                                 if x is None else x)

                if user[1] and 1000 * user[0] / user[1] > threshhold:
                    sentence_substitute = ircstrip(msg.text)
                    if sentence_substitute.startswith(
                            "\x01ACTION") and sentence_substitute.endswith(
                                "\x01"):
                        sentence_substitute = "%s %s" % (
                            msg.address.nick, sentence_substitute[8:-1])
                    for word, sub in data.items():
                        sentence_substitute = sentence_substitute.replace(
                            word, "\x02%s\x02" %
                            sub[0] if sub else strikethrough(word))
                    server.message(
                        ("%s: " % msg.address.nick) + sentence_substitute,
                        msg.context)
                    if len(data) == 1:
                        self.last = list(data.keys())[0]
                    else:
                        self.last = None
Example #2
0
 def display(self, num, line, strike=False):
     points = re.split(r"\s*(\[(?:\d+/)?\d+\])\s*", line, maxsplit=1)
     vis = "│"
     if len(points) == 3:
         line = "%s %s" % (points[0], points[-1])
         points = [float(x) for x in points[1][1:-1].split("/")]
         align = math.ceil(points[-1]/5) * 5
         total = points[-1]
         if len(points) > 1:
             done = points[0]
         else:
             done = 0
         vis = '┝' + "━" * math.ceil(total - done) + '15' + "─" * math.ceil(done) + " " * (align - math.ceil(total))
     line = re.sub(r"(^| )(#|\+|@)(\S+)", lambda x: r"%s%.2d%s" % (x.group(1), {"#":15,"+":15,"@":6}[x.group(2)], smallcaps(x.group(3))), line)
     if strike: line = strikethrough(line)
     return "06│ %s %s %s" % (num, vis, line)
Example #3
0
    def pop(self, server, msg, query):
        nick = server.lower(msg.address.nick)
        queue = self.queues.setdefault(nick, [])

        if not queue:
            yield "06│ Your queue is empty. "
            return

        if not query: 
            query = "1"

        q = self.find(queue, query)

        if not q:
            yield "06│ No matching items."
            return

        for i in sorted(q, key=lambda x:-x[0]):
            queue.pop(i[0]-1)

        yield from self.displayAll([('✓' if len(q) == 1 else i[0], strikethrough(i[1])) for i in q], 25 if msg.prefix == '!' else 5)

        self.save()
Example #4
0
    def display(self, num, line, strike=False):
        points = re.split(r"\s*(\[(?:\d+/)?\d+\])\s*", line, maxsplit=1)
        vis, line = priority_vis(line)

        if len(points) == 3:
            line = "%s %s" % (points[0], points[-1])
            points = [float(x) for x in points[1][1:-1].split("/")]
            align = math.ceil(points[-1] / 5) * 5
            total = points[-1]
            if len(points) > 1:
                done = points[0]
            else:
                done = 0
            vis += "━" * math.ceil(total - done) + '15' + "─" * math.ceil(
                done) + " " * (align - math.ceil(total))
        line = re.sub(
            r"(^| )(#|\+|@)(\S+)", lambda x: r"%s%.2d%s" % (x.group(1), {
                "#": 15,
                "+": 15,
                "@": 6
            }[x.group(2)], smallcaps(x.group(3))), line)
        if strike:
            line = strikethrough(line)
        return "06│ %s %s %s" % (num, vis, line)
Example #5
0
        def passiveCorrector(self, server, line) -> "privmsg":
            msg = Message(line)
            nick = msg.address.nick
            if not self.dictionary.check(nick):
                self.dictionary.add(nick)
            nick = server.lower(nick)
            if msg.text and msg.text[0] in "@!.:`~/": 
                return
            if msg.text.startswith("\x01ACTION") and msg.text.endswith("\x01"):
                data = self.spellcheck(msg.text[8:-1])
            else:
                data = self.spellcheck(msg.text)

            user = self.users.setdefault(nick, [0, 0])
            user[0] += len(data) if data else 0
            user[1] += len(line.split(" ")) - 3
            if user[1] > self.reset_at:
                user[0] /= self.reset_to
                user[1] /= self.reset_to

            if data:
                with sqlite3.connect(self.db) as typos:
                    for i in data:
                        typos.execute("INSERT INTO typos VALUES (?, ?, ?, ?, ?)", (time.time(), nick, msg.context, self.name, i))

                threshhold_context = self.getSettings(msg.context)
                threshhold_user = self.getSettings(nick)
                if threshhold_user == threshhold_context == None:
                    return
                
                threshhold = min(threshhold_context, threshhold_user, key=lambda x: float("inf") if x is None else x)

                if user[1] and 1000*user[0]/user[1] > threshhold:
                    sentence_substitute = ircstrip(msg.text)
                    if sentence_substitute.startswith("\x01ACTION") and sentence_substitute.endswith("\x01"):
                        sentence_substitute = "%s %s" % (msg.address.nick, sentence_substitute[8:-1])
                    for word, sub in data.items():
                        sentence_substitute = sentence_substitute.replace(word, "\x02%s\x02" % sub[0] if sub else strikethrough(word))
                    server.message(("%s: " % msg.address.nick) + sentence_substitute, msg.context)
                    if len(data) == 1:
                        self.last = list(data.keys())[0]
                    else:
                        self.last = None