-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
130 lines (113 loc) · 4.03 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from tokens import *
import telebot
import os
import subprocess
from urllib.parse import unquote
from telebot import types
bot = telebot.TeleBot(bot_token)
msid = 0
@bot.callback_query_handler(func = lambda call: True)
def _ (call):
try:
if 'sendme' in call.data:
mkvnum = call.data.replace('sendme ', '')
path = mkvnum.split()[1]
mkvnum = mkvnum.split()[0]
print('path = ', path)
current_path = use_command_os('pwd')
if path not in current_path:
os.chdir('/data/data/com.termux/files/home/storage/movies/' + path)
ls = use_command_os('ls | grep mkv')
ls = ls.splitlines()
mkvname = ls[0]
for i in ls:
if mkvnum in i and i.split()[0] == mkvnum:
mkvname = i
break
f = open(mkvname, 'rb')
print('sending...')
msid = bot.send_message(rockxi, 'Отправляю...').message_id
bot.send_document(rockxi, f, timeout=200)
bot.delete_message(chat_id=rockxi, message_id=msid)
print('sended')
return
except Exception as e:
sm(str(e))
@bot.message_handler()
def _ (message):
user_id = message.chat.id
command = message.text
if user_id != rockxi:
bot.send_message(user_id, "Кря.")
return
try:
if 'cd' in command:
path = command.replace('cd ', '')
print(command)
if path == '~':
os.chdir('/data/data/com.termux/files/home')
os.chdir(path)
out = sm(use_command('pwd'))
return
if command == 'course':
os.chdir('/data/data/com.termux/files/home/storage/movies')
sm(use_command('pwd'))
return
sendme = 'sendme'
if sendme in command:
if sendme == command:
link_generator()
return
mkvname = command.replace(f'{sendme} ', '')
if len(mkvname) == 3 and mkvname[1] == '.':
mkvname = sm(use_command_os('ls | grep ' + mkvname))
print(f'mkvname = "{mkvname}"')
if '.mkv' not in mkvname: sm(f'{sendme} <имя файла.mkv>'); return
lsList = use_command_os('ls')
if sendme in mkvname: mkvname.replect(sendme + ' ', '')
if mkvname not in lsList: sm('File not found.'); return
f = open(mkvname, 'rb')
print('sending...')
bot.send_document(rockxi, f, timeout=200)
print('sended')
return
result = use_command(command)
sm(result)
print(command)
except Exception as e:
try:
os.system(command)
out = os.popen(command).read()
if not out:
out = '-> empty string <-'
sm(out)
except Exception as e:
print(e)
sm(str(e))
def use_command(command : str) -> str:
subprocess.run(command.split(), capture_output=True)
output = subprocess.check_output(command)
return unquote(output)
def use_command_os(command : str) -> str:
os.system(command)
out = os.popen(command).read()
if not out:
out = '-> empty string <-'
return out
def sm(message):
bot.send_message(rockxi, message)
return message
#wtf
def link_generator():
ls = use_command_os('ls | grep mkv')
ls = ls.splitlines()
keyboard = types.InlineKeyboardMarkup(row_width=2)
path = use_command_os('pwd')
path = path.replace('/storage/emulated/0/Movies/', '')
for i in ls:
calldata = i.split()[0]
keyboard.add(types.InlineKeyboardButton(text = i, callback_data=f'sendme {calldata} {path}'))
ls = '\n'.join(ls)
bot.send_message(chat_id=rockxi, text='Выберите файл:', reply_markup=keyboard)
#pollingpollingpollingpollingpollingpollingpollingpollingpollingpollingpollingpollingpollingpolling
bot.infinity_polling(20, True)