forked from Ns-Bots/TG-File-Store
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mode opt to switch uploader details in caption via /mode (Ns-Bots#12)
- Loading branch information
1 parent
972d88e
commit 8536ce1
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker, scoped_session | ||
|
||
import os | ||
import threading | ||
import asyncio | ||
|
||
from sqlalchemy import Column, Integer, Boolean, String, ForeignKey, UniqueConstraint, func | ||
|
||
DATABASE_URL = os.environ.get("DATABASE_URL", "") | ||
|
||
def start() -> scoped_session: | ||
engine = create_engine(DATABASE_URL, client_encoding="utf8") | ||
BASE.metadata.bind = engine | ||
BASE.metadata.create_all(engine) | ||
return scoped_session(sessionmaker(bind=engine, autoflush=False)) | ||
|
||
BASE = declarative_base() | ||
SESSION = start() | ||
|
||
INSERTION_LOCK = threading.RLock() | ||
|
||
class Database(BASE): | ||
__tablename__ = "database" | ||
id = Column(String, primary_key=True) | ||
up_name = Column(Boolean) | ||
|
||
def __init__(self, id, up_name): | ||
self.id = str(id) | ||
self.up_name = up_name | ||
|
||
Database.__table__.create(checkfirst=True) | ||
|
||
async def update_as_name(id, mode): | ||
with INSERTION_LOCK: | ||
msg = SESSION.query(Database).get(str(id)) | ||
if not msg: | ||
msg = Database(str(id), False) | ||
else: | ||
msg.up_name = mode | ||
SESSION.delete(msg) | ||
SESSION.add(msg) | ||
SESSION.commit() | ||
|
||
async def get_data(id): | ||
try: | ||
user_data = SESSION.query(Database).get(str(id)) | ||
if not user_data: | ||
new_user = Database(str(id), False) | ||
SESSION.add(new_user) | ||
SESSION.commit() | ||
user_data = SESSION.query(Database).get(str(id)) | ||
return user_data | ||
finally: | ||
SESSION.close() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pyrogram==1.2.9 | ||
Pyromod | ||
TgCrypto | ||
psycopg2-binary | ||
sqlalchemy==1.3.23 |