Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
92 lines (79 loc) · 4.09 KB
/
Copy pathbot.py
File metadata and controls
92 lines (79 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import sys
from datetime import datetime
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, MessageHandler, filters, ContextTypes
from config import BOT_TOKEN, ADMIN_IDS, ADMIN_ID
from utils.logger import logger
from utils.auth import admin_only
from utils.keyboard import get_main_menu
# Import handlers
from handlers.power import handle_power_menu, handle_power_action, handle_power_confirm
from handlers.cleaner import handle_cleaner_menu, handle_cleaner_action
from handlers.system import handle_system_menu, handle_system_action
from handlers.files import handle_files_menu, handle_files_action, handle_file_download, handle_file_path_upload
from handlers.security import handle_settings_menu, error_handler
@admin_only
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = update.effective_user
logger.info(f"Bot started by {user.first_name} ({user.id})")
await update.message.reply_text(
f"👋 **Welcome to GHOST-HAND, {user.first_name}!**\n\n"
"Your computer is now under your command via Telegram.\n"
"Select a category below to begin:",
reply_markup=get_main_menu(),
parse_mode='Markdown'
)
async def main_menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()
await query.edit_message_text(
"🖥 **MAIN MENU**\nSelect a category:",
reply_markup=get_main_menu(),
parse_mode='Markdown'
)
async def post_init(application):
"""Notification when the bot starts up"""
for admin_id in ADMIN_IDS:
try:
await application.bot.send_message(
chat_id=admin_id,
text=f"🚀 <b>GHOST-HAND is Online!</b>\n"
f"💻 Your PC is now connected and ready for commands.\n"
f"⏰ Time: <code>{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</code>",
parse_mode='HTML'
)
logger.info(f"Startup notification sent to Admin: {admin_id}")
except Exception as e:
logger.error(f"Failed to send startup notification to {admin_id}: {e}")
def main():
if not BOT_TOKEN:
logger.critical("BOT_TOKEN not found in .env file! Exiting.")
sys.exit(1)
if not ADMIN_IDS:
logger.warning("ADMIN_IDS not set! The bot will block all commands. Please update your .env file.")
application = ApplicationBuilder().token(BOT_TOKEN).post_init(post_init).build()
# Base Commands
application.add_handler(CommandHandler("start", start))
# Callback Handlers (Menus)
application.add_handler(CallbackQueryHandler(main_menu_callback, pattern="^menu_main$"))
application.add_handler(CallbackQueryHandler(handle_power_menu, pattern="^menu_power$"))
application.add_handler(CallbackQueryHandler(handle_cleaner_menu, pattern="^menu_cleaner$"))
application.add_handler(CallbackQueryHandler(handle_system_menu, pattern="^menu_system$"))
application.add_handler(CallbackQueryHandler(handle_files_menu, pattern="^menu_files$"))
application.add_handler(CallbackQueryHandler(handle_settings_menu, pattern="^menu_settings$"))
# Action Handlers
application.add_handler(CallbackQueryHandler(handle_power_action, pattern="^pwr_"))
application.add_handler(CallbackQueryHandler(handle_power_confirm, pattern="^confirm_"))
application.add_handler(CallbackQueryHandler(handle_cleaner_action, pattern="^cln_"))
application.add_handler(CallbackQueryHandler(handle_system_action, pattern="^sys_"))
application.add_handler(CallbackQueryHandler(handle_files_action, pattern="^file_"))
# File Handlers
application.add_handler(MessageHandler(filters.Document.ALL | filters.PHOTO | filters.VIDEO | filters.AUDIO | filters.VOICE, handle_file_download))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_file_path_upload))
# Error Handler
application.add_error_handler(error_handler)
logger.info("Bot is starting...")
application.run_polling()
if __name__ == '__main__':
main()