1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-25 06:37:29 +00:00

Remove manual rate limiting

discord.py now handles this internally
This commit is contained in:
Dylan Dizon 2018-11-03 17:00:36 -04:00
parent 8fb637396e
commit fc1d00eff0
4 changed files with 17 additions and 53 deletions

View file

@ -28,7 +28,6 @@ class MsG:
self.bot = bot self.bot = bot
self.LIMIT = 100 self.LIMIT = 100
self.HISTORY_LIMIT = 150 self.HISTORY_LIMIT = 150
self.RATE_LIMIT = u.RATE_LIMIT
self.reversiqueue = asyncio.Queue() self.reversiqueue = asyncio.Queue()
self.heartqueue = asyncio.Queue() self.heartqueue = asyncio.Queue()
self.reversifying = False self.reversifying = False
@ -132,16 +131,12 @@ class MsG:
if isinstance(temp[1], d.Embed): if isinstance(temp[1], d.Embed):
await temp[0].send(embed=temp[1]) await temp[0].send(embed=temp[1])
await asyncio.sleep(self.RATE_LIMIT)
elif isinstance(temp[1], d.Message): elif isinstance(temp[1], d.Message):
for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', temp[1].content): for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', temp[1].content):
await temp[0].send(match) await temp[0].send(match)
await asyncio.sleep(self.RATE_LIMIT)
for attachment in temp[1].attachments: for attachment in temp[1].attachments:
await temp[0].send(attachment.url) await temp[0].send(attachment.url)
await asyncio.sleep(self.RATE_LIMIT)
print('STOPPED : hearting') print('STOPPED : hearting')
@ -240,21 +235,17 @@ class MsG:
await dest.trigger_typing() await dest.trigger_typing()
for tag in tags: for tag in tags:
try: tag_request = await u.fetch('https://e621.net/tag/related.json', params={'tags': tag}, json=True)
tag_request = await u.fetch('https://e621.net/tag/related.json', params={'tags': tag}, json=True) for rel in tag_request.get(tag, []):
for rel in tag_request.get(tag, []): related.append(rel[0])
related.append(rel[0])
if related: if related:
await dest.send('`{}` **related tags:**\n```\n{}```'.format(tag, formatter.tostring(related))) await dest.send('`{}` **related tags:**\n```\n{}```'.format(tag, formatter.tostring(related)))
else: else:
await ctx.send(f'**No related tags found for:** `{tag}`', delete_after=7) await ctx.send(f'**No related tags found for:** `{tag}`', delete_after=7)
related.clear() related.clear()
c += 1 c += 1
finally:
await asyncio.sleep(self.RATE_LIMIT)
if not c: if not c:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@ -270,21 +261,17 @@ class MsG:
await dest.trigger_typing() await dest.trigger_typing()
for tag in tags: for tag in tags:
try: alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True)
alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True) for dic in alias_request:
for dic in alias_request: aliases.append(dic['name'])
aliases.append(dic['name'])
if aliases: if aliases:
await dest.send('`{}` **aliases:**\n```\n{}```'.format(tag, formatter.tostring(aliases))) await dest.send('`{}` **aliases:**\n```\n{}```'.format(tag, formatter.tostring(aliases)))
else: else:
await ctx.send(f'**No aliases found for:** `{tag}`', delete_after=7) await ctx.send(f'**No aliases found for:** `{tag}`', delete_after=7)
aliases.clear() aliases.clear()
c += 1 c += 1
finally:
await asyncio.sleep(self.RATE_LIMIT)
if not c: if not c:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@ -305,10 +292,9 @@ class MsG:
raise exc.MissingArgument raise exc.MissingArgument
for ident in posts: for ident in posts:
try: await dest.trigger_typing()
await dest.trigger_typing()
ident = ident if not ident.isdigit() else re.search( ident = ident if not ident.isdigit() else re.search(
'show/([0-9]+)', ident).group(1) 'show/([0-9]+)', ident).group(1)
post = await u.fetch('https://e621.net/post/show.json', params={'id': ident}, json=True) post = await u.fetch('https://e621.net/post/show.json', params={'id': ident}, json=True)
@ -317,13 +303,8 @@ class MsG:
embed.set_thumbnail(url=post['file_url']) embed.set_thumbnail(url=post['file_url'])
embed.set_author(name=f'{post["width"]} x {post["height"]}', embed.set_author(name=f'{post["width"]} x {post["height"]}',
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url)
embed.set_footer(text=post['score'], embed.set_footer(text=post['score'],
icon_url=self._get_score(post['score'])) icon_url=self._get_score(post['score']))
# except
finally:
await asyncio.sleep(self.RATE_LIMIT)
except exc.MissingArgument: except exc.MissingArgument:
await ctx.send('**Invalid url**', delete_after=7) await ctx.send('**Invalid url**', delete_after=7)
@ -340,19 +321,15 @@ class MsG:
raise exc.MissingArgument raise exc.MissingArgument
for url in urls: for url in urls:
try: await dest.trigger_typing()
await dest.trigger_typing()
await dest.send(await scraper.get_image(url)) await dest.send(await scraper.get_image(url))
c += 1 c += 1
# except # except
# await ctx.send(f'**No aliases found for:** `{tag}`', delete_after=7) # await ctx.send(f'**No aliases found for:** `{tag}`', delete_after=7)
finally:
await asyncio.sleep(self.RATE_LIMIT)
if not c: if not c:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@ -563,8 +540,6 @@ class MsG:
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT)
with suppress(err.NotFound): with suppress(err.NotFound):
await message.delete() await message.delete()
@ -878,8 +853,6 @@ class MsG:
n = 1 n = 1
for embed in hearted.values(): for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed)
n += 1 n += 1
@ -1039,8 +1012,6 @@ class MsG:
n = 1 n = 1
for embed in hearted.values(): for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed)
n += 1 n += 1
@ -1203,8 +1174,6 @@ class MsG:
n = 1 n = 1
for embed in hearted.values(): for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed)
n += 1 n += 1

View file

@ -17,7 +17,6 @@ class Administration:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.RATE_LIMIT = u.RATE_LIMIT
self.queue = asyncio.Queue() self.queue = asyncio.Queue()
self.deleting = False self.deleting = False
@ -145,7 +144,6 @@ class Administration:
async def delete(self): async def delete(self):
while self.deleting: while self.deleting:
message = await self.queue.get() message = await self.queue.get()
await asyncio.sleep(self.RATE_LIMIT)
with suppress(err.NotFound): with suppress(err.NotFound):
if not message.pinned: if not message.pinned:
await message.delete() await message.delete()

View file

@ -19,8 +19,6 @@ async def get_post(url):
except ValueError: except ValueError:
raise exc.MissingArgument raise exc.MissingArgument
await asyncio.sleep(u.RATE_LIMIT)
content = await u.fetch('http://iqdb.harry.lu', params={'url': url}) content = await u.fetch('http://iqdb.harry.lu', params={'url': url})
try: try:

View file

@ -87,7 +87,6 @@ temp = setdefault('temp/temp.pkl', default={'startup': ()})
secrets = setdefault('secrets.json', default={'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True) secrets = setdefault('secrets.json', default={'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True)
cogs = {} cogs = {}
RATE_LIMIT = 2.2
color = d.Color(0x1A1A1A) color = d.Color(0x1A1A1A)
session = aiohttp.ClientSession() session = aiohttp.ClientSession()
last_commands = {} last_commands = {}