Time sleep 0?

This commit is contained in:
Jeremy Zhang 2018-11-03 18:52:24 +00:00
parent ca09254ada
commit e9e2471e41
3 changed files with 11 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class Gateway(Namespace):
channels = get_guild_channels(guild_id, forced_role=forced_role) channels = get_guild_channels(guild_id, forced_role=forced_role)
join_room("GUILD_"+guild_id) join_room("GUILD_"+guild_id)
for chan in channels: for chan in channels:
time.sleep(0)
if chan["read"]: if chan["read"]:
join_room("CHANNEL_"+chan["channel"]["id"]) join_room("CHANNEL_"+chan["channel"]["id"])
if session.get("unauthenticated", True) and guild_id in session.get("user_keys", {}): if session.get("unauthenticated", True) and guild_id in session.get("user_keys", {}):
@ -68,6 +69,7 @@ class Gateway(Namespace):
else: else:
name = name + username + "#" + str(session["discriminator"]) name = name + username + "#" + str(session["discriminator"])
for webhook in guild_webhooks: for webhook in guild_webhooks:
time.sleep(0)
if webhook["name"] == name: if webhook["name"] == name:
discord_api.delete_webhook(webhook["id"], webhook["token"]) discord_api.delete_webhook(webhook["id"], webhook["token"])
self.teardown_db_session() self.teardown_db_session()
@ -135,19 +137,23 @@ class Gateway(Namespace):
guild_roles = redisqueue.get_guild(guild_id)["roles"] guild_roles = redisqueue.get_guild(guild_id)["roles"]
guildroles_filtered = {} guildroles_filtered = {}
for role in guild_roles: for role in guild_roles:
time.sleep(0)
guildroles_filtered[role["id"]] = role guildroles_filtered[role["id"]] = role
member_roleids = member["roles"] member_roleids = member["roles"]
member_roles = [] member_roles = []
for roleid in member_roleids: for roleid in member_roleids:
time.sleep(0)
role = guildroles_filtered.get(str(roleid)) role = guildroles_filtered.get(str(roleid))
if not role: if not role:
continue continue
member_roles.append(role) member_roles.append(role)
member_roles = sorted(member_roles, key=lambda k: k['position']) member_roles = sorted(member_roles, key=lambda k: k['position'])
for role in member_roles: for role in member_roles:
time.sleep(0)
if role["color"] != 0: if role["color"] != 0:
color = '{0:02x}'.format(role["color"]) color = '{0:02x}'.format(role["color"])
while len(color) < 6: while len(color) < 6:
time.sleep(0)
color = "0" + color color = "0" + color
return color return color

View File

@ -53,6 +53,7 @@ class DiscordREST:
data = json.dumps(data) data = json.dumps(data)
for tries in range(5): for tries in range(5):
time.sleep(0)
curepoch = time.time() curepoch = time.time()
if self._get_bucket("global_limited") == "True": if self._get_bucket("global_limited") == "True":
time.sleep(int(float(self._get_bucket("global_limit_expire"))) - curepoch) time.sleep(int(float(self._get_bucket("global_limit_expire"))) - curepoch)

View File

@ -16,6 +16,7 @@ class RedisQueue:
} }
loop_count = 0 loop_count = 0
while (not data and data != "") and loop_count < 50: while (not data and data != "") and loop_count < 50:
time.sleep(0)
if loop_count % 25 == 0: if loop_count % 25 == 0:
redis_store.publish("discord-api-req", json.dumps(payload)) redis_store.publish("discord-api-req", json.dumps(payload))
time.sleep(0.1) time.sleep(0.1)
@ -46,6 +47,7 @@ class RedisQueue:
snowflakes = [] snowflakes = []
guild_members = {} guild_members = {}
for x in q: for x in q:
time.sleep(0)
if x["id"] in snowflakes or int(x["id"]) <= int(after_snowflake): if x["id"] in snowflakes or int(x["id"]) <= int(after_snowflake):
continue continue
snowflakes.append(x["id"]) snowflakes.append(x["id"])
@ -74,6 +76,7 @@ class RedisQueue:
message["author"]["discriminator"] = member["discriminator"] message["author"]["discriminator"] = member["discriminator"]
message["author"]["username"] = member["username"] message["author"]["username"] = member["username"]
for mention in message["mentions"]: for mention in message["mentions"]:
time.sleep(0)
if mention["id"] not in guild_members: if mention["id"] not in guild_members:
author = self.get_guild_member(guild_id, mention["id"]) author = self.get_guild_member(guild_id, mention["id"])
guild_members[mention["id"]] = author guild_members[mention["id"]] = author
@ -106,6 +109,7 @@ class RedisQueue:
member_ids = self.get(key, "list_guild_members", {"guild_id": guild_id}, data_type="set") member_ids = self.get(key, "list_guild_members", {"guild_id": guild_id}, data_type="set")
members = [] members = []
for member_id in member_ids: for member_id in member_ids:
time.sleep(0)
usr_id = member_id["user_id"] usr_id = member_id["user_id"]
member = self.get_guild_member(guild_id, usr_id) member = self.get_guild_member(guild_id, usr_id)
if member: if member: