inital update
swadhinbiswas committed 2 years ago
2920c72
1 parent b9bedb3
commit 2920c72
13 files changed
+111 -0
Showing 13 changed files+111-0
app/bot/__init__.pyapp/bot/helper/__init__.pyapp/bot/helper/authorize.pyapp/bot/helper/ext-utils/__init__.pyapp/bot/helper/telegram_helper/__init__.pyapp/bot/helper/telegram_helper/bot_command.pyapp/bot/helper/telegram_helper/button_build.pyapp/bot/helper/telegram_helper/filters.pyapp/bot/helper/telegram_helper/message_utils.pyapp/database/__init__.pyapp/models/__init__.pyapp/schemas/__init__.pyapp/settings/__init__.py
▼app/bot/__init__.py
+0-0
0 | 0 |
▼app/bot/helper/__init__.py
+0-0
0 | 0 |
▼app/bot/helper/authorize.py
+0-0
0 | 0 |
▼app/bot/helper/ext-utils/__init__.py
+1-0
| @@ -0,0 +1 @@ | ||
1 | + | |
0 | 2 | |
▼app/bot/helper/telegram_helper/__init__.py
+0-0
0 | 0 |
▼app/bot/helper/telegram_helper/bot_command.py
+29-0
| @@ -0,0 +1,29 @@ | ||
1 | +class _BotCommands: | |
2 | + def __init__(self): | |
3 | + self.StartCommand = 'start' | |
4 | + self.HelpCommand = 'help' | |
5 | + self.MemeCommand = 'meme' | |
6 | + self.UnzipCommand = 'unzip' | |
7 | + self.ZipCommand = 'zip' | |
8 | + self.CancelCommand = 'cancel' | |
9 | + self.Author='author' | |
10 | + self.About='about' | |
11 | + self.Settings='settings' | |
12 | + self.Restart='restart' | |
13 | + self.Stats='stats' | |
14 | + self.leetch='leetch' | |
15 | + self.clones='clones' | |
16 | + self.speedtest='speedtest' | |
17 | + self.upload='upload' | |
18 | + self.search='search' | |
19 | + self.cancelMirror='cancelMirror' | |
20 | + self.cancelAll='cancelAll' | |
21 | + self.delete='delete' | |
22 | + self.log='log' | |
23 | + self.exec='exec' | |
24 | + self.addMirror='addMirror' | |
25 | + | |
26 | + | |
27 | + | |
28 | + | |
29 | +Botcommands=_BotCommands() | |
0 | 30 | |
▼app/bot/helper/telegram_helper/button_build.py
+28-0
| @@ -0,0 +1,28 @@ | ||
1 | +from telegram import InlineKeyboardButton, InlineKeyboardMarkup | |
2 | + | |
3 | +class ButtonBuild: | |
4 | + def __init__(self): | |
5 | + self.button = [] | |
6 | + | |
7 | + def buildbutton(self,key,link): | |
8 | + self.button.append([InlineKeyboardButton(text=key, url=link)]) | |
9 | + | |
10 | + def subbutton(self,key,link): | |
11 | + self.button.append([InlineKeyboardButton(text=key, callback_data=link)]) | |
12 | + | |
13 | + def build_menu(self,buttons,n_cols,header_buttons=None,footer_buttons=None): | |
14 | + menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] | |
15 | + if header_buttons: | |
16 | + menu.insert(0, header_buttons) | |
17 | + if footer_buttons: | |
18 | + menu.append(footer_buttons) | |
19 | + return menu | |
20 | + | |
21 | + def build_menu2(self,buttons,n_cols,header_buttons=None,footer_buttons=None): | |
22 | + menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] | |
23 | + if header_buttons: | |
24 | + menu.insert(0, header_buttons) | |
25 | + if footer_buttons: | |
26 | + menu.append(footer_buttons) | |
27 | + return menu | |
28 | + | |
0 | 29 | |
▼app/bot/helper/telegram_helper/filters.py
+51-0
| @@ -0,0 +1,51 @@ | ||
1 | +from telegram.ext import MessageFilter | |
2 | +from telegram import Message | |
3 | +from bot import AUTHORIZED_CHATS, SUDO_USERS, OWNER_ID, download_dict, download_dict_lock | |
4 | + | |
5 | + | |
6 | +class CustomFilters: | |
7 | + class _OwnerFilter(MessageFilter): | |
8 | + def filter(self, message): | |
9 | + return bool(message.from_user.id == OWNER_ID) | |
10 | + | |
11 | + owner_filter = _OwnerFilter() | |
12 | + | |
13 | + class _AuthorizedUserFilter(MessageFilter): | |
14 | + def filter(self, message): | |
15 | + id = message.from_user.id | |
16 | + return bool(id in AUTHORIZED_CHATS or id in SUDO_USERS or id == OWNER_ID) | |
17 | + | |
18 | + authorized_user = _AuthorizedUserFilter() | |
19 | + | |
20 | + class _AuthorizedChat(MessageFilter): | |
21 | + def filter(self, message): | |
22 | + return bool(message.chat.id in AUTHORIZED_CHATS) | |
23 | + | |
24 | + authorized_chat = _AuthorizedChat() | |
25 | + | |
26 | + class _SudoUser(MessageFilter): | |
27 | + def filter(self,message): | |
28 | + return bool(message.from_user.id in SUDO_USERS) | |
29 | + | |
30 | + sudo_user = _SudoUser() | |
31 | + | |
32 | + class _MirrorOwner(MessageFilter): | |
33 | + def filter(self, message: Message): | |
34 | + user_id = message.from_user.id | |
35 | + if user_id == OWNER_ID: | |
36 | + return True | |
37 | + args = str(message.text).split(' ') | |
38 | + if len(args) > 1: | |
39 | + # Cancelling by gid | |
40 | + with download_dict_lock: | |
41 | + for message_id, status in download_dict.items(): | |
42 | + if status.gid() == args[1] and status.message.from_user.id == user_id: | |
43 | + return True | |
44 | + else: | |
45 | + return False | |
46 | + if not message.reply_to_message and len(args) == 1: | |
47 | + return True | |
48 | + # Cancelling by replying to original mirror message | |
49 | + reply_user = message.reply_to_message.from_user.id | |
50 | + return bool(reply_user == user_id) | |
51 | + mirror_owner_filter = _MirrorOwner() | |
0 | 52 | |
▼app/bot/helper/telegram_helper/message_utils.py
+2-0
| @@ -0,0 +1,2 @@ | ||
1 | + | |
2 | + | |
0 | 3 | |
▼app/database/__init__.py
+0-0
0 | 0 |
▼app/models/__init__.py
+0-0
0 | 0 |
▼app/schemas/__init__.py
+0-0
0 | 0 |
▼app/settings/__init__.py
+0-0
0 | 0 |