-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
207 lines (181 loc) Β· 7.74 KB
/
bot.py
File metadata and controls
207 lines (181 loc) Β· 7.74 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
import os
import time
import logging
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.constants import ParseMode
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes, MessageHandler, filters
import requests
import hashlib
from datetime import datetime
import pytz # Aggiunto per il timezone
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
logger = logging.getLogger(__name__)
TOKEN = "your-bot-token"
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
welcome_message = (
"π *Welcome to DrWeb 2.0!*\n\n"
"This is the new version of DrWeb using the DrWeb API.\n\n"
"You can use:\n"
"β’ Text interface (chat)\n\n"
"Use the About button for more information!\n"
"Use the Tutorial button to see how it works!"
)
keyboard = [
[InlineKeyboardButton("βΉοΈ About", callback_data="about")],
[InlineKeyboardButton("π Tutorial", callback_data="tutorial")]
]
await update.message.reply_text(
welcome_message,
parse_mode='Markdown',
reply_markup=InlineKeyboardMarkup(keyboard)
)
async def check_server_status() -> str:
try:
response = requests.get("http://217.154.2.118", timeout=5)
return "π’ ONLINE" if response.status_code == 200 else "π΄ OFFLINE"
except:
return "π΄ OFFLINE"
async def about_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
server_status = await check_server_status()
about_message = (
"π *Information DrWeb 2.0*\n\n"
f"π€ Owner: [macs](https://t.me/onniscienza)\n"
f"π¦ Version: 1.0.0\n"
f"π Server: {server_status}"
)
keyboard = [[InlineKeyboardButton("π Back", callback_data="back")]]
await query.edit_message_text(
about_message,
parse_mode='Markdown',
reply_markup=InlineKeyboardMarkup(keyboard)
)
async def tutorial_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
tutorial_message = (
"*DrWeb 2.0 Tutorial*\n\n"
"1. Send a URL or a file to the bot.\n"
"2. The bot will send the scan result.\n"
"3. Click the result link for more details.\n"
"4. You can also use the /start command to return to the main screen.\n"
"5. You can go back at any time by clicking the Back button."
)
keyboard = [[InlineKeyboardButton("π Back", callback_data="back")]]
await query.edit_message_text(
tutorial_message,
parse_mode='Markdown',
reply_markup=InlineKeyboardMarkup(keyboard)
)
async def back_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
await query.edit_message_text(
"π *Welcome to DrWeb 2.0!*\n\n"
"This is the new version of DrWeb using the DrWeb API.\n\n"
"You can use:\n"
"β’ Web interface (miniapp)\n"
"β’ Text interface (chat)\n\n"
"Use the About button for more information!\n"
"Use the Tutorial button to see how it works!",
parse_mode='Markdown',
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("βΉοΈ About", callback_data="about")],
[InlineKeyboardButton("π Tutorial", callback_data="tutorial")]
])
)
async def handle_file(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
file = update.message.document
if file.file_size > 20 * 1024 * 1024:
await update.message.reply_text("β The file is too large, maximum 20MB.")
return
start_time = time.time()
file_info = await context.bot.get_file(file.file_id)
file_bytes = await file_info.download_as_bytearray()
file_name = file.file_name
upload_dir = "/var/www/html/bot/drweb/test/uploads"
os.makedirs(upload_dir, exist_ok=True)
file_path = os.path.join(upload_dir, file_name)
with open(file_path, 'wb') as f:
f.write(file_bytes)
file_hash = hashlib.md5(file_bytes).hexdigest()[:8]
public_file_url = f"https://macsgames.cloud/bot/drweb/test/uploads/{file_name}"
rome_tz = pytz.timezone("Europe/Rome")
scan_time = datetime.now(rome_tz).strftime("%H:%M:%S") # Ora locale di Roma
scan_result = {
"status": "β
File Clean",
"version": "7.0.65.5230",
"size": f"{file.file_size / 1024:.2f} KB",
"md5": file_hash,
"scan_link": f"https://online.drweb.com/result/?lng=en&url={public_file_url}",
"scan_time": scan_time,
"scan_date": datetime.now().strftime("%Y/%m/%d"),
"timezone": "Europe/Rome"
}
scan_message = (
"β
Scan completed successfully.\n"
"ββββββββ\n"
f"βοΈ Scan Results:\n\n"
f"π‘ File Status: {scan_result['status']}\n"
f"βοΈ Antivirus Version: {scan_result['version']}\n"
f"π File Size: {scan_result['size']}\n"
f"#οΈβ£ MD5 Hash: {scan_result['md5']}\n"
f"π Result Link: [Click here]({scan_result['scan_link']})\n"
f"β° Scan Time: {scan_result['scan_time']}\n"
f"π
Scan Date: {scan_result['scan_date']}\n"
f"βοΈ Time Zone: {scan_result['timezone']}\n"
"ββββββββ\n"
"π£ @macsgames"
)
await update.message.reply_text(scan_message, parse_mode='Markdown')
async def handle_url(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
url = update.message.text
if not url.startswith(('http://', 'https://')):
await update.message.reply_text(
"β Wrong URL, please use this format: http://macsgames.cloud/bot/drweb/test/file.php or https://macsgames.cloud/bot/drweb/test/file.php"
)
return
start_time = time.time()
url_hash = hashlib.md5(url.encode()).hexdigest()[:8]
rome_tz = pytz.timezone("Europe/Rome")
scan_time = datetime.now(rome_tz).strftime("%H:%M:%S") # Ora locale di Roma
scan_result = {
"status": "β
URL Clean",
"version": "7.0.65.5230",
"size": "N/A",
"md5": url_hash,
"scan_link": f"https://online.drweb.com/result/?lng=en&url={url}",
"scan_time": scan_time,
"scan_date": datetime.now().strftime("%Y/%m/%d"),
"timezone": "Europe/Rome"
}
scan_message = (
"β
Scan completed successfully.\n"
"ββββββββ\n"
f"βοΈ Scan Results:\n\n"
f"π‘ URL Status: {scan_result['status']}\n"
f"βοΈ Antivirus Version: {scan_result['version']}\n"
f"π URL MD5 Hash: {scan_result['md5']}\n"
f"π Result Link: [Click here]({scan_result['scan_link']})\n"
f"β° Scan Time: {scan_result['scan_time']}\n"
f"π
Scan Date: {scan_result['scan_date']}\n"
f"βοΈ Time Zone: {scan_result['timezone']}\n"
"ββββββββ\n"
"π£ @drwebultra"
)
await update.message.reply_text(scan_message, parse_mode='Markdown')
def main() -> None:
application = Application.builder().token(TOKEN).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(CallbackQueryHandler(about_callback, pattern="about"))
application.add_handler(CallbackQueryHandler(tutorial_callback, pattern="tutorial"))
application.add_handler(CallbackQueryHandler(back_callback, pattern="back"))
application.add_handler(MessageHandler(filters.Document.ALL, handle_file))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_url))
application.run_polling()
if __name__ == '__main__':
main()