-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual_enhancer.py
More file actions
316 lines (263 loc) Β· 11.3 KB
/
Copy pathvisual_enhancer.py
File metadata and controls
316 lines (263 loc) Β· 11.3 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
"""
Visual Enhancements - Beautiful messages, animations, and progress indicators
"""
import asyncio
from typing import Optional
from telegram import Update, Message
from telegram.constants import ChatAction
from loguru import logger
class VisualEnhancer:
"""Enhance bot messages with emojis, formatting, and animations"""
@staticmethod
def escape_markdown(text: str) -> str:
"""Escape markdown special characters for Telegram"""
# Escape special markdown characters
special_chars = ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']
for char in special_chars:
text = text.replace(char, f'\\{char}')
return text
# Emoji sets
EMOJIS = {
'loading': ['β³', 'β'],
'progress': ['β±β±β±β±β±', 'β°β±β±β±β±', 'β°β°β±β±β±', 'β°β°β°β±β±', 'β°β°β°β°β±', 'β°β°β°β°β°'],
'scan': 'π',
'success': 'β
',
'error': 'β',
'warning': 'β οΈ',
'info': 'βΉοΈ',
'rocket': 'π',
'fire': 'π₯',
'star': 'β',
'check': 'β',
'cross': 'β',
'arrow': 'β',
'bullet': 'β’',
'shield': 'π‘οΈ',
'lock': 'π',
'globe': 'π',
'speed': 'β‘',
'chart': 'π',
'doc': 'π',
'folder': 'π',
'link': 'π',
'tools': 'π§',
'clock': 'β°',
'calendar': 'π
',
'location': 'π',
'server': 'π₯οΈ',
'database': 'ποΈ',
'download': 'β¬οΈ',
'upload': 'β¬οΈ',
'heart': 'β€οΈ',
'trophy': 'π',
'crown': 'π',
'gem': 'π',
'magic': 'β¨',
'party': 'π',
'target': 'π―',
'package': 'π¦',
'bug': 'π',
'robot': 'π€'
}
@staticmethod
def format_header(text: str, emoji: str = 'π') -> str:
"""Format header with emojis"""
line = 'β' * 30
return f"{line}\n{emoji} {text} {emoji}\n{line}"
@staticmethod
def format_section(title: str, emoji: str = 'π') -> str:
"""Format section title"""
return f"\n{emoji} {title}\n{'β' * 25}"
@staticmethod
def format_item(key: str, value: str, emoji: str = 'β’') -> str:
"""Format key-value item"""
return f"{emoji} {key}: {value}"
@staticmethod
def format_list(items: list, emoji: str = 'βͺοΈ') -> str:
"""Format list items"""
return '\n'.join([f"{emoji} {item}" for item in items])
@staticmethod
def create_progress_bar(current: int, total: int, width: int = 10) -> str:
"""Create visual progress bar"""
if total == 0:
return "β±" * width
filled = int((current / total) * width)
bar = "β°" * filled + "β±" * (width - filled)
percentage = int((current / total) * 100)
return f"{bar} {percentage}%"
@staticmethod
async def send_with_animation(message: Message, text: str, animation_type: str = 'typing'):
"""Send message with animation"""
try:
# Show action
if animation_type == 'typing':
await message.chat.send_action(ChatAction.TYPING)
elif animation_type == 'upload':
await message.chat.send_action(ChatAction.UPLOAD_DOCUMENT)
await asyncio.sleep(0.5)
# Send message
return await message.reply_text(text, parse_mode='Markdown')
except Exception as e:
logger.error(f"Animation error: {e}")
return await message.reply_text(text)
@staticmethod
async def show_progress(message: Message, current: int, total: int, item_name: str = "item"):
"""Update message with progress"""
try:
progress_bar = VisualEnhancer.create_progress_bar(current, total)
text = f"π Processing...\n\n{progress_bar}\n\n{current}/{total} {item_name}s completed"
await message.edit_text(text)
except Exception as e:
logger.error(f"Progress update error: {e}")
@staticmethod
def format_scan_result(result: dict) -> str:
"""Format scan result beautifully"""
try:
lines = []
# Header
lines.append(VisualEnhancer.format_header("Scan Complete", "π―"))
lines.append("")
# URL
if 'url' in result:
lines.append(f"π URL: {result['url']}")
lines.append("")
# Status
if 'status' in result:
status_emoji = 'β
' if result['status'] == 'success' else 'β'
lines.append(f"{status_emoji} Status: {result['status']}")
lines.append("")
# Summary stats
if 'summary' in result:
lines.append(VisualEnhancer.format_section("Summary", "π"))
for key, value in result['summary'].items():
emoji = VisualEnhancer._get_summary_emoji(key)
lines.append(VisualEnhancer.format_item(key, str(value), emoji))
lines.append("")
# Scanner count
if 'scanners' in result:
scanner_count = len(result['scanners'])
lines.append(f"π Scanners Used: {scanner_count}")
lines.append("")
lines.append("β" * 30)
return '\n'.join(lines)
except Exception as e:
logger.error(f"Format error: {e}")
return "β
Scan completed successfully"
@staticmethod
def format_batch_result(results: list, total_time: float) -> str:
"""Format batch scan results"""
try:
lines = []
lines.append(VisualEnhancer.format_header("Batch Scan Complete", "π"))
lines.append("")
successful = sum(1 for r in results if r.get('status') == 'success')
failed = len(results) - successful
lines.append(f"π Total Scans: {len(results)}")
lines.append(f"β
Successful: {successful}")
lines.append(f"β Failed: {failed}")
lines.append(f"β±οΈ Time: {total_time:.1f}s")
lines.append("")
# List URLs
lines.append(VisualEnhancer.format_section("Scanned URLs", "π"))
for i, result in enumerate(results[:10], 1): # Show first 10
status = "β" if result.get('status') == 'success' else "β"
url = result.get('url', 'Unknown')
safe_url = VisualEnhancer.escape_markdown(url[:50])
lines.append(f"{i}. {status} {safe_url}...")
if len(results) > 10:
lines.append(f"\n... and {len(results) - 10} more")
lines.append("")
lines.append("β" * 30)
return '\n'.join(lines)
except Exception as e:
logger.error(f"Format batch error: {e}")
return f"β
Batch scan completed: {len(results)} URLs"
@staticmethod
def format_deep_scan_result(result: dict) -> str:
"""Format deep scan results"""
try:
lines = []
lines.append(VisualEnhancer.format_header("Deep Scan Complete", "π¬"))
lines.append("")
if 'base_url' in result:
lines.append(f"π Base URL: {result['base_url']}")
if 'pages_scanned' in result:
lines.append(f"π Pages Scanned: {result['pages_scanned']}")
if 'max_depth_reached' in result:
lines.append(f"π Max Depth: {result['max_depth_reached']}")
lines.append("")
# Visited URLs
if 'visited_urls' in result:
lines.append(VisualEnhancer.format_section("Visited Pages", "π"))
for i, url in enumerate(result['visited_urls'][:8], 1):
safe_url = VisualEnhancer.escape_markdown(url[:60])
lines.append(f"{i}. {safe_url}...")
if len(result['visited_urls']) > 8:
lines.append(f"\n... and {len(result['visited_urls']) - 8} more")
lines.append("")
lines.append("β" * 30)
return '\n'.join(lines)
except Exception as e:
logger.error(f"Format deep scan error: {e}")
return "β
Deep scan completed"
@staticmethod
def format_queue_status(position: int, total: int, estimated_time: int) -> str:
"""Format queue status message"""
try:
lines = []
lines.append(VisualEnhancer.format_header("Added to Queue", "β³"))
lines.append("")
lines.append(f"π Your Position: #{position}")
lines.append(f"π₯ Queue Size: {total}")
lines.append(f"β±οΈ Estimated Wait: ~{estimated_time}s")
lines.append("")
# Progress visualization
if total > 0:
progress = VisualEnhancer.create_progress_bar(total - position, total)
lines.append(f"Queue: {progress}")
lines.append("")
lines.append("π‘ You'll be notified when your scan starts!")
lines.append("β" * 30)
return '\n'.join(lines)
except Exception as e:
logger.error(f"Format queue error: {e}")
return f"β³ Added to queue (position: {position})"
@staticmethod
def _get_summary_emoji(key: str) -> str:
"""Get appropriate emoji for summary key"""
key_lower = key.lower()
if 'time' in key_lower or 'duration' in key_lower:
return 'β±οΈ'
elif 'success' in key_lower:
return 'β
'
elif 'fail' in key_lower or 'error' in key_lower:
return 'β'
elif 'security' in key_lower:
return 'π‘οΈ'
elif 'speed' in key_lower or 'performance' in key_lower:
return 'β‘'
elif 'size' in key_lower:
return 'π¦'
elif 'redirect' in key_lower:
return 'βͺοΈ'
elif 'status' in key_lower:
return 'π'
else:
return 'βͺοΈ'
@staticmethod
async def animate_scanning(message: Message, url: str):
"""Animate scanning process"""
animations = [
f"π Scanning {url}\nβ±β±β±β±β±β±β±β±β±β± 0%",
f"π Scanning {url}\nβ°β°β±β±β±β±β±β±β±β± 20%",
f"π Scanning {url}\nβ°β°β°β°β±β±β±β±β±β± 40%",
f"π Scanning {url}\nβ°β°β°β°β°β°β±β±β±β± 60%",
f"π Scanning {url}\nβ°β°β°β°β°β°β°β°β±β± 80%",
f"π Scanning {url}\nβ°β°β°β°β°β°β°β°β°β° 100%",
]
for anim in animations:
try:
await message.edit_text(anim)
await asyncio.sleep(0.3)
except Exception:
break