Making sure multilanguage is possible
This commit is contained in:
26
bot.py
26
bot.py
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from sys import exit
|
||||
from os import getpid, listdir, sep, system
|
||||
from modules.functions import *
|
||||
from modules.functions_bot import *
|
||||
from pyrogram import Client, filters, idle
|
||||
@@ -10,7 +10,7 @@ from pyrogram.types import ForceReply, BotCommand, BotCommandScopeChat
|
||||
from pyrogram.enums.chat_action import ChatAction
|
||||
|
||||
if configGet("bot_token") != "12345678:asdfghjklzxcvbnm":
|
||||
pid = os.getpid()
|
||||
pid = getpid()
|
||||
app = Client("auto_zoom_public_bot", api_id=configGet("api_id"), api_hash=configGet("api_hash"), bot_token=configGet("bot_token"))
|
||||
else:
|
||||
logWrite("Could not start the bot. Please, configure token in config.json")
|
||||
@@ -28,9 +28,11 @@ def start(app, msg):
|
||||
|
||||
app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
||||
|
||||
if f"{msg.from_user.id}.json" not in os.listdir("data/users/"):
|
||||
user_locale = msg.from_user.language_code
|
||||
|
||||
if f"{msg.from_user.id}.json" not in listdir(f"data{sep}users{sep}"):
|
||||
logWrite(f'Creating blank data file for {msg.from_user.id}')
|
||||
jsonSave( f"data/users/{msg.from_user.id}.json", {"api_key": None, "linked": False, "context": {"action": None, "data": None}} )
|
||||
jsonSave( f"data{sep}users{sep}{msg.from_user.id}.json", {"api_key": None, "linked": False, "context": {"action": None, "data": None}} )
|
||||
|
||||
if not userGet(msg.from_user.id, "linked"):
|
||||
msg.reply_text(locale("link_input", "msg"), reply_markup=ForceReply(placeholder=locale("link", "fry")))
|
||||
@@ -45,13 +47,15 @@ def unlink(app, msg):
|
||||
|
||||
app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
||||
|
||||
user_locale = msg.from_user.language_code
|
||||
|
||||
if not userGet(msg.from_user.id, "linked"):
|
||||
msg.reply_text(locale("not_linked", "msg"))
|
||||
else:
|
||||
try:
|
||||
keys_storage = jsonLoad("data/keys_storage.json")
|
||||
keys_storage = jsonLoad(f"data{sep}keys_storage.json")
|
||||
del keys_storage[userGet(msg.from_user.id, "api_key")]
|
||||
jsonSave("data/keys_storage.json", keys_storage)
|
||||
jsonSave(f"data{sep}keys_storage.json", keys_storage)
|
||||
except:
|
||||
pass
|
||||
userClear(msg.from_user.id, "api_key")
|
||||
@@ -63,6 +67,8 @@ def cancel(app, msg):
|
||||
|
||||
app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
||||
|
||||
user_locale = msg.from_user.language_code
|
||||
|
||||
if userGet(msg.from_user.id, "context") is not None:
|
||||
userClear(msg.from_user.id, "context")
|
||||
userClear(msg.from_user.id, "context_content")
|
||||
@@ -76,7 +82,7 @@ def kill(app, msg):
|
||||
|
||||
if msg.from_user.id == configGet("admin"):
|
||||
msg.reply_text(f"Shutting down bot with pid `{pid}`")
|
||||
os.system('kill -9 '+str(pid))
|
||||
system('kill -9 '+str(pid)) # REFACTOR
|
||||
|
||||
|
||||
@app.on_message(~ filters.scheduled)
|
||||
@@ -84,13 +90,15 @@ def any_message_handler(app, msg):
|
||||
|
||||
if userGet(msg.from_user.id, "context") == "link_key":
|
||||
|
||||
user_locale = msg.from_user.language_code
|
||||
|
||||
if msg.text in jsonLoad(configGet("api_keys"))["autozoom"]:
|
||||
msg.reply_text(locale("key_correct", "msg"))
|
||||
userSet(msg.from_user.id, "api_key", msg.text)
|
||||
userSet(msg.from_user.id, "linked", True)
|
||||
keys_storage = jsonLoad("data/keys_storage.json")
|
||||
keys_storage = jsonLoad(f"data{sep}keys_storage.json")
|
||||
keys_storage[msg.text] = msg.from_user.id
|
||||
jsonSave("data/keys_storage.json", keys_storage)
|
||||
jsonSave(f"data{sep}keys_storage.json", keys_storage)
|
||||
logWrite(f"Added apikey {msg.text} for user {msg.from_user.id}")
|
||||
else:
|
||||
logWrite(f"User {msg.from_user.id} tried to pair with invalid apikey {msg.text}")
|
||||
|
||||
Reference in New Issue
Block a user