first signs of life

This commit is contained in:
2025-10-09 16:39:07 +03:00
parent 7053da89a8
commit add82ff0e7
5 changed files with 83 additions and 7 deletions

79
main.py
View File

@@ -1,4 +1,79 @@
import logging
import localization as lang
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
import os
import sqlite3
print(lang.getlstr("ru", "test"))
print(lang.getlstr("en", "test"))
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
DB_PATH = 'furry.db'
conn = sqlite3.connect(DB_PATH, check_same_thread=False)
cursor = conn.cursor()
def init_db():
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_lang (
chatid INTEGER PRIMARY KEY NULL,
lang TEXT DEFAULT 'no'
)
''')
conn.commit()
init_db()
print(lang.getstr("ru", "test"))
print(lang.getstr("en", "test"))
tokenfile = open("../token.txt", "r")
bottoken = str(tokenfile.read())
tokenfile.close()
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
chat = update.effective_chat
chat_id = chat.id
try:
cursor.execute("SELECT lang FROM user_lang WHERE chatid = ?", (chat_id,))
row = cursor.fetchone()
if row[0] == "ru":
await update.message.reply_text(lang.getstr("ru", "test2"))
elif row[0] == "en":
await update.message.reply_text(lang.getstr("en", "test"))
else:
await update.message.reply_text('Select your language using "/lang en" command.\n\nВыберите ваш язык командой "/lang ru".')
except:
await update.message.reply_text('Select your language using "/lang en" command.\n\nВыберите ваш язык командой "/lang ru".')
cursor.execute("INSERT INTO user_lang (chatid, lang) VALUES (?, ?)", (chat_id, "no"))
conn.commit()
async def set_lang(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
chat = update.effective_chat
chat_id = chat.id
try:
userlang = str(context.args[0])
try:
cursor.execute("INSERT INTO user_lang (chatid, lang) VALUES (?, ?)", (chat_id, userlang)) # omfg
except:
fuckinnothing = "fuckinnothing"
cursor.execute("UPDATE user_lang SET lang = ? WHERE chatid = ?", (userlang, chat_id)) # omfg
conn.commit()
cursor.execute("SELECT lang FROM user_lang WHERE chatid = ?", (chat_id,))
row = cursor.fetchone()
await update.message.reply_text(lang.getstr(row[0], "succlang"))
except:
await update.message.reply_text('/lang en\n/lang ru')
def main() -> None:
application = Application.builder().token(bottoken).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("lang", set_lang))
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()