This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues or pull requests.
l9_stud_bot/database/tg.py

34 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from .l9 import L9_DB
import telegram
class TG_DB:
"""Класс взаимодействия с БД пользователей бота в Telegram"""
def __init__(self, l9lk: L9_DB):
self.l9lk = l9lk
self.db = l9lk.db
self.db.executeFile('tg')
def getTag(self, query: telegram.Message) -> (str, str, str):
"""Получить тэг и l9Id пользователя"""
tgId = query.from_user.id
name = f'{query.from_user.first_name or ""} {query.from_user.last_name or ""}'
l9Id = self.db.get('tg_users', f"tgId = {tgId}", ["l9Id"])
if l9Id == []:
l9Id = self.l9lk.initUser(0)
user = {"l9Id": l9Id, "tgId": tgId, "name": name}
self.db.insert('tg_users', user)
else:
l9Id = l9Id[0][0]
tag = self.db.get('tg_users', f"tgId = {tgId}", ["posTag"])[0][0]
return tag, l9Id, f'{tgId}\t{tag}\t{name}\t{query.text}'
def changeTag(self, tgId: int, tag: str) -> None:
"""Сменить тэг пользователя"""
self.db.update('tg_users', f"tgId = {tgId}", f"posTag = '{tag}'")