first signs of life
This commit is contained in:
Binary file not shown.
@@ -1,9 +1,10 @@
|
|||||||
def getlstr(lang, strname):
|
def getstr(lang, strname):
|
||||||
|
|
||||||
# ======== RUSSIAN ========
|
# ======== RUSSIAN ========
|
||||||
if lang == "ru" and strname == "test":
|
if lang == "ru" and strname == "test": return "Привет, мир!"
|
||||||
return "Привет, мир!"
|
if lang == "ru" and strname == "test2": return "жопа"
|
||||||
|
if lang == "ru" and strname == "succlang": return "Русский язык был успешно пременён!"
|
||||||
|
|
||||||
# ======== ENGLISH ========
|
# ======== ENGLISH ========
|
||||||
if lang == "en" and strname == "test":
|
if lang == "en" and strname == "test": return "Hello, world!"
|
||||||
return "Hello, world!"
|
if lang == "en" and strname == "succlang": return "English language has been successfully applied!"
|
||||||
79
main.py
79
main.py
@@ -1,4 +1,79 @@
|
|||||||
|
import logging
|
||||||
import localization as lang
|
import localization as lang
|
||||||
|
from telegram import Update
|
||||||
|
from telegram.ext import Application, CommandHandler, ContextTypes
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
print(lang.getlstr("ru", "test"))
|
# Enable logging
|
||||||
print(lang.getlstr("en", "test"))
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user