1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 22:27:28 +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,7 +235,6 @@ 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])
@ -253,9 +247,6 @@ class MsG:
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,7 +261,6 @@ 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'])
@ -283,9 +273,6 @@ class MsG:
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,7 +292,6 @@ 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(
@ -320,11 +306,6 @@ class MsG:
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)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@ -340,7 +321,6 @@ 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))
@ -350,9 +330,6 @@ class MsG:
# 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 = {}