-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
163 lines (113 loc) · 4.59 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from torrent-client import downloading
# function to handle the /start command
log_time = 5
def start(update, context):
update.message.reply_text('You can use this bot to download files from torrent')
update.message.reply_text(main_menu_message(), reply_markup=main_menu_keyboard())
def main_menu_message():
return 'Choose the option in main menu:'
def first_menu_message():
return 'Choose the logging time:'
def second_menu_message():
return 'Choose the option in main menu:'
def third_menu_message():
return 'Choose the option in main menu:'
def fourth_menu_message():
return 'Choose the option in main menu:'
def main_menu_keyboard():
keyboard = [[InlineKeyboardButton('Change log_time', callback_data='m1')]]
return InlineKeyboardMarkup(keyboard)
def main_menu(update, context):
query = update.callback_query
query.answer()
query.edit_message_text(
text=main_menu_message(),
reply_markup=main_menu_keyboard())
def first_menu(update, context):
query = update.callback_query
query.answer()
query.edit_message_text(
text=first_menu_message(),
reply_markup=first_menu_keyboard())
def first_menu_keyboard():
keyboard = [[InlineKeyboardButton('5', callback_data='m3')],
[InlineKeyboardButton('10', callback_data='m2')],
[InlineKeyboardButton('20', callback_data='m4')],
[InlineKeyboardButton('Main menu', callback_data='main')]]
return InlineKeyboardMarkup(keyboard)
def second_menu_keyboard():
keyboard = [[InlineKeyboardButton('Main menu', callback_data='main')]]
return InlineKeyboardMarkup(keyboard)
def third_menu_keyboard():
keyboard = [[InlineKeyboardButton('Main menu', callback_data='main')]]
return InlineKeyboardMarkup(keyboard)
def fourth_menu_keyboard():
keyboard = [[InlineKeyboardButton('Main menu', callback_data='main')]]
return InlineKeyboardMarkup(keyboard)
def text(update, context):
text_received = update.message.text
update.message.reply_text(f'did you said "{text_received}" ?')
def downloader(update, context):
name = update.message.document.file_name
file_torrent = context.bot.getFile(update.message.document.file_id)
file_torrent.download(name)
# writing to a custom file
with open(name, 'wb') as f:
context.bot.get_file(update.message.document).download(out=f)
global log_time
update.message.reply_text('File uploaded!')
fl = downloading(name, update, log_time)
def log_time_5(update, context):
global log_time
log_time = 5
print(log_time)
query = update.callback_query
query.answer()
query.edit_message_text(
text=second_menu_message(),
reply_markup=second_menu_keyboard())
def log_time_10(update, context):
global log_time
log_time = 10
print(log_time)
query = update.callback_query
query.answer()
query.edit_message_text(
text=third_menu_message(),
reply_markup=third_menu_keyboard())
def log_time_20(update, context):
global log_time
log_time = 20
print(log_time)
query = update.callback_query
query.answer()
query.edit_message_text(
text=fourth_menu_message(),
reply_markup=fourth_menu_keyboard())
def error(update, context):
print(f'Update {update} caused error {context.error}')
def main():
TOKEN = "2007164030:AAEhuQkk3Y_uHBdXBKpdQOjdw3Yz6CiqU6M"
# create the updater, that will automatically create also a dispatcher and a queue to
# make them dialoge
updater = Updater(TOKEN, use_context=True)
dispatcher = updater.dispatcher
# add handlers for start and help commands
dispatcher.add_handler(CommandHandler("start", start))
# add an handler for normal text (not commands)
dispatcher.add_handler(MessageHandler(Filters.text, text))
dispatcher.add_handler(CallbackQueryHandler(main_menu, pattern='main'))
dispatcher.add_handler(CallbackQueryHandler(first_menu, pattern='m1'))
dispatcher.add_handler(CallbackQueryHandler(log_time_5, pattern='m3'))
dispatcher.add_handler(CallbackQueryHandler(log_time_10, pattern='m2'))
dispatcher.add_handler(CallbackQueryHandler(log_time_20, pattern='m4'))
dispatcher.add_handler(MessageHandler(Filters.document, downloader))
dispatcher.add_error_handler(error)
# start your shiny new bot
updater.start_polling()
# run the bot until Ctrl-C
updater.idle()
if __name__ == '__main__':
main()