mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-24 14:07:03 +01:00
Remove all instances of sleep 0
This commit is contained in:
parent
cb6a87f73c
commit
e31945be83
@ -8,7 +8,6 @@ import json
|
||||
|
||||
class Gateway(Namespace):
|
||||
def teardown_db_session(self):
|
||||
time.sleep(0)
|
||||
db.session.commit()
|
||||
db.session.remove()
|
||||
|
||||
@ -16,7 +15,6 @@ class Gateway(Namespace):
|
||||
emit('hello')
|
||||
|
||||
def on_identify(self, data):
|
||||
time.sleep(0)
|
||||
guild_id = data["guild_id"]
|
||||
if not guild_accepts_visitors(guild_id) and not check_user_in_guild(guild_id):
|
||||
disconnect()
|
||||
@ -31,7 +29,6 @@ class Gateway(Namespace):
|
||||
channels = get_guild_channels(guild_id, forced_role=forced_role)
|
||||
join_room("GUILD_"+guild_id)
|
||||
for chan in channels:
|
||||
time.sleep(0)
|
||||
if chan["read"]:
|
||||
join_room("CHANNEL_"+chan["channel"]["id"])
|
||||
if session.get("unauthenticated", True) and guild_id in session.get("user_keys", {}):
|
||||
@ -49,7 +46,6 @@ class Gateway(Namespace):
|
||||
self.teardown_db_session()
|
||||
|
||||
def on_disconnect(self):
|
||||
time.sleep(0)
|
||||
if "user_keys" not in session:
|
||||
self.teardown_db_session()
|
||||
return
|
||||
@ -75,13 +71,11 @@ class Gateway(Namespace):
|
||||
else:
|
||||
name = name + username + "#" + str(session["discriminator"])
|
||||
for webhook in guild_webhooks:
|
||||
time.sleep(0)
|
||||
if webhook["name"] == name:
|
||||
discord_api.delete_webhook(webhook["id"], webhook["token"])
|
||||
self.teardown_db_session()
|
||||
|
||||
def on_heartbeat(self, data):
|
||||
time.sleep(0)
|
||||
if "socket_guild_id" not in session:
|
||||
disconnect()
|
||||
return
|
||||
@ -95,7 +89,6 @@ class Gateway(Namespace):
|
||||
return
|
||||
if session["unauthenticated"]:
|
||||
key = session["user_keys"][guild_id]
|
||||
time.sleep(0)
|
||||
status = update_user_status(guild_id, session["username"], key)
|
||||
if status["revoked"] or status["banned"]:
|
||||
emit("revoke")
|
||||
@ -113,7 +106,6 @@ class Gateway(Namespace):
|
||||
self.teardown_db_session()
|
||||
|
||||
def on_channel_list(self, data):
|
||||
time.sleep(0)
|
||||
if "socket_guild_id" not in session:
|
||||
disconnect()
|
||||
return
|
||||
@ -134,7 +126,6 @@ class Gateway(Namespace):
|
||||
self.teardown_db_session()
|
||||
|
||||
def on_current_user_info(self, data):
|
||||
time.sleep(0)
|
||||
if "socket_guild_id" not in session:
|
||||
disconnect()
|
||||
return
|
||||
@ -159,28 +150,23 @@ class Gateway(Namespace):
|
||||
guild_roles = redisqueue.get_guild(guild_id)["roles"]
|
||||
guildroles_filtered = {}
|
||||
for role in guild_roles:
|
||||
time.sleep(0)
|
||||
guildroles_filtered[role["id"]] = role
|
||||
member_roleids = member["roles"]
|
||||
member_roles = []
|
||||
for roleid in member_roleids:
|
||||
time.sleep(0)
|
||||
role = guildroles_filtered.get(str(roleid))
|
||||
if not role:
|
||||
continue
|
||||
member_roles.append(role)
|
||||
member_roles = sorted(member_roles, key=lambda k: k['position'])
|
||||
for role in member_roles:
|
||||
time.sleep(0)
|
||||
if role["color"] != 0:
|
||||
color = '{0:02x}'.format(role["color"])
|
||||
while len(color) < 6:
|
||||
time.sleep(0)
|
||||
color = "0" + color
|
||||
return color
|
||||
|
||||
def on_lookup_user_info(self, data):
|
||||
time.sleep(0)
|
||||
if "socket_guild_id" not in session:
|
||||
disconnect()
|
||||
return
|
||||
@ -198,7 +184,6 @@ class Gateway(Namespace):
|
||||
"avatar_url": None,
|
||||
"discordbotsorgvoted": False,
|
||||
}
|
||||
time.sleep(0)
|
||||
member = redisqueue.get_guild_member_named(guild_id, "{}#{}".format(name, discriminator))
|
||||
if member:
|
||||
usr["id"] = str(member["id"])
|
||||
|
@ -53,7 +53,6 @@ class DiscordREST:
|
||||
data = json.dumps(data)
|
||||
|
||||
for tries in range(5):
|
||||
time.sleep(0)
|
||||
curepoch = time.time()
|
||||
if self._get_bucket("global_limited") == "True":
|
||||
time.sleep(int(float(self._get_bucket("global_limit_expire"))) - curepoch)
|
||||
|
@ -66,7 +66,6 @@ def get_user_managed_servers():
|
||||
guilds = json.loads(fetched)
|
||||
filtered = []
|
||||
for guild in guilds:
|
||||
time.sleep(0)
|
||||
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):
|
||||
filtered.append(guild)
|
||||
@ -83,7 +82,6 @@ def get_user_managed_servers_id():
|
||||
guilds = get_user_managed_servers_safe()
|
||||
ids=[]
|
||||
for guild in guilds:
|
||||
time.sleep(0)
|
||||
ids.append(guild['id'])
|
||||
return ids
|
||||
|
||||
@ -94,7 +92,6 @@ def check_user_can_administrate_guild(guild_id):
|
||||
def check_user_permission(guild_id, id):
|
||||
guilds = get_user_managed_servers_safe()
|
||||
for guild in guilds:
|
||||
time.sleep(0)
|
||||
if guild['id'] == guild_id:
|
||||
return user_has_permission(guild['permissions'], id) or guild['owner']
|
||||
return False
|
||||
|
@ -16,7 +16,6 @@ class RedisQueue:
|
||||
}
|
||||
loop_count = 0
|
||||
while (not data and data != "") and loop_count < 50:
|
||||
time.sleep(0)
|
||||
if loop_count % 25 == 0:
|
||||
redis_store.publish("discord-api-req", json.dumps(payload))
|
||||
time.sleep(0.1)
|
||||
@ -29,7 +28,6 @@ class RedisQueue:
|
||||
data = list(data)
|
||||
data_parsed = []
|
||||
for d in data:
|
||||
time.sleep(0)
|
||||
if d != "":
|
||||
data_parsed.append(json.loads(d))
|
||||
return data_parsed
|
||||
@ -48,7 +46,6 @@ class RedisQueue:
|
||||
snowflakes = []
|
||||
guild_members = {}
|
||||
for x in q:
|
||||
time.sleep(0)
|
||||
if x["id"] in snowflakes or int(x["id"]) <= int(after_snowflake):
|
||||
continue
|
||||
snowflakes.append(x["id"])
|
||||
@ -77,7 +74,6 @@ class RedisQueue:
|
||||
message["author"]["discriminator"] = member["discriminator"]
|
||||
message["author"]["username"] = member["username"]
|
||||
for mention in message["mentions"]:
|
||||
time.sleep(0)
|
||||
if mention["id"] not in guild_members:
|
||||
author = self.get_guild_member(guild_id, mention["id"])
|
||||
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")
|
||||
members = []
|
||||
for member_id in member_ids:
|
||||
time.sleep(0)
|
||||
usr_id = member_id["user_id"]
|
||||
member = self.get_guild_member(guild_id, usr_id)
|
||||
if member:
|
||||
|
@ -113,7 +113,6 @@ def checkUserBanned(guild_id, ip_address=None):
|
||||
banned = False
|
||||
else:
|
||||
for usr in dbUser:
|
||||
time.sleep(0)
|
||||
if usr.lifter_id is not None:
|
||||
banned = False
|
||||
else:
|
||||
@ -182,11 +181,9 @@ def get_online_embed_user_keys(guild_id="*", user_type=None):
|
||||
user_type = [user_type]
|
||||
usrs = {}
|
||||
for utype in user_type:
|
||||
time.sleep(0)
|
||||
usrs[utype] = []
|
||||
keys = redis_store.keys("MemberPresence/{}/{}/*".format(guild_id, utype))
|
||||
for key in keys:
|
||||
time.sleep(0)
|
||||
client_key = key.split("/")[-1]
|
||||
usrs[utype].append(client_key)
|
||||
return usrs
|
||||
@ -203,7 +200,6 @@ def get_member_roles(guild_id, user_id):
|
||||
roles = q["roles"]
|
||||
role_converted = []
|
||||
for role in roles:
|
||||
time.sleep(0)
|
||||
role_converted.append(str(role))
|
||||
return role_converted
|
||||
|
||||
@ -226,7 +222,6 @@ def get_guild_channels(guild_id, force_everyone=False, forced_role=0):
|
||||
guild_owner = guild["owner_id"]
|
||||
result_channels = []
|
||||
for channel in guild_channels:
|
||||
time.sleep(0)
|
||||
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)
|
||||
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 = {}
|
||||
for role in guild_roles:
|
||||
time.sleep(0)
|
||||
role_positions[str(role["id"])] = role["position"]
|
||||
member_roles = sorted(member_roles, key=lambda x: role_positions.get(str(x), -1), reverse=True)
|
||||
|
||||
# @everyone
|
||||
for role in guild_roles:
|
||||
time.sleep(0)
|
||||
if role["id"] == guild_id:
|
||||
channel_perm |= role["permissions"]
|
||||
continue
|
||||
|
||||
# User Guild Roles
|
||||
for m_role in member_roles:
|
||||
time.sleep(0)
|
||||
for g_role in guild_roles:
|
||||
time.sleep(0)
|
||||
if g_role["id"] == m_role:
|
||||
channel_perm |= g_role["permissions"]
|
||||
continue
|
||||
@ -288,7 +279,6 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
|
||||
|
||||
# channel specific
|
||||
for overwrite in channel["permission_overwrites"]:
|
||||
time.sleep(0)
|
||||
if overwrite["type"] == "role" and overwrite["id"] in member_roles:
|
||||
denies |= overwrite["deny"]
|
||||
allows |= overwrite["allow"]
|
||||
@ -297,7 +287,6 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
|
||||
|
||||
# member specific
|
||||
for overwrite in channel["permission_overwrites"]:
|
||||
time.sleep(0)
|
||||
if overwrite["type"] == "member" and overwrite["id"] == str(session.get("user_id")):
|
||||
channel_perm = (channel_perm & ~overwrite['deny']) | overwrite['allow']
|
||||
break
|
||||
@ -328,16 +317,13 @@ def bot_can_create_webhooks(guild):
|
||||
guild_roles = guild["roles"]
|
||||
# @everyone
|
||||
for role in guild_roles:
|
||||
time.sleep(0)
|
||||
if role["id"] == guild["id"]:
|
||||
perm |= role["permissions"]
|
||||
continue
|
||||
member_roles = get_member_roles(guild["id"], config["client-id"])
|
||||
# User Guild Roles
|
||||
for m_role in member_roles:
|
||||
time.sleep(0)
|
||||
for g_role in guild_roles:
|
||||
time.sleep(0)
|
||||
if g_role["id"] == m_role:
|
||||
perm |= g_role["permissions"]
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user