forked from SpEcHiDe/PublicLeech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
233 lines (206 loc) · 6.88 KB
/
bot.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2020 PublicLeech Authors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import shutil
from publicleechgroup import (
APP_ID,
API_HASH,
AUTH_CHANNEL,
DOWNLOAD_LOCATION,
LOGGER,
SHOULD_USE_BUTTONS,
TG_BOT_TOKEN,
DIS_ABLE_ST_GFC_COMMAND_I,
SLEEP_THRES_HOLD,
SUDO_USERS
)
from pyrogram import (
Client,
filters,
__version__
)
from pyrogram.handlers import (
MessageHandler,
CallbackQueryHandler
)
from publicleechgroup.plugins.new_join_fn import (
new_join_f,
help_message_f
)
from publicleechgroup.plugins.incoming_message_fn import (
incoming_message_f,
incoming_youtube_dl_f,
incoming_purge_message_f,
leech_commandi_f
)
from publicleechgroup.plugins.status_message_fn import (
status_message_f,
cancel_message_f,
exec_message_f,
eval_message_f,
upload_document_f,
save_rclone_conf_f,
upload_log_file
)
from publicleechgroup.plugins.call_back_button_handler import button
from publicleechgroup.plugins.custom_thumbnail import (
save_thumb_nail,
clear_thumb_nail
)
from publicleechgroup.helper_funcs.custom_filters import message_fliter
from publicleechgroup.dinmamoc import Commandi
class Bot(Client):
""" modded client """
def __init__(self):
super().__init__(
":memory:",
bot_token=TG_BOT_TOKEN,
api_id=APP_ID,
api_hash=API_HASH,
workers=343,
workdir=DOWNLOAD_LOCATION,
parse_mode="html",
sleep_threshold=SLEEP_THRES_HOLD,
# TODO: utilize PSP
# plugins={
# "root": "bot/plugins"
# }
)
async def start(self):
await super().start()
usr_bot_me = await self.get_me()
# create download directory, if not exist
if not os.path.isdir(DOWNLOAD_LOCATION):
os.makedirs(DOWNLOAD_LOCATION)
LOGGER(__name__).info(
"@PublicLeechGroup, trying to add handlers"
)
# PURGE command
self.add_handler(MessageHandler(
incoming_purge_message_f,
filters=filters.command(
[Commandi.PURGE]
) & filters.chat(chats=AUTH_CHANNEL)
))
# STATUS command
self.add_handler(MessageHandler(
status_message_f,
filters=filters.command(
[Commandi.STATUS]
) & filters.chat(chats=AUTH_CHANNEL)
))
# CANCEL command
self.add_handler(MessageHandler(
cancel_message_f,
filters=filters.command([Commandi.CANCEL]) & filters.chat(chats=AUTH_CHANNEL)
))
if not SHOULD_USE_BUTTONS:
LOGGER(__name__).info("using COMMANDi mode")
# LEECH command
self.add_handler(MessageHandler(
leech_commandi_f,
filters=filters.command(
[Commandi.LEECH]
) & filters.chat(chats=AUTH_CHANNEL)
))
# YTDL command
self.add_handler(MessageHandler(
incoming_youtube_dl_f,
filters=filters.command(
[Commandi.YTDL]
) & filters.chat(chats=AUTH_CHANNEL)
))
else:
LOGGER(__name__).info("using BUTTONS mode")
# all messages filter
# in the AUTH_CHANNELs
self.add_handler(MessageHandler(
incoming_message_f,
filters=message_fliter & filters.chat(chats=AUTH_CHANNEL)
))
# button is LEGACY command to handle
# the OLD YTDL buttons,
# and also the new SUB buttons
self.add_handler(CallbackQueryHandler(
button
))
if DIS_ABLE_ST_GFC_COMMAND_I:
self.add_handler(MessageHandler(
exec_message_f,
filters=filters.command([Commandi.EXEC]) & filters.user(users=SUDO_USERS)
))
self.add_handler(MessageHandler(
eval_message_f,
filters=filters.command([Commandi.EVAL]) & filters.user(users=SUDO_USERS)
))
# MEMEs COMMANDs
self.add_handler(MessageHandler(
upload_document_f,
filters=filters.command([Commandi.UPLOAD]) & filters.user(users=SUDO_USERS)
))
# HELP command
self.add_handler(MessageHandler(
help_message_f,
filters=filters.command(
[Commandi.HELP]
) & filters.chat(chats=AUTH_CHANNEL)
))
# not AUTH CHANNEL users
self.add_handler(MessageHandler(
new_join_f,
filters=~filters.chat(chats=AUTH_CHANNEL)
))
# welcome MESSAGE
self.add_handler(MessageHandler(
help_message_f,
filters=filters.chat(chats=AUTH_CHANNEL) & filters.new_chat_members
))
# savethumbnail COMMAND
self.add_handler(MessageHandler(
save_thumb_nail,
filters=filters.command(
[Commandi.SAVETHUMBNAIL]
) & filters.chat(chats=AUTH_CHANNEL)
))
# clearthumbnail COMMAND
self.add_handler(MessageHandler(
clear_thumb_nail,
filters=filters.command(
[Commandi.CLEARTHUMBNAIL]
) & filters.chat(chats=AUTH_CHANNEL)
))
# an probably easy way to get RClone CONF URI
self.add_handler(MessageHandler(
save_rclone_conf_f,
filters=filters.command(
[Commandi.GET_RCLONE_CONF_URI]
) & filters.user(users=SUDO_USERS)
))
# Telegram command to upload LOG files
self.add_handler(MessageHandler(
upload_log_file,
filters=filters.command(
[Commandi.UPLOAD_LOG_FILE]
) & filters.user(users=SUDO_USERS)
))
LOGGER(__name__).info(
f"@{usr_bot_me.username} based on Pyrogram v{__version__} "
)
async def stop(self, *args):
await super().stop()
shutil.rmtree(
DOWNLOAD_LOCATION,
ignore_errors=True
)
LOGGER(__name__).info("PublicLeechGroup stopped. Bye.")