Created
December 19, 2023 12:53
-
-
Save TannicArcher/3e36356709bc23645e253f525cadf757 to your computer and use it in GitHub Desktop.
Check files sites with VirusTotal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telegram import Update | |
from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandler, Filters | |
from vtapi import VirusTotalAPI | |
import logging | |
import locale | |
from pathlib import Path | |
from gettext import translation, NullTranslations | |
# Замените 'YOUR_VT_API_KEY' на ваш ключ API от VirusTotal | |
VT_API_KEY = 'YOUR_VT_API_KEY' | |
LOCALE_DIR = Path("locales") # Папка с файлами локализации | |
# Инициализация механизма локализации | |
locale.setlocale(locale.LC_ALL, 'en_US.utf8') | |
translations = translation("messages", LOCALE_DIR, languages=["en_US"]) | |
translations.install() | |
# Инициализация логгирования | |
logging.basicConfig(level=logging.INFO) | |
def start(update: Update, context: CallbackContext) -> None: | |
update.message.reply_text( | |
_("Welcome to VirusTotal Bot! This bot helps you check files and URLs for threats.\n" | |
"Use /scan to scan a file or URL.") | |
) | |
def scan(update: Update, context: CallbackContext) -> None: | |
user_message = update.message.text | |
command, *args = user_message.split(" ", 1) | |
if len(args) == 0: | |
update.message.reply_text(_("Please provide a file or URL to scan.")) | |
return | |
target = args[0] | |
vt = VirusTotalAPI(VT_API_KEY) | |
try: | |
result = vt.scan(target) | |
if result["response_code"] == 1: | |
positives = result["positives"] | |
total = result["total"] | |
permalink = result["permalink"] | |
scan_date = result["scan_date"] | |
message = ( | |
_("Scan results for {target}:\n" | |
"🛡️ Positives: {positives}/{total}\n" | |
"📅 Scan date: {scan_date}\n" | |
"🔗 Permalink: {permalink}") | |
.format(target=target, positives=positives, total=total, scan_date=scan_date, permalink=permalink) | |
) | |
update.message.reply_text(message) | |
else: | |
update.message.reply_text(_("Scan failed. Please try again.")) | |
except Exception as e: | |
logging.exception("An error occurred during scanning.") | |
update.message.reply_text(_("An error occurred during scanning. Please try again later.")) | |
def main() -> None: | |
updater = Updater("YOUR_TELEGRAM_BOT_TOKEN") | |
# Добавляем обработчик для текстовых сообщений | |
dp = updater.dispatcher | |
dp.add_handler(CommandHandler("start", start)) | |
dp.add_handler(CommandHandler("scan", scan)) | |
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, start)) | |
updater.start_polling() | |
updater.idle() | |
if __name__ == '__main__': | |
main() | |
*/READTHIS | |
You need to create a locales folder and add localization files there. Each language will be represented by its own file (for example, en_US.po). | |
This example assumes that you have localization files in po format and use the gettext library to process them.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment