From 8c0439c707529fc8c1875c9f438bc16f379df9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Sat, 7 Jul 2018 14:34:51 +0200 Subject: [PATCH] Get rid of ? prefix on Discord --- clients/discord.py | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/clients/discord.py b/clients/discord.py index 492c04a..e008f1f 100644 --- a/clients/discord.py +++ b/clients/discord.py @@ -35,9 +35,9 @@ class DiscordClient(discord.Client): self.logger = logger self.commands = commands self.supported_commands = [ - (re.compile(r'^(?P!|\?)(bella(gram|pics)|insta(gram|bella))$'), self._do_bellagram), - (re.compile(r'^(?P!|\?)yt\s+(?P")?(?P.+)(?(q)")$'), self._do_yt), - (re.compile(r'^(?P!|\?)clip\s+(?P")?(?P.+)(?(q)")$'), self._do_clip), + (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), ] super(DiscordClient, self).__init__() @@ -60,49 +60,40 @@ class DiscordClient(discord.Client): 'the same command again'.format(message.author.mention)) @cooldown(retries=2, timeout=5*60, failure=_cooldown_failure) - async def _do_bellagram(self, user, message, prefix, **kwargs): + async def _do_bellagram(self, user, message, **kwargs): try: bellagram = self.commands.bellagram() except CommandError as e: await self.send_message(message.channel, 'Sorry {0}, {1}'.format(message.author.mention, e)) else: - if prefix == '!': - embed = discord.Embed(title=bellagram['title'], url=bellagram['url'], color=0x8545bc) - embed.set_image(url=bellagram['display_url']) - embed.set_author(name=bellagram['owner'], url=bellagram['owner_url'], - icon_url=bellagram['owner_pic_url']) - await self.send_message(message.channel, embed=embed) - elif prefix == '?': - await self.send_message(message.channel, bellagram['url']) + embed = discord.Embed(title=bellagram['title'], url=bellagram['url'], color=0xd2a517) + embed.set_image(url=bellagram['display_url']) + embed.set_author(name=bellagram['owner'], url=bellagram['owner_url'], + icon_url=bellagram['owner_pic_url']) + await self.send_message(message.channel, embed=embed) @cooldown(retries=3, timeout=5*60, failure=_cooldown_failure) - async def _do_yt(self, user, message, query, prefix, **kwargs): + async def _do_yt(self, user, message, query, **kwargs): try: result = self.commands.query_youtube(query) except CommandError as e: await self.send_message(message.channel, 'Sorry {0}, {1}'.format(message.author.mention, e)) else: - if prefix == '!': + if result['kind'] == 'playlist': embed = discord.Embed(title=result['title'], url=result['url'], description=result['description'], color=0xff0000) embed.set_thumbnail(url=result['thumbnail_url']) embed.set_author(name=result['channel_title'], url=result['channel_url'], icon_url=result['channel_thumbnail_url']) await self.send_message(message.channel, embed=embed) - elif prefix == '?': - await self.send_message(message.channel, result['url']) + else: + await self.send_message(message.channel, '{title}\n{url}'.format(**result)) @cooldown(retries=3, timeout=5*60, failure=_cooldown_failure) - async def _do_clip(self, user, message, filter, prefix, **kwargs): + async def _do_clip(self, user, message, filter, **kwargs): try: result = self.commands.find_clip(filter) except CommandError as e: await self.send_message(message.channel, 'Sorry {0}, {1}'.format(message.author.mention, e)) else: - if prefix == '!': - embed = discord.Embed(title=result['title'], url=result['url'], color=0xff5733) - embed.set_thumbnail(url=result['thumbnail_medium']) - embed.set_author(name=result['curator_display_name'], icon_url=result['curator_logo']) - await self.send_message(message.channel, embed=embed) - elif prefix == '?': - await self.send_message(message.channel, result['url']) + await self.send_message(message.channel, '{title}\n{url}'.format(**result))