From 6f0b31cb9a516b1411ea7e0e592661dea22ca5f0 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 18 May 2019 19:20:09 +0100 Subject: [PATCH] Switch imgur.py to use command.regex system --- modules/imgur.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/imgur.py b/modules/imgur.py index 9804c96f..feefcb92 100644 --- a/modules/imgur.py +++ b/modules/imgur.py @@ -26,24 +26,22 @@ class Module(ModuleManager.BaseModule): text += "%s " % data["account_url"] return text - @utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW) - def channel_message(self, event): + @utils.hook("command.regex", pattern=REGEX_IMAGE) + def _regex_image(self, event): + """ + :command: imgur + """ if event["channel"].get_setting("auto-imgur", False): - match_gallery = REGEX_GALLERY.match(event["message"]) - match_image = REGEX_IMAGE.match(event["message"]) - - result = None - if match_gallery: - result = self._parse_gallery(match_gallery.group(1)) - elif match_image: - result = self._parse_image(match_image.group(1)) - else: - return - + event["stdout"].write(self._parse_image(event["match"].group(1))) + event.eat() + @utils.hook("command.regex", pattern=REGEX_GALLERY) + def _regex_gallery(self, event): + """ + :command: imgur + """ + if event["channel"].get_setting("auto-imgur", False): + event["stdout"].write(self._parse_gallery(event["match"].group(1))) event.eat() - - self.events.on("send.stdout").call(target=event["channel"], - module_name="Imgur", server=event["server"], message=result) def _parse_gallery(self, hash): api_key = self.bot.config["imgur-api-key"]