<commit_before># -*- coding: utf-8 -*-
import bot
import fnmatch


class Module(bot.Module):

    index = "autoop"

    def register(self):
        self.w = {}
        self.tmpw = {}
        self.addsetting('#enabled', True)
        self.addhook("self.join", "self.join", self.join)
        self.addhook("recv", "recv", self.recv)
        self.addtimer(self.timer, 'timer', 20 * 1000)
        self.addcommand(
            self.auto,
            "autoop",
            "Modify a channel's +w mode list. autoop add/remove o/v *@host",
            ["[channel]", "operation", "mode", "mask"],
            recognizers={'channel': self.server.ischannel})
        self.addcommand(
            self.autolist,
            "autoop list",
            "View a channel's +w list.",
            ["[channel]"],
            recognizers={'channel': self.server.ischannel})

    def autolist(self, context, args):
        if context.channel:
            args.default("channel", context.channel)
        context.exceptrights([args.getstr('channel') + ",op"])
        w = (self.w[args.getstr("channel")]
            if args.getstr("channel") in self.w else [])
        out = []
        for x in w:
            out.append("%s:%s" % (x["level"], x["glob"]))
        return ", ".join(out) or "No results."

    def auto(self, context, args):
        if context.channel:
            args.default("channel", context.channel)
        context.exceptrights([args.getstr('channel') + ",op"])
        insert = {
            "level": args.getstr("mode")[0],
            "glob": args.getstr("mask"),
        }
        if args.getstr("channel") not in self.server.channels:
            return "The bot is not joined there."
        names = self.server.channels[args.getstr("channel")].names
        if self.server.nick not in names or 'o' not in names[self.server.nick]:
            return "The bot does not have sufficient elevation."
        inw = (args.getstr("channel") in self.w and
            insert in self.w[args.getstr("channel")])
        if args.getstr("operation") == "add":
            if inw:
                return "That is already in the +w list."
            else:
                self.server.send("MODE %s +w %s:%s" % (
                    args.getstr("channel"), insert["level"], insert["glob"]))
                return "" if context.channel else "Done."
        elif args.getstr("operation") == "remove":
            if inw:
                self.server.send("MODE %s -w %s:%s" % (
                    args.getstr("channel"), insert["level"], insert["glob"]))
                return "" if context.channel else "Done."
            else:
                return "Cannot find that in the +w list."

        return "The operation must be add or remove."

    def join(self, channel):
        if not self.getchannelsetting('enabled', channel):
            return
        self.server.send("MODE %s +w" % channel)

    def timer(self):
        for channel in self.server.channels:
            if not self.getchannelsetting('enabled', channel):
                return
            self.server.send("MODE %s +w" % channel)
<commit_msg>more +w checking<commit_after># -*- coding: utf-8 -*-
import bot
import fnmatch


class Module(bot.Module):

    index = "autoop"

    def register(self):
        self.w = {}
        self.tmpw = {}
        self.addsetting('#enabled', True)
        self.addhook("join", "join", self.join)
        self.addhook("recv", "recv", self.recv)
        self.addtimer(self.timer, 'timer', 20 * 1000)
        self.addcommand(
            self.auto,
            "autoop",
            "Modify a channel's +w mode list. autoop add/remove o/v *@host",
            ["[channel]", "operation", "mode", "mask"],
            recognizers={'channel': self.server.ischannel})
        self.addcommand(
            self.autolist,
            "autoop list",
            "View a channel's +w list.",
            ["[channel]"],
            recognizers={'channel': self.server.ischannel})

    def autolist(self, context, args):
        if context.channel:
            args.default("channel", context.channel)
        context.exceptrights([args.getstr('channel') + ",op"])
        w = (self.w[args.getstr("channel")]
            if args.getstr("channel") in self.w else [])
        out = []
        for x in w:
            out.append("%s:%s" % (x["level"], x["glob"]))
        return ", ".join(out) or "No results."

    def auto(self, context, args):
        if context.channel:
            args.default("channel", context.channel)
        context.exceptrights([args.getstr('channel') + ",op"])
        insert = {
            "level": args.getstr("mode")[0],
            "glob": args.getstr("mask"),
        }
        if args.getstr("channel") not in self.server.channels:
            return "The bot is not joined there."
        names = self.server.channels[args.getstr("channel")].names
        if self.server.nick not in names or 'o' not in names[self.server.nick]:
            return "The bot does not have sufficient elevation."
        inw = (args.getstr("channel") in self.w and
            insert in self.w[args.getstr("channel")])
        if args.getstr("operation") == "add":
            if inw:
                return "That is already in the +w list."
            else:
                self.server.send("MODE %s +w %s:%s" % (
                    args.getstr("channel"), insert["level"], insert["glob"]))
                return "" if context.channel else "Done."
        elif args.getstr("operation") == "remove":
            if inw:
                self.server.send("MODE %s -w %s:%s" % (
                    args.getstr("channel"), insert["level"], insert["glob"]))
                return "" if context.channel else "Done."
            else:
                return "Cannot find that in the +w list."

        return "The operation must be add or remove."

    def join(self, channel, user):
        if not self.getchannelsetting('enabled', channel):
            return
        self.server.send("MODE %s +w" % channel)

    def timer(self):
        for channel in self.server.channels:
            if not self.getchannelsetting('enabled', channel):
                return
            self.server.send("MODE %s +w" % channel)

{'fraction_non_alphanumeric': 0.15050651230101303, 'fraction_numerical': 0.0025727608940344106, 'mean_word_length': 1.9011194029850746, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '355545', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1741, 'n_words': 465}