Ejemplo n.º 1
0
 def test_parse(self):
     nsfw = Nsfw(logging.getLogger("TestNsfw"))
     for arg in self.PARSE_ARGS:
         res = nsfw.parse(arg[0])
         self.assertEqual(res.mode(), arg[1], "mode for '%s'" % arg[0])
         self.assertEqual(res.known(), arg[2], "known for '%s'" % arg[0])
         self.assertEqual(res.unknown(), arg[3], "unknown for '%s'" % arg[0])
Ejemplo n.º 2
0
class ModuleNSFW(ModuleBase):
    def __init__(self, bot):
        ModuleBase.__init__(self, bot)
        self.name = "NSFW"
        self.nsfw = Nsfw(self.logger)
        self.limitator = LimitatorMultiple(
            Limitator(5, 60, True),
            Limitator(50, 600, False),
        )

    def notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):
        if commandName == "bonjour":
            if commandStr == "":
                text = "Bonjours : %s" % ", ".join(self.nsfw.bonjours)
                self.bot.sendMessage(text, chat["id"])
                return
            parserResult = self.nsfw.parse(commandStr)
            if len(parserResult.unknown()) > 0:
                self.bot.sendMessage("bonjour '%s' not found" % "', '".join(parserResult.unknown()), chat["id"])
            try:
                for key in parserResult.known():
                    self.limitator.next(from_attr)
                    result = self.nsfw.image(key, parserResult.mode())
                    if result.ok():
                        self.bot.sendPhotoUrl(chat["id"], result.url(), result.message())
                    else:
                        self.bot.sendMessage(result.message(), chat["id"])
            except LimitatorLimitted:
                self.bot.sendMessage("N'abuse pas mon petit cochon !", chat["id"])


    def get_commands(self):
        return [
            ("bonjour", "Bonjour. Keywords: <%s> <last/random>" % "/".join(self.nsfw.bonjours)),
        ]
Ejemplo n.º 3
0
class ModuleNSFW(ModuleBase):
    def __init__(self, bot):
        ModuleBase.__init__(self, bot)
        self.name = "NSFW"
        self.nsfw = Nsfw(self.logger)
        self.limitator = LimitatorMultiple(
            Limitator(5, 60, True),
            Limitator(50, 600, False),
        )

    def notify_command(self, message_id, from_attr, date, chat, commandName, commandStr):
        if commandName == "bonjour":
            if commandStr == "":
                text = "Bonjours : %s" % ", ".join(self.nsfw.bonjours_keys)
                self.bot.sendMessage(text, chat["id"])
                return
            parserResult = self.nsfw.parse(commandStr)
            if len(parserResult.unknown()) > 0:
                self.bot.sendMessage("bonjour '%s' not found" % "', '".join(parserResult.unknown()), chat["id"])
            try:
                for key in parserResult.known():
                    self.limitator.next(from_attr)
                    result = self.nsfw.image(key, parserResult.mode())
                    if result.ok():
                        self.bot.sendPhotoUrl(chat["id"], result.url(), result.message())
                    else:
                        self.bot.sendMessage(result.message(), chat["id"])
            except LimitatorLimitted:
                self.bot.sendMessage("N'abuse pas mon petit cochon !", chat["id"])

    def get_commands(self):
        return [
            ("bonjour", "Bonjour. Keywords: <%s> <last/random>" % "/".join(self.nsfw.bonjours_keys)),
        ]
Ejemplo n.º 4
0
 def __init__(self, bot):
     ModuleBase.__init__(self, bot)
     self.name = "NSFW"
     self.nsfw = Nsfw(self.logger)
     self.limitator = LimitatorMultiple(
         Limitator(5, 60, True),
         Limitator(50, 600, False),
     )
Ejemplo n.º 5
0
 def test_all(self):
     modes = (
         ("last", 1),
         ("random", 5),
     )
     nsfw = Nsfw(logging.getLogger("TestNsfw"))
     for name in nsfw.bonjours:
         for mode, n in modes:
             print("%s : %s" % (name, mode))
             for i in range(n):
                 res = nsfw.image(name, mode)
                 self.assertTrue(res.ok(), "%s : %s" % (name, mode))
Ejemplo n.º 6
0
 def __init__(self, bot):
     ModuleBase.__init__(self, bot)
     self.name = "ModuleRandom"
     self.nsfw = Nsfw(self.logger)
     self.images_type = list(
         [i for i in self.nsfw.bonjours.keys() if i != "monsieur"])
     self.bullshit = Bullshit()
Ejemplo n.º 7
0
 def __init__(self, bot):
     ModuleBase.__init__(self, bot)
     self.name = "NSFW"
     self.nsfw = Nsfw(self.logger)
     self.limitator = LimitatorMultiple(
         Limitator(5, 60, True),
         Limitator(50, 600, False),
     )
Ejemplo n.º 8
0
 def name_mode(self, name, mode):
     n = 5 if mode == "random" else 1
     nsfw = Nsfw(logging.getLogger("TestNsfw"))
     for i in range(n):
         res = nsfw.image(name, mode)
         self.assertTrue(res.ok())