Exemple #1
0
class Bad:
    def __init__(self, path):
        self.lines = FileList(path)

    def bad(self, text):
        bads = []

        for word in re.findall("\w{2,}", text.lower(), re.UNICODE):
            if word in self.lines:
                bads.append(word)

        return bads

    @classmethod
    def __invalid(cls, word):
        return " " in word or len(word) <= 2

    def add(self, word):
        if self.__invalid(word):
            return
        word = word.lower()
        if word not in self.lines:
            self.lines.add(word)

    def remove(self, word):
        if self.__invalid(word):
            return
        word = word.lower()
        if word in self.lines:
            self.lines.remove(word)
Exemple #2
0
class Admin(AdminBase):
    FILE = os.path.join(os.path.dirname(__file__), "../modules/resources/admin.txt")

    def __init__(self):
        self.lines = FileList(self.FILE)

    def is_admin(self, user):
        return self.__get_id(user) in self.lines

    def add(self, current_user, user):
        if not self.is_admin(current_user):
            raise NotAdminException()
        self.lines.add(self.__get_id(user))

    def remove(self, current_user, user):
        if not self.is_admin(current_user):
            raise NotAdminException()
        self.lines.remove(self.__get_id(user))

    @classmethod
    def __get_id(cls, user):
        if isinstance(user, int):
            return str(user)
        if isinstance(user, str):
            return user
        elif isinstance(user, dict):
            return cls.__get_id(user["id"])
        else:
            print("%s is not valid user %s" % (user, type(user)))
Exemple #3
0
class ModuleRage(ModuleBase):
    def __init__(self, bot):
        ModuleBase.__init__(self, bot)
        self.name = "ModuleRage"
        self.ragelist = FileList("botTest/ragelist")

    def notify_command(self, message_id, from_attr, date, chat, commandName,
                       commandStr):
        if commandName == "rage":

            args = commandStr.split(" ")

            if args[0] != '':
                if len(args) > 1:
                    if args[0] == "add":
                        template = " ".join(args[1:])
                        if "$" in template:
                            template = template[:1].upper() + template[1:]
                            self.ragelist.add(template)
                            self.bot.sendMessage(
                                "/rage : template \"%s\" added." % template,
                                chat['id'])
                        else:
                            self.bot.sendMessage(
                                "/rage : Your rage phrase template must contains at least one '$' ",
                                chat['id'])
                        return

                if len(self.ragelist) > 0:
                    try:
                        self.bot.sendMessage(
                            random.choice(self.ragelist.list).replace(
                                "$", " ".join(args)), chat['id'])
                    except:
                        self.bot.sendMessage(
                            "/rage : YOU TRIED TO RAGE BUT THIS IS THE MOTHERFUCKING MODULE THAT RAGE BECAUSE IT'S F****D UP",
                            chat['id'])
                else:
                    self.bot.sendMessage(
                        "/rage : First add a rage template please.",
                        chat['id'])
            else:
                self.bot.sendMessage("/rage : Arguments missing", chat['id'])

    def get_commands(self):
        return [
            ("rage",
             "Eh bah, ça rage du cul ? Keyword: add <rage template with '$' placeholder> | <thing against you rage>"
             ),
        ]
    def test_add_remove(self):
        word = str(uuid.uuid4()).replace("-", "")
        print(word)
        list = FileList(self.FILE)
        n = len(list)

        self.assertFalse(word in list)

        list.add(word)

        self.assertTrue(word in list)
        self.assertEqual(len(list), n + 1)

        list.remove(word)

        self.assertFalse(word in list)
        self.assertEqual(len(list), n)
Exemple #5
0
class ModuleRage(ModuleBase):
    def __init__(self, bot):
        ModuleBase.__init__(self, bot)
        self.name = "ModuleRage"
        self.ragelist = FileList("botTest/ragelist")

    def notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):
        if commandName == "rage":

            args = commandStr.split(" ")

            if args[0] != "":
                if len(args) > 1:
                    if args[0] == "add":
                        template = " ".join(args[1:])
                        if "$" in template:
                            template = template[:1].upper() + template[1:]
                            self.ragelist.add(template)
                            self.bot.sendMessage('/rage : template "%s" added.' % template, chat["id"])
                        else:
                            self.bot.sendMessage(
                                "/rage : Your rage phrase template must contains at least one '$' ", chat["id"]
                            )
                        return

                if len(self.ragelist) > 0:
                    try:
                        self.bot.sendMessage(random.choice(self.ragelist.list).replace("$", " ".join(args)), chat["id"])
                    except:
                        self.bot.sendMessage(
                            "/rage : YOU TRIED TO RAGE BUT THIS IS THE MOTHERFUCKING MODULE THAT RAGE BECAUSE IT'S F****D UP",
                            chat["id"],
                        )
                else:
                    self.bot.sendMessage("/rage : First add a rage template please.", chat["id"])
            else:
                self.bot.sendMessage("/rage : Arguments missing", chat["id"])

    def get_commands(self):
        return [
            (
                "rage",
                "Eh bah, ça rage du cul ? Keyword: add <rage template with '$' placeholder> | <thing against you rage>",
            )
        ]
    def test_add_remove(self):
        word = str(uuid.uuid4()).replace("-", "")
        print(word)
        list = FileList(self.FILE)
        n = len(list)

        self.assertFalse(word in list)

        list.add(word)

        self.assertTrue(word in list)
        self.assertEqual(len(list), n + 1)

        list.remove(word)

        self.assertFalse(word in list)
        self.assertEqual(len(list), n)
Exemple #7
0
 def __init__(self):
     self.lines = FileList(self.FILE)
Exemple #8
0
 def __init__(self, bot):
     ModuleBase.__init__(self, bot)
     self.name = "ModuleRage"
     self.ragelist = FileList("botTest/ragelist")
Exemple #9
0
 def __init__(self, bot):
     ModuleBase.__init__(self, bot)
     self.name = "ModuleRage"
     self.ragelist = FileList("botTest/ragelist")
Exemple #10
0
 def __init__(self, path):
     self.lines = FileList(path)