mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
Teardown sqlalchemy session on each emit
This commit is contained in:
parent
fc8768d389
commit
370d4c6985
@ -7,6 +7,10 @@ import time
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
class Gateway(Namespace):
|
class Gateway(Namespace):
|
||||||
|
def teardown_db_session(self):
|
||||||
|
db.session.commit()
|
||||||
|
db.session.remove()
|
||||||
|
|
||||||
def on_connect(self):
|
def on_connect(self):
|
||||||
emit('hello')
|
emit('hello')
|
||||||
|
|
||||||
@ -37,6 +41,7 @@ class Gateway(Namespace):
|
|||||||
nickname = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.user_id == session["user_id"]).first().nickname
|
nickname = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.user_id == session["user_id"]).first().nickname
|
||||||
emit("embed_user_connect", {"unauthenticated": False, "id": session["user_id"], "nickname": nickname, "username": session["username"],"discriminator": session["discriminator"], "avatar_url": session["avatar"]}, room="GUILD_"+guild_id)
|
emit("embed_user_connect", {"unauthenticated": False, "id": session["user_id"], "nickname": nickname, "username": session["username"],"discriminator": session["discriminator"], "avatar_url": session["avatar"]}, room="GUILD_"+guild_id)
|
||||||
emit("identified")
|
emit("identified")
|
||||||
|
self.teardown_db_session()
|
||||||
|
|
||||||
def on_disconnect(self):
|
def on_disconnect(self):
|
||||||
if "user_keys" not in session:
|
if "user_keys" not in session:
|
||||||
@ -62,6 +67,7 @@ class Gateway(Namespace):
|
|||||||
for webhook in guild_webhooks:
|
for webhook in guild_webhooks:
|
||||||
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()
|
||||||
|
|
||||||
def on_heartbeat(self, data):
|
def on_heartbeat(self, data):
|
||||||
guild_id = data["guild_id"]
|
guild_id = data["guild_id"]
|
||||||
@ -78,6 +84,7 @@ class Gateway(Namespace):
|
|||||||
else:
|
else:
|
||||||
if not guild_accepts_visitors(guild_id):
|
if not guild_accepts_visitors(guild_id):
|
||||||
disconnect()
|
disconnect()
|
||||||
|
self.teardown_db_session()
|
||||||
|
|
||||||
def on_channel_list(self, data):
|
def on_channel_list(self, data):
|
||||||
guild_id = data["guild_id"]
|
guild_id = data["guild_id"]
|
||||||
@ -93,6 +100,7 @@ class Gateway(Namespace):
|
|||||||
else:
|
else:
|
||||||
leave_room("CHANNEL_"+chan["channel"]["id"])
|
leave_room("CHANNEL_"+chan["channel"]["id"])
|
||||||
emit("channel_list", channels)
|
emit("channel_list", channels)
|
||||||
|
self.teardown_db_session()
|
||||||
|
|
||||||
def on_current_user_info(self, data):
|
def on_current_user_info(self, data):
|
||||||
guild_id = data["guild_id"]
|
guild_id = data["guild_id"]
|
||||||
@ -106,6 +114,7 @@ class Gateway(Namespace):
|
|||||||
'user_id': session['user_id'],
|
'user_id': session['user_id'],
|
||||||
}
|
}
|
||||||
emit("current_user_info", usr)
|
emit("current_user_info", usr)
|
||||||
|
self.teardown_db_session()
|
||||||
|
|
||||||
def get_user_color(self, guild_id, user_id):
|
def get_user_color(self, guild_id, user_id):
|
||||||
color = None
|
color = None
|
||||||
@ -165,3 +174,4 @@ class Gateway(Namespace):
|
|||||||
if (usr["avatar"]):
|
if (usr["avatar"]):
|
||||||
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.jpg".format(usr["id"], usr["avatar"])
|
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.jpg".format(usr["id"], usr["avatar"])
|
||||||
emit("lookup_user_info", usr)
|
emit("lookup_user_info", usr)
|
||||||
|
self.teardown_db_session()
|
Loading…
Reference in New Issue
Block a user