mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Compressed history checks into one url loop, failed reaction tweak
This commit is contained in:
parent
0dc968f177
commit
0ebd06c4c1
1 changed files with 56 additions and 86 deletions
|
@ -276,44 +276,30 @@ class MsG:
|
||||||
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
|
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
|
||||||
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
|
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
|
||||||
urls = []
|
urls = []
|
||||||
attachments = []
|
c = 0
|
||||||
|
|
||||||
if not ctx.author.permissions_in(ctx.channel).manage_messages:
|
if not ctx.author.permissions_in(ctx.channel).manage_messages:
|
||||||
dest = ctx.author
|
dest = ctx.author
|
||||||
|
|
||||||
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
|
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
|
||||||
if len(urls) + len(attachments) >= limit:
|
if c >= limit:
|
||||||
break
|
break
|
||||||
if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None:
|
if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments):
|
||||||
urls.append(message)
|
for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
||||||
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
urls.append(match.group(0))
|
||||||
elif message.author.id != self.bot.user.id and message.attachments:
|
for embed in message.embeds:
|
||||||
attachments.append(message)
|
if embed.image.url is not d.Embed.Empty:
|
||||||
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
urls.append(embed.image.url)
|
||||||
|
for attachment in message.attachments:
|
||||||
|
urls.append(attachment.url)
|
||||||
|
|
||||||
if not urls and not attachments:
|
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
||||||
|
c += 1
|
||||||
|
|
||||||
|
if not urls:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
for message in urls:
|
for url in urls:
|
||||||
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
|
||||||
try:
|
|
||||||
await dest.trigger_typing()
|
|
||||||
|
|
||||||
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_post(match.group(0))))
|
|
||||||
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
|
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
|
||||||
|
|
||||||
if remove:
|
|
||||||
with suppress(err.NotFound):
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
except exc.MatchError as e:
|
|
||||||
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
|
||||||
await message.add_reaction('\N{CROSS MARK}')
|
|
||||||
|
|
||||||
for message in attachments:
|
|
||||||
for attachment in message.attachments:
|
|
||||||
try:
|
try:
|
||||||
await dest.trigger_typing()
|
await dest.trigger_typing()
|
||||||
|
|
||||||
|
@ -329,8 +315,12 @@ class MsG:
|
||||||
except exc.MatchError as e:
|
except exc.MatchError as e:
|
||||||
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
||||||
await message.add_reaction('\N{CROSS MARK}')
|
await message.add_reaction('\N{CROSS MARK}')
|
||||||
|
c -= 1
|
||||||
|
|
||||||
|
if c > 0:
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
else:
|
||||||
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await ctx.send('**No matches found**', delete_after=10)
|
await ctx.send('**No matches found**', delete_after=10)
|
||||||
|
@ -346,50 +336,34 @@ class MsG:
|
||||||
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
|
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
|
||||||
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
|
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
|
||||||
urls = []
|
urls = []
|
||||||
attachments = []
|
c = 0
|
||||||
|
|
||||||
if not ctx.author.permissions_in(ctx.channel).manage_messages:
|
if not ctx.author.permissions_in(ctx.channel).manage_messages:
|
||||||
dest = ctx.author
|
dest = ctx.author
|
||||||
|
|
||||||
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
|
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
|
||||||
if len(urls) + len(attachments) >= limit:
|
if c >= limit:
|
||||||
break
|
break
|
||||||
if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None:
|
if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments):
|
||||||
urls.append(message)
|
for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
||||||
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
urls.append(match.group(0))
|
||||||
elif message.author.id != self.bot.user.id and message.attachments:
|
for embed in message.embeds:
|
||||||
attachments.append(message)
|
if embed.image.url is not d.Embed.Empty:
|
||||||
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
urls.append(embed.image.url)
|
||||||
|
for attachment in message.attachments:
|
||||||
|
urls.append(attachment.url)
|
||||||
|
|
||||||
if not urls and not attachments:
|
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
|
||||||
|
c += 1
|
||||||
|
|
||||||
|
if not urls:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
for message in urls:
|
for url in urls:
|
||||||
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
|
||||||
try:
|
try:
|
||||||
await dest.trigger_typing()
|
await dest.trigger_typing()
|
||||||
|
|
||||||
post = await scraper.get_post(match.group(0))
|
post = await scraper.get_post(url)
|
||||||
|
|
||||||
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post)))
|
|
||||||
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
|
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
|
||||||
|
|
||||||
if remove:
|
|
||||||
with suppress(err.NotFound):
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
except exc.MatchError as e:
|
|
||||||
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
|
||||||
await message.add_reaction('\N{CROSS MARK}')
|
|
||||||
|
|
||||||
for message in attachments:
|
|
||||||
for attachment in message.attachments:
|
|
||||||
try:
|
|
||||||
await dest.trigger_typing()
|
|
||||||
|
|
||||||
post = await scraper.get_post(attachment.url)
|
|
||||||
|
|
||||||
await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_image(post)))
|
await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_image(post)))
|
||||||
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
@ -403,8 +377,12 @@ class MsG:
|
||||||
except exc.MatchError as e:
|
except exc.MatchError as e:
|
||||||
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
||||||
await message.add_reaction('\N{CROSS MARK}')
|
await message.add_reaction('\N{CROSS MARK}')
|
||||||
|
c -= 1
|
||||||
|
|
||||||
|
if c > 0:
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
else:
|
||||||
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await ctx.send('**No matches found**', delete_after=10)
|
await ctx.send('**No matches found**', delete_after=10)
|
||||||
|
@ -416,32 +394,24 @@ class MsG:
|
||||||
async def _qualitify(self):
|
async def _qualitify(self):
|
||||||
while self.qualitifying:
|
while self.qualitifying:
|
||||||
message = await self.qualiqueue.get()
|
message = await self.qualiqueue.get()
|
||||||
|
urls = []
|
||||||
|
|
||||||
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
|
||||||
try:
|
urls.append(match.group(0))
|
||||||
await message.channel.trigger_typing()
|
for embed in message.embeds:
|
||||||
|
if embed.image.url is not d.Embed.Empty:
|
||||||
post = await scraper.get_post(match.group(0))
|
urls.append(embed.image.url)
|
||||||
|
|
||||||
await message.channel.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post)))
|
|
||||||
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
|
||||||
|
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
|
||||||
|
|
||||||
with suppress(err.NotFound):
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
except exc.MatchError as e:
|
|
||||||
await message.channel.send('**No probable match for:** `{}`'.format(e), delete_after=10)
|
|
||||||
await message.add_reaction('\N{CROSS MARK}')
|
|
||||||
|
|
||||||
for attachment in message.attachments:
|
for attachment in message.attachments:
|
||||||
|
urls.append(attachment.url)
|
||||||
|
|
||||||
|
for url in urls:
|
||||||
try:
|
try:
|
||||||
await message.channel.trigger_typing()
|
await message.channel.trigger_typing()
|
||||||
|
|
||||||
post = await scraper.get_post(attachment.url)
|
post = await scraper.get_post(url)
|
||||||
|
|
||||||
await message.channel.send('**Probable match from** {}\n{}'.format(message.author.display_name, await scraper.get_image(post)))
|
await message.channel.send('**Probable match from** {}\n{}'.format(message.author.display_name, await scraper.get_image(post)))
|
||||||
|
with suppress(err.NotFound):
|
||||||
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
await asyncio.sleep(self.RATE_LIMIT)
|
||||||
|
|
Loading…
Reference in a new issue