Remove all instances of sleep 0

This commit is contained in:
Jeremy Zhang 2019-01-01 23:39:51 +00:00
parent cb6a87f73c
commit e31945be83
5 changed files with 0 additions and 38 deletions

View File

@ -8,7 +8,6 @@ import json
class Gateway(Namespace): class Gateway(Namespace):
def teardown_db_session(self): def teardown_db_session(self):
time.sleep(0)
db.session.commit() db.session.commit()
db.session.remove() db.session.remove()
@ -16,7 +15,6 @@ class Gateway(Namespace):
emit('hello') emit('hello')
def on_identify(self, data): def on_identify(self, data):
time.sleep(0)
guild_id = data["guild_id"] guild_id = data["guild_id"]
if not guild_accepts_visitors(guild_id) and not check_user_in_guild(guild_id): if not guild_accepts_visitors(guild_id) and not check_user_in_guild(guild_id):
disconnect() disconnect()
@ -31,7 +29,6 @@ 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", {}):
@ -49,7 +46,6 @@ class Gateway(Namespace):
self.teardown_db_session() self.teardown_db_session()
def on_disconnect(self): def on_disconnect(self):
time.sleep(0)
if "user_keys" not in session: if "user_keys" not in session:
self.teardown_db_session() self.teardown_db_session()
return return
@ -75,13 +71,11 @@ 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()
def on_heartbeat(self, data): def on_heartbeat(self, data):
time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
disconnect() disconnect()
return return
@ -95,7 +89,6 @@ class Gateway(Namespace):
return return
if session["unauthenticated"]: if session["unauthenticated"]:
key = session["user_keys"][guild_id] key = session["user_keys"][guild_id]
time.sleep(0)
status = update_user_status(guild_id, session["username"], key) status = update_user_status(guild_id, session["username"], key)
if status["revoked"] or status["banned"]: if status["revoked"] or status["banned"]:
emit("revoke") emit("revoke")
@ -113,7 +106,6 @@ class Gateway(Namespace):
self.teardown_db_session() self.teardown_db_session()
def on_channel_list(self, data): def on_channel_list(self, data):
time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
disconnect() disconnect()
return return
@ -134,7 +126,6 @@ class Gateway(Namespace):
self.teardown_db_session() self.teardown_db_session()
def on_current_user_info(self, data): def on_current_user_info(self, data):
time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
disconnect() disconnect()
return return
@ -159,28 +150,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
def on_lookup_user_info(self, data): def on_lookup_user_info(self, data):
time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
disconnect() disconnect()
return return
@ -198,7 +184,6 @@ class Gateway(Namespace):
"avatar_url": None, "avatar_url": None,
"discordbotsorgvoted": False, "discordbotsorgvoted": False,
} }
time.sleep(0)
member = redisqueue.get_guild_member_named(guild_id, "{}#{}".format(name, discriminator)) member = redisqueue.get_guild_member_named(guild_id, "{}#{}".format(name, discriminator))
if member: if member:
usr["id"] = str(member["id"]) usr["id"] = str(member["id"])

View File

@ -53,7 +53,6 @@ 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

@ -66,7 +66,6 @@ def get_user_managed_servers():
guilds = json.loads(fetched) guilds = json.loads(fetched)
filtered = [] filtered = []
for guild in guilds: for guild in guilds:
time.sleep(0)
permission = guild['permissions'] # Manage Server, Ban Members, Kick Members permission = guild['permissions'] # Manage Server, Ban Members, Kick Members
if guild['owner'] or user_has_permission(permission, 5) or user_has_permission(permission, 2) or user_has_permission(permission, 1): if guild['owner'] or user_has_permission(permission, 5) or user_has_permission(permission, 2) or user_has_permission(permission, 1):
filtered.append(guild) filtered.append(guild)
@ -83,7 +82,6 @@ def get_user_managed_servers_id():
guilds = get_user_managed_servers_safe() guilds = get_user_managed_servers_safe()
ids=[] ids=[]
for guild in guilds: for guild in guilds:
time.sleep(0)
ids.append(guild['id']) ids.append(guild['id'])
return ids return ids
@ -94,7 +92,6 @@ def check_user_can_administrate_guild(guild_id):
def check_user_permission(guild_id, id): def check_user_permission(guild_id, id):
guilds = get_user_managed_servers_safe() guilds = get_user_managed_servers_safe()
for guild in guilds: for guild in guilds:
time.sleep(0)
if guild['id'] == guild_id: if guild['id'] == guild_id:
return user_has_permission(guild['permissions'], id) or guild['owner'] return user_has_permission(guild['permissions'], id) or guild['owner']
return False return False

View File

@ -16,7 +16,6 @@ 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)
@ -29,7 +28,6 @@ class RedisQueue:
data = list(data) data = list(data)
data_parsed = [] data_parsed = []
for d in data: for d in data:
time.sleep(0)
if d != "": if d != "":
data_parsed.append(json.loads(d)) data_parsed.append(json.loads(d))
return data_parsed return data_parsed
@ -48,7 +46,6 @@ 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"])
@ -77,7 +74,6 @@ 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
@ -110,7 +106,6 @@ 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:

