Пример #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])
Пример #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)),
        ]
Пример #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)),
        ]