mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
backend+ telegram: регистрация переведена на классы
This commit is contained in:
@@ -6,7 +6,7 @@ with open("textsouls/config.json") as config_file:
|
||||
|
||||
|
||||
class Backend:
|
||||
base_url = config_data["backend_settings"]["base_url"]
|
||||
base_url = config_data["BACKEND_SETTINGS"]["BASE_URL"]
|
||||
|
||||
def post(self, relative_url, data):
|
||||
try:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"main_settings": {
|
||||
"bot_token": "token-from-@BotFather"
|
||||
"MAIN_SETTINGS": {
|
||||
"BOT_TOKEN": "token-from-@BotFather"
|
||||
},
|
||||
"backend_settings": {
|
||||
"base_url": "http://localhost:5000"
|
||||
"BACKEND_SETTINGS": {
|
||||
"BASE_URL": "http://localhost:5000"
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ from common import backend
|
||||
with open("textsouls/config.json") as config_file:
|
||||
config_data = json.load(config_file)
|
||||
|
||||
API_TOKEN = config_data["main_settings"]["bot_token"]
|
||||
API_TOKEN = config_data["MAIN_SETTINGS"]["BOT_TOKEN"]
|
||||
|
||||
bot = Bot(token=API_TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
@@ -17,18 +17,20 @@ dp = Dispatcher(bot)
|
||||
async def start(message):
|
||||
tg_user = message.from_user
|
||||
ts_user = {
|
||||
"tg_id": tg_user.id,
|
||||
"id": tg_user.id,
|
||||
"first_name": tg_user.first_name,
|
||||
"last_name": tg_user.last_name,
|
||||
"username": tg_user.username,
|
||||
}
|
||||
result = backend.post("/registration", ts_user)
|
||||
if not result["error"] and result["response"].ok:
|
||||
data = json.loads(result["response"].text)
|
||||
if data["created"]:
|
||||
result = backend.post("/users", ts_user)
|
||||
if not result["error"]:
|
||||
response_code = result["response"].status_code
|
||||
if response_code == 200:
|
||||
await message.reply("Добро пожаловать!")
|
||||
else:
|
||||
elif response_code == 400:
|
||||
await message.reply("Добро пожаловать! Снова")
|
||||
else:
|
||||
await message.reply("Что-то другое")
|
||||
else:
|
||||
await message.reply("Упс! Что-то пошло не так")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user