2022-09-14 14:01:31 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from sys import exit
|
2022-09-15 12:07:39 +03:00
|
|
|
from os import getpid, listdir, sep
|
2022-09-14 14:01:31 +03:00
|
|
|
from modules.functions import *
|
|
|
|
from modules.functions_bot import *
|
|
|
|
from pyrogram import Client, filters, idle
|
|
|
|
from pyrogram.types import ForceReply, BotCommand, BotCommandScopeChat
|
|
|
|
from pyrogram.enums.chat_action import ChatAction
|
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
|
2022-09-14 14:01:31 +03:00
|
|
|
if configGet("bot_token") != "12345678:asdfghjklzxcvbnm":
|
2022-09-15 01:16:38 +03:00
|
|
|
pid = getpid()
|
2022-09-14 14:01:31 +03:00
|
|
|
app = Client("auto_zoom_public_bot", api_id=configGet("api_id"), api_hash=configGet("api_hash"), bot_token=configGet("bot_token"))
|
|
|
|
else:
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite("Could not start the bot. Please, configure token in config.json", logs_folder=configGet("logs"))
|
2022-09-14 14:01:31 +03:00
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["link", "start"], prefixes="/"))
|
2022-09-15 12:07:39 +03:00
|
|
|
async def start(app, msg):
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f'Got command start/link from {msg.from_user.id}', logs_folder=configGet("logs"))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 01:16:38 +03:00
|
|
|
user_locale = msg.from_user.language_code
|
2022-09-15 13:45:29 +03:00
|
|
|
data = configGet("data")
|
2022-09-15 01:16:38 +03:00
|
|
|
|
2022-09-15 13:45:29 +03:00
|
|
|
if f"{msg.from_user.id}.json" not in listdir(f"{data}{sep}users{sep}"):
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f'Creating blank data file for {msg.from_user.id}', logs_folder=configGet("logs"))
|
2022-09-15 13:45:29 +03:00
|
|
|
jsonSave( f"{data}{sep}users{sep}{msg.from_user.id}.json", {"api_key": None, "linked": False, "context": {"action": None, "data": None}} )
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
if not userGet(msg.from_user.id, "linked"):
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("link_input", "msg", locale=user_locale), reply_markup=ForceReply(placeholder=locale("link", "fry", locale=user_locale)))
|
2022-09-14 14:01:31 +03:00
|
|
|
userSet(msg.chat.id, "context", "link_key")
|
|
|
|
else:
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("already_linked", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["unlink"], prefixes="/"))
|
2022-09-15 12:07:39 +03:00
|
|
|
async def unlink(app, msg):
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f'Got command ulink from {msg.from_user.id}', logs_folder=configGet("logs"))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 01:16:38 +03:00
|
|
|
user_locale = msg.from_user.language_code
|
2022-09-15 13:45:29 +03:00
|
|
|
data = configGet("data")
|
2022-09-15 01:16:38 +03:00
|
|
|
|
2022-09-14 14:01:31 +03:00
|
|
|
if not userGet(msg.from_user.id, "linked"):
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("not_linked", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
else:
|
|
|
|
try:
|
2022-09-15 13:45:29 +03:00
|
|
|
keys_storage = jsonLoad(f"{data}{sep}keys_storage.json")
|
2022-09-14 14:01:31 +03:00
|
|
|
del keys_storage[userGet(msg.from_user.id, "api_key")]
|
2022-09-15 13:45:29 +03:00
|
|
|
jsonSave(f"{data}{sep}keys_storage.json", keys_storage)
|
2022-09-14 14:01:31 +03:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
userClear(msg.from_user.id, "api_key")
|
|
|
|
userSet(msg.chat.id, "linked", False)
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("unlinked", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["cancel"], prefixes="/"))
|
2022-09-15 12:07:39 +03:00
|
|
|
async def cancel(app, msg):
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 01:16:38 +03:00
|
|
|
user_locale = msg.from_user.language_code
|
|
|
|
|
2022-09-14 14:01:31 +03:00
|
|
|
if userGet(msg.from_user.id, "context") is not None:
|
|
|
|
userClear(msg.from_user.id, "context")
|
|
|
|
userClear(msg.from_user.id, "context_content")
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("cancel", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
else:
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("cancel_empty", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
@app.on_message(filters.command(["kill", "die", "shutdown", "reboot"], prefixes="/"))
|
2022-09-15 12:07:39 +03:00
|
|
|
async def kill(app, msg):
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
if msg.from_user.id == configGet("admin"):
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(f"Shutting down bot with pid `{pid}`")
|
|
|
|
killProc(pid)
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled)
|
2022-09-15 12:07:39 +03:00
|
|
|
async def any_message_handler(app, msg):
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
if userGet(msg.from_user.id, "context") == "link_key":
|
|
|
|
|
2022-09-15 01:16:38 +03:00
|
|
|
user_locale = msg.from_user.language_code
|
2022-09-15 13:45:29 +03:00
|
|
|
data = configGet("data")
|
2022-09-15 01:16:38 +03:00
|
|
|
|
2022-09-14 14:01:31 +03:00
|
|
|
if msg.text in jsonLoad(configGet("api_keys"))["autozoom"]:
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("key_correct", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
userSet(msg.from_user.id, "api_key", msg.text)
|
|
|
|
userSet(msg.from_user.id, "linked", True)
|
2022-09-15 13:45:29 +03:00
|
|
|
keys_storage = jsonLoad(f"{data}{sep}keys_storage.json")
|
2022-09-14 14:01:31 +03:00
|
|
|
keys_storage[msg.text] = msg.from_user.id
|
2022-09-15 13:45:29 +03:00
|
|
|
jsonSave(f"{data}{sep}keys_storage.json", keys_storage)
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f"Added apikey {msg.text} for user {msg.from_user.id}", logs_folder=configGet("logs"))
|
2022-09-15 14:50:14 +03:00
|
|
|
elif msg.text in jsonLoad(configGet("expired_keys")):
|
|
|
|
logWrite(f"User {msg.from_user.id} tried to pair with expired apikey {msg.text}", logs_folder=configGet("logs"))
|
|
|
|
await msg.reply_text(locale("key_expired", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
else:
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f"User {msg.from_user.id} tried to pair with invalid apikey {msg.text}", logs_folder=configGet("logs"))
|
2022-09-15 12:07:39 +03:00
|
|
|
await msg.reply_text(locale("key_wrong", "msg", locale=user_locale))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
userClear(msg.from_user.id, "context")
|
|
|
|
userClear(msg.from_user.id, "context_content")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f'Starting with PID {str(pid)}', logs_folder=configGet("logs"))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
app.start()
|
|
|
|
app.send_message(configGet("admin"), f"Starting bot with pid `{pid}`")
|
2022-09-15 13:45:29 +03:00
|
|
|
|
|
|
|
locales = configGet("locales")
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 13:45:29 +03:00
|
|
|
for entry in listdir(locales):
|
2022-09-15 12:07:39 +03:00
|
|
|
|
|
|
|
if entry.endswith(".json"):
|
|
|
|
|
|
|
|
all_commands = locale("cmd", locale=entry.replace(".json", ""))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
# Registering user commands
|
|
|
|
commands_list = []
|
|
|
|
for command in all_commands["general"]:
|
|
|
|
commands_list.append(BotCommand(command, all_commands["general"][command]))
|
|
|
|
app.set_bot_commands(commands_list, language_code=entry.replace(".json", ""))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
# Registering admin commands
|
|
|
|
commands_admin_list = []
|
|
|
|
for command in all_commands["general"]:
|
|
|
|
commands_admin_list.append(BotCommand(command, all_commands["general"][command]))
|
|
|
|
for command in all_commands["admin"]:
|
|
|
|
commands_admin_list.append(BotCommand(command, all_commands["admin"][command]))
|
|
|
|
app.set_bot_commands(commands_admin_list, language_code=entry.replace(".json", ""), scope=BotCommandScopeChat(chat_id=configGet("admin")))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
|
|
|
idle()
|
|
|
|
|
|
|
|
app.send_message(configGet("admin"), f"Shutting down bot with pid `{pid}`")
|
2022-09-15 13:55:33 +03:00
|
|
|
logWrite(f'Shutting down with PID {pid}', logs_folder=configGet("logs"))
|
2022-09-14 14:01:31 +03:00
|
|
|
|
2022-09-15 12:07:39 +03:00
|
|
|
killProc(pid)
|