Remove all time sleep 0 to test

This commit is contained in:
Jeremy Zhang 2019-01-01 23:32:37 +00:00
parent db1643595f
commit 883a5d27b7
5 changed files with 0 additions and 32 deletions

View File

@ -9,7 +9,6 @@ from titanembeds.decorators import timeit
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()
@ -18,7 +17,6 @@ class Gateway(Namespace):
@timeit @timeit
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()
@ -33,7 +31,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", {}):
@ -51,7 +48,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
@ -77,13 +73,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
@ -97,7 +91,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")
@ -115,7 +108,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
@ -136,7 +128,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
@ -161,28 +152,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
@ -200,7 +186,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

@ -17,7 +17,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)
@ -30,7 +29,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
@ -49,7 +47,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"])
@ -78,7 +75,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
@ -112,7 +108,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

@ -116,7 +116,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:
@ -185,11 +184,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
@ -208,7 +205,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
@ -232,7 +228,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)
@ -330,16 +325,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