From 414d50f7caa60b438525c7e539515ce94bb1e3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 20 Jul 2018 17:50:55 +0200 Subject: [PATCH] Add act_as_proxy config option and enable quotes on Discord --- clients/discord.py | 18 ++++++++++++++++++ clients/twitch.py | 10 ++++++++-- settings.cfg.example | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/clients/discord.py b/clients/discord.py index 4649ea1..6da8a38 100644 --- a/clients/discord.py +++ b/clients/discord.py @@ -36,6 +36,8 @@ class DiscordClient(discord.Client): self.logger = logger self.commands = commands self.supported_commands = [ + (re.compile(r'^!lastquote$'), self._do_lastquote), + (re.compile(r'^!findquote\s+(?P")?(?P.+)(?(q)")$'), self._do_findquote), (re.compile(r'^!(bella(gram|pics)|insta(gram|bella))$'), self._do_bellagram), (re.compile(r'^!yt\s+(?P")?(?P.+)(?(q)")$'), self._do_yt), (re.compile(r'^!clip\s+(?P")?(?P.+)(?(q)")$'), self._do_clip), @@ -64,6 +66,22 @@ class DiscordClient(discord.Client): 'Sorry {0}, you have to wait a while before running ' 'the same command again'.format(message.author.mention)) + async def _do_lastquote(self, server, user, message, **kwargs): + try: + result = self.commands.last_quote() + except CommandError as e: + await self.send_message(message.channel, 'Sorry {0}, {1}'.format(message.author.mention, e)) + else: + await self.send_message(message.channel, 'One time, Lilia said this... `#{id}: {text} [{game}] [{date}]`'.format(**result)) + + async def _do_findquote(self, server, user, message, filter, **kwargs): + try: + result = self.commands.find_quote(filter) + except CommandError as e: + await self.send_message(message.channel, 'Sorry {0}, {1}'.format(message.author.mention, e)) + else: + await self.send_message(message.channel, 'One time, Lilia said this... `#{id}: {text} [{game}] [{date}]`'.format(**result)) + @cooldown(retries=2, timeout=5*60, failure=_cooldown_failure) async def _do_bellagram(self, server, user, message, **kwargs): try: diff --git a/clients/twitch.py b/clients/twitch.py index e5ec914..eba7b44 100644 --- a/clients/twitch.py +++ b/clients/twitch.py @@ -131,7 +131,10 @@ class TwitchClient(irc.bot.SingleServerIRCBot): except CommandError as e: send_response('Sorry @{0}, {1}'.format(tags['display-name'], e)) else: - send_response('!quote {0}'.format(quote['id'])) + if self.config['Quotes'].getboolean('act_as_proxy'): + send_response('!quote {0}'.format(quote['id'])) + else: + send_response('One time, Lilia said this... #{id}: "{text}" [{game}] [{date}]'.format(**quote)) def _do_findquote(self, tags, send_response, filter, **kwargs): try: @@ -139,7 +142,10 @@ class TwitchClient(irc.bot.SingleServerIRCBot): except CommandError as e: send_response('Sorry @{0}, {1}'.format(tags['display-name'], e)) else: - send_response('!quote {0}'.format(quote['id'])) + if self.config['Quotes'].getboolean('act_as_proxy'): + send_response('!quote {0}'.format(quote['id'])) + else: + send_response('One time, Lilia said this... #{id}: "{text}" [{game}] [{date}]'.format(**quote)) def _do_syncquotes(self, tags, send_response, **kwargs): master_user_id = self.config['Twitch'].getint('master_user_id') diff --git a/settings.cfg.example b/settings.cfg.example index 25073b8..f89269a 100644 --- a/settings.cfg.example +++ b/settings.cfg.example @@ -25,6 +25,7 @@ channel_ids = UC5970RJMoEcRNZl0MNp8tlQ,UCHNjavmkFUf2n0uzWSgj16w [Quotes] api_url = https://ladylilia.com/quotes/api api_key = __QUOTES_API_KEY__ +act_as_proxy = true [Extra Commands] ;!command = Response Text