View File

@ -113,7 +113,6 @@ def checkUserBanned(guild_id, ip_address=None):
banned = False banned = False
else: else:
for usr in dbUser: for usr in dbUser:
time.sleep(0)
if usr.lifter_id is not None: if usr.lifter_id is not None:
banned = False banned = False
else: else:
@ -182,11 +181,9 @@ def get_online_embed_user_keys(guild_id="*", user_type=None):
user_type = [user_type] user_type = [user_type]
usrs = {} usrs = {}
for utype in user_type: for utype in user_type:
time.sleep(0)
usrs[utype] = [] usrs[utype] = []
keys = redis_store.keys("MemberPresence/{}/{}/*".format(guild_id, utype)) keys = redis_store.keys("MemberPresence/{}/{}/*".format(guild_id, utype))
for key in keys: for key in keys:
time.sleep(0)
client_key = key.split("/")[-1] client_key = key.split("/")[-1]
usrs[utype].append(client_key) usrs[utype].append(client_key)
return usrs return usrs
@ -203,7 +200,6 @@ def get_member_roles(guild_id, user_id):
roles = q["roles"] roles = q["roles"]
role_converted = [] role_converted = []
for role in roles: for role in roles:
time.sleep(0)
role_converted.append(str(role)) role_converted.append(str(role))
return role_converted return role_converted
@ -226,7 +222,6 @@ def get_guild_channels(guild_id, force_everyone=False, forced_role=0):
guild_owner = guild["owner_id"] guild_owner = guild["owner_id"]
result_channels = [] result_channels = []
for channel in guild_channels: for channel in guild_channels:
time.sleep(0)
if channel['type'] in ["text", "category"]: if channel['type'] in ["text", "category"]:
result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_roles, str(session.get("user_id")), force_everyone) result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_roles, str(session.get("user_id")), force_everyone)
bot_result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, bot_member_roles, config["client-id"], False) bot_result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, bot_member_roles, config["client-id"], False)
@ -255,22 +250,18 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
role_positions = {} role_positions = {}
for role in guild_roles: for role in guild_roles:
time.sleep(0)
role_positions[str(role["id"])] = role["position"] role_positions[str(role["id"])] = role["position"]
member_roles = sorted(member_roles, key=lambda x: role_positions.get(str(x), -1), reverse=True) member_roles = sorted(member_roles, key=lambda x: role_positions.get(str(x), -1), reverse=True)
# @everyone # @everyone
for role in guild_roles: for role in guild_roles:
time.sleep(0)
if role["id"] == guild_id: if role["id"] == guild_id:
channel_perm |= role["permissions"] channel_perm |= role["permissions"]
continue continue
# User Guild Roles # User Guild Roles
for m_role in member_roles: for m_role in member_roles:
time.sleep(0)
for g_role in guild_roles: for g_role in guild_roles:
time.sleep(0)
if g_role["id"] == m_role: if g_role["id"] == m_role:
channel_perm |= g_role["permissions"] channel_perm |= g_role["permissions"]
continue continue
@ -288,7 +279,6 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
# channel specific # channel specific
for overwrite in channel["permission_overwrites"]: for overwrite in channel["permission_overwrites"]:
time.sleep(0)
if overwrite["type"] == "role" and overwrite["id"] in member_roles: if overwrite["type"] == "role" and overwrite["id"] in member_roles:
denies |= overwrite["deny"] denies |= overwrite["deny"]
allows |= overwrite["allow"] allows |= overwrite["allow"]
@ -297,7 +287,6 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
# member specific # member specific
for overwrite in channel["permission_overwrites"]: for overwrite in channel["permission_overwrites"]:
time.sleep(0)
if overwrite["type"] == "member" and overwrite["id"] == str(session.get("user_id")): if overwrite["type"] == "member" and overwrite["id"] == str(session.get("user_id")):
channel_perm = (channel_perm & ~overwrite['deny']) | overwrite['allow'] channel_perm = (channel_perm & ~overwrite['deny']) | overwrite['allow']
break break
@ -328,16 +317,13 @@ def bot_can_create_webhooks(guild):
guild_roles = guild["roles"] guild_roles = guild["roles"]
# @everyone # @everyone
for role in guild_roles: for role in guild_roles:
time.sleep(0)
if role["id"] == guild["id"]: if role["id"] == guild["id"]:
perm |= role["permissions"] perm |= role["permissions"]
continue continue
member_roles = get_member_roles(guild["id"], config["client-id"]) member_roles = get_member_roles(guild["id"], config["client-id"])
# User Guild Roles # User Guild Roles
for m_role in member_roles: for m_role in member_roles:
time.sleep(0)
for g_role in guild_roles: for g_role in guild_roles:
time.sleep(0)
if g_role["id"] == m_role: if g_role["id"] == m_role:
perm |= g_role["permissions"] perm |= g_role["permissions"]
continue continue