def upd_chat_lastset(self, chat_id, setid): """ :param chat_id: int (T_Chat_ID) :param setid: id of last set :return: """ logging.debug('Called') try: with self.db.atomic(): ChatIDs.update({ ChatIDs.last_set: setid }).where(ChatIDs.chat_id == chat_id).execute() except Exception as e: logging.error(e)
def user_is_admin(self, chat_id): logging.debug('Called') try: return ChatIDs.select(ChatIDs.is_admin).where( ChatIDs.chat_id == chat_id).execute()[0].is_admin except Exception as e: logging.error(e)
def make_user_admin(self, chat_id): logging.debug('Called') try: return ChatIDs.update({ ChatIDs.is_admin: True }).where(ChatIDs.chat_id == chat_id).execute() except Exception as e: logging.error(e)
def get_user_last_qa_set(self, user_id: int) -> ChatIDs.last_set: """ Get user last question and answer set. """ logging.debug('Entry') result = ChatIDs.select(ChatIDs.last_set).where( ChatIDs.chat_id == user_id).execute()[0].last_set logging.debug('Возвращаемый результат ' + result) return result
def get_chatid_name_by_id(self, chat_id): """ TODO: Упрлс? :param chat_id: :return: number of affected rows """ logging.debug('Called') with self.db.atomic(): try: return ChatIDs.select(ChatIDs.user_name).where( ChatIDs.chat_id == chat_id).execute() except OperationalError as e: logging.error(e)
def is_exists_user_acc(self, chat_id): """ Check what the user is exist in DB :param chat_id: int (T_Chat_ID) :return: bool type """ logging.debug('Called') try: with self.db.atomic(): return ChatIDs.select().where( ChatIDs.chat_id == chat_id).exists() except Exception as e: logging.error(e)
def add_user_acc(self, user_id: int, username: str, first_name: str, last_name: str): """ Add new user to table """ logging.debug('Called') try: return ChatIDs.insert({ ChatIDs.chat_id: user_id, ChatIDs.user_name: username, ChatIDs.first_name: first_name, ChatIDs.last_name: last_name }).execute() except Exception as e: logging.error(e)