diff --git a/__pycache__/localization.cpython-310.pyc b/__pycache__/localization.cpython-310.pyc index 35ccfef..73d06a9 100644 Binary files a/__pycache__/localization.cpython-310.pyc and b/__pycache__/localization.cpython-310.pyc differ diff --git a/furry.db b/furry.db new file mode 100644 index 0000000..68dc37b Binary files /dev/null and b/furry.db differ diff --git a/localization.py b/localization.py index 8310715..5ff2f2b 100644 --- a/localization.py +++ b/localization.py @@ -1,9 +1,10 @@ -def getlstr(lang, strname): +def getstr(lang, strname): # ======== RUSSIAN ======== - if lang == "ru" and strname == "test": - return "Привет, мир!" + if lang == "ru" and strname == "test": return "Привет, мир!" + if lang == "ru" and strname == "test2": return "жопа" + if lang == "ru" and strname == "succlang": return "Русский язык был успешно пременён!" # ======== ENGLISH ======== - if lang == "en" and strname == "test": - return "Hello, world!" \ No newline at end of file + if lang == "en" and strname == "test": return "Hello, world!" + if lang == "en" and strname == "succlang": return "English language has been successfully applied!" \ No newline at end of file diff --git a/main.py b/main.py index aa46772..355f479 100644 --- a/main.py +++ b/main.py @@ -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")) \ No newline at end of file +# 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() diff --git a/pfp.png b/pfp.png new file mode 100644 index 0000000..2b747ed Binary files /dev/null and b/pfp.png differ