File size: 1,850 Bytes
44aada1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | from sqlalchemy import BigInteger, Boolean, Column, String, UnicodeText
from telebot.plugins.sql_helper import SESSION, BASE
class Welcome(BASE):
__tablename__ = "welcome"
chat_id = Column(String(14), primary_key=True)
custom_welcome_message = Column(UnicodeText)
media_file_id = Column(UnicodeText)
should_clean_welcome = Column(Boolean, default=False)
previous_welcome = Column(BigInteger)
def __init__(
self,
chat_id,
custom_welcome_message,
should_clean_welcome,
previous_welcome,
media_file_id=None,
):
self.chat_id = chat_id
self.custom_welcome_message = custom_welcome_message
self.media_file_id = media_file_id
self.should_clean_welcome = should_clean_welcome
self.previous_welcome = previous_welcome
Welcome.__table__.create(checkfirst=True)
def get_current_welcome_settings(chat_id):
try:
return SESSION.query(Welcome).filter(
Welcome.chat_id == str(chat_id)).one()
except BaseException:
return None
finally:
SESSION.close()
def add_welcome_setting(
chat_id,
custom_welcome_message,
should_clean_welcome,
previous_welcome,
media_file_id
):
# adder = SESSION.query(Welcome).get(chat_id)
adder = Welcome(
chat_id,
custom_welcome_message,
should_clean_welcome,
previous_welcome,
media_file_id
)
SESSION.add(adder)
SESSION.commit()
def rm_welcome_setting(chat_id):
rem = SESSION.query(Welcome).get(str(chat_id))
if rem:
SESSION.delete(rem)
SESSION.commit()
def update_previous_welcome(chat_id, previous_welcome):
row = SESSION.query(Welcome).get(chat_id)
row.previous_welcome = previous_welcome
# commit the changes to the DB
SESSION.commit()
|