-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.py
92 lines (77 loc) · 3.39 KB
/
kernel.py
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
#!/usr/bin/python3
import requests
import logging
import subprocess
from aiogram import F
import os
from aiogram import Bot, Dispatcher
from aiogram.types import Message, FSInputFile
from aiogram.filters import Command, CommandObject
TOKEN = "token" # token here
admins = {1234567890,1234567891} # admins id
timeout = 45 # timeout seconds, to apply terminal(cmd).
for admin in admins:
requests.get(f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={admin}&text=notebook%20is%20on!")
dp = Dispatcher()
logger = logging.getLogger(__name__)
@dp.message(Command(commands=["start"]))
async def command_start_handler(message: Message, bot: Bot) -> None:
if message.from_user.id in admins:
await message.answer("hello")
else:
for admin in admins:
await bot.send_message(admin,f"{message.from_user.id} - unauthorized access to command")
@dp.message(Command(commands=["send"]))
async def send_file(message: Message, command: CommandObject, bot: Bot) -> None:
if message.from_user.id in admins:
try:
await bot.send_document(message.chat.id, FSInputFile(command.args))
except Exception as error:
await message.answer(str(error))
else:
for admin in admins:
await bot.send_message(admin,f"{message.from_user.id} - unauthorized access to command")
@dp.message(Command(commands=["screenshot"]))
async def screenshot(message: Message, command: CommandObject, bot: Bot) -> None:
if message.from_user.id in admins:
try:
os.system('import -window root root.png')
if command.args == "-no":
await bot.send_document(message.chat.id, FSInputFile('root.png'))
else:
await bot.send_photo(message.chat.id, FSInputFile("root.png"))
os.system('rm -rf root.png')
except Exception as error:
await message.answer(str(error))
else:
for admin in admins:
await bot.send_message(admin,f"{message.from_user.id} - unauthorized access to command")
@dp.message(F.document)
async def download(message: Message, bot: Bot):
if message.from_user.id in admins:
try:
msg = await bot.send_message(message.from_user.id, "⌛")
file = await bot.get_file(message.document.file_id)
await bot.download_file(file.file_path, message.document.file_name)
await bot.edit_message_text('Successfully loaded ✅',message.chat.id, msg.message_id)
except Exception as error:
await bot.edit_message_text(str(error), message.chat.id, msg.message_id)
else:
for admin in admins:
await bot.send_message(admin,f"{message.from_user.id} - unauthorized access to command")
@dp.message(Command(commands=["cmd","c"]))
async def system(message: Message, command: CommandObject, bot : Bot) -> None:
if message.from_user.id in admins:
try:
bbb = subprocess.check_output(command.args, shell=True,stderr=subprocess.STDOUT,timeout=timeout).decode('utf-8')
await message.answer(f'<code>{bbb}</code>')
except Exception as error:
await message.answer(str(error))
else:
for admin in admins:
await bot.send_message(admin,f"{message.from_user.id} - unauthorized access to command")
def main() -> None:
bot = Bot(TOKEN, parse_mode="HTML")
dp.run_polling(bot)
if __name__ == "__main__":
main()