2022-10-17 00:30:07 +03:00
|
|
|
import asyncio
|
2022-10-20 16:08:46 +03:00
|
|
|
from time import time
|
2022-10-17 00:30:07 +03:00
|
|
|
from os import getpid, listdir
|
|
|
|
from modules.utils import *
|
|
|
|
|
|
|
|
from pyrogram.client import Client
|
|
|
|
from pyrogram import filters
|
2022-10-20 13:24:32 +03:00
|
|
|
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat, ReplyKeyboardMarkup, ForceReply
|
2022-10-17 00:30:07 +03:00
|
|
|
from pyrogram import idle # type: ignore
|
|
|
|
from pyrogram.errors.exceptions import bad_request_400
|
|
|
|
|
|
|
|
pid = getpid()
|
|
|
|
|
|
|
|
app = Client("holochecker", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
|
|
|
|
2022-10-20 13:24:32 +03:00
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["start"], prefixes=["/"]))
|
|
|
|
async def cmd_start(app, msg):
|
|
|
|
|
|
|
|
try:
|
2022-10-20 15:43:13 +03:00
|
|
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
|
|
|
if user_stage != 0:
|
2022-10-20 13:24:32 +03:00
|
|
|
return
|
|
|
|
except FileNotFoundError:
|
|
|
|
jsonSave(jsonLoad(f"data{sep}user_default.json"), f"data{sep}users{sep}{msg.from_user.id}.json")
|
2022-10-20 15:43:13 +03:00
|
|
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
2022-10-20 16:08:46 +03:00
|
|
|
configSet("telegram_id", str(msg.from_user.username), file=str(msg.from_user.id))
|
|
|
|
configSet("telegram_name", f"{msg.from_user.first_name} {msg.from_user.last_name}", file=str(msg.from_user.id))
|
|
|
|
configSet("telegram_phone", str(msg.from_user.phone_number), file=str(msg.from_user.id))
|
|
|
|
configSet("telegram_locale", str(msg.from_user.language_code), file=str(msg.from_user.id))
|
2022-10-20 13:24:32 +03:00
|
|
|
|
2022-10-20 16:08:46 +03:00
|
|
|
await msg.reply_text(locale("start", "message"), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboards"), resize_keyboard=True))
|
2022-10-20 13:24:32 +03:00
|
|
|
|
2022-10-17 00:30:07 +03:00
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
|
|
|
|
async def cmd_kill(app, msg):
|
|
|
|
|
|
|
|
if (msg.from_user.id == configGet("owner")) or (msg.from_user.id in configGet("admins")):
|
|
|
|
logWrite(f"Shutting down bot with pid {pid}")
|
|
|
|
await msg.reply_text(f"Вимкнення бота з підом `{pid}`")
|
|
|
|
killProc(pid)
|
|
|
|
|
2022-10-20 13:24:32 +03:00
|
|
|
@app.on_message(~ filters.scheduled & (filters.regex(locale("welcome", "keyboards")[0][0]) | filters.regex(locale("return", "keyboards")[0][0])))
|
2022-10-20 15:43:13 +03:00
|
|
|
async def welcome_pass(app, msg):
|
2022-10-20 13:24:32 +03:00
|
|
|
|
|
|
|
await msg.reply_text(locale("privacy_notice", "message"))
|
|
|
|
await msg.reply_text(locale("question1", "message"), reply_markup=ForceReply(placeholder=locale("question1", "force_reply")))
|
2022-10-20 15:43:13 +03:00
|
|
|
configSet("stage", 1, file=str(msg.from_user.id))
|
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled & (filters.regex(locale("welcome", "keyboards")[1][0])))
|
|
|
|
async def welcome_reject(app, msg):
|
|
|
|
|
2022-10-20 16:08:46 +03:00
|
|
|
await msg.reply_text(locale("goodbye", "message"), reply_markup=ReplyKeyboardMarkup(locale("return", "keyboards"), resize_keyboard=True))
|
|
|
|
|
|
|
|
|
|
|
|
@app.on_message(~ filters.scheduled)
|
|
|
|
async def any_stage(app, msg):
|
|
|
|
|
|
|
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
|
|
|
|
|
|
|
if user_stage == 1:
|
|
|
|
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder="Enter shit"))
|
|
|
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
|
|
|
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
|
|
|
else:
|
|
|
|
if user_stage <= 9:
|
|
|
|
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder="Enter shit"))
|
|
|
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
|
|
|
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
|
|
|
else:
|
|
|
|
if not configGet("sent", file=str(msg.from_user.id)):
|
|
|
|
await msg.reply_text("You are fucking done, great job!")
|
|
|
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
|
|
|
configSet("sent", True, file=str(msg.from_user.id))
|
|
|
|
configSet("application_date", int(time()), file=str(msg.from_user.id))
|
|
|
|
else:
|
|
|
|
await msg.reply_text("You are already done, wait!")
|
2022-10-20 13:24:32 +03:00
|
|
|
|
2022-10-17 00:30:07 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
logWrite(f"Starting up with pid {pid}")
|
|
|
|
|
|
|
|
# Yes, it should be in some kind of async main() function but I don't give a shit.
|
2022-10-20 13:24:32 +03:00
|
|
|
# I did compare performance, almost no difference and it's much more useful this way. Change my mind.
|
2022-10-17 00:30:07 +03:00
|
|
|
app.start() # type: ignore
|
|
|
|
|
|
|
|
app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") # type: ignore
|
|
|
|
|
|
|
|
# Registering user commands for fallback locale
|
|
|
|
commands_list = []
|
|
|
|
for command in configGet("commands"):
|
|
|
|
commands_list.append(BotCommand(command, configGet("commands")[command]))
|
|
|
|
app.set_bot_commands(commands_list) # type: ignore
|
|
|
|
|
|
|
|
# Registering admin commands
|
|
|
|
commands_admin_list = []
|
|
|
|
for command in configGet("commands"):
|
|
|
|
commands_admin_list.append(BotCommand(command, configGet("commands")[command]))
|
|
|
|
|
|
|
|
for command in configGet("commands_admin"):
|
|
|
|
commands_admin_list.append(BotCommand(command, configGet("commands_admin")[command]))
|
|
|
|
|
|
|
|
for admin in configGet("admins"):
|
|
|
|
try:
|
|
|
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=admin)) # type: ignore
|
|
|
|
except bad_request_400.PeerIdInvalid:
|
|
|
|
pass
|
|
|
|
|
|
|
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("owner"))) # type: ignore
|
|
|
|
|
|
|
|
idle()
|
|
|
|
|
|
|
|
app.send_message(configGet("owner"), f"Shutting with pid `{pid}`") # type: ignore
|
|
|
|
|
|
|
|
app.stop() # type: ignore
|
|
|
|
|
|
|
|
killProc(pid)
|