init
This commit is contained in:
commit
f4a511ca44
12 files changed
+159
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from telegram import BotCommand, Update
|
||||
from telegram.ext import Application, ApplicationBuilder, CommandHandler, ContextTypes
|
||||
|
||||
from serverssh import (
|
||||
create_download_link,
|
||||
execute_server_audit,
|
||||
get_user_by_tid,
|
||||
remove_audit_file,
|
||||
)
|
||||
|
||||
load_dotenv()
|
||||
|
||||
async def load_menu(app: Application) -> None:
|
||||
await app.bot.set_my_commands(
|
||||
[
|
||||
BotCommand("get_analytic_server", "Получить аналитику по удаленному серверу"),
|
||||
BotCommand("download_data", "Получить данные пользователя"),
|
||||
])
|
||||
|
||||
app = ApplicationBuilder().token(os.getenv('BOT_TOKEN')).post_init(load_menu).build()
|
||||
|
||||
async def download_data(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
await update.message.reply_text('Обращаемся к удаленному серверу по данным пользователя...')
|
||||
user = get_user_by_tid(tid=update.effective_user.id)
|
||||
now_utc = date.today()
|
||||
if user:
|
||||
execute_server_audit(user=user[2], pwd=user[3])
|
||||
create_download_link(user=user[2], pwd=user[3])
|
||||
remove_audit_file(user=user[2], pwd=user[3])
|
||||
chat_id = update.effective_chat.id
|
||||
context.bot.send_document(chat_id, document=open(f'audit_{now_utc}.txt', 'rb'))
|
||||
|
||||
app.add_handler(CommandHandler("download_data", download_data))
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run_polling()
|
||||
Reference in new issue
Block a user