From f0e389da7b9cfe21e416980bc1cbc383d8b87ca1 Mon Sep 17 00:00:00 2001 From: TheTechromancer Date: Wed, 8 Nov 2023 10:58:36 -0500 Subject: [PATCH] fixed filedownload file counter --- bbot/modules/filedownload.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bbot/modules/filedownload.py b/bbot/modules/filedownload.py index 8b61dbdd8..ad4128e90 100644 --- a/bbot/modules/filedownload.py +++ b/bbot/modules/filedownload.py @@ -84,7 +84,8 @@ async def setup(self): self.max_filesize = self.options.get("max_filesize", "10MB") self.download_dir = self.scan.home / "filedownload" self.helpers.mkdir(self.download_dir) - self.files_downloaded = set() + self.urls_downloaded = set() + self.files_downloaded = 0 self.mime_db_file = await self.helpers.wordlist( "https://raw.githubusercontent.com/jshttp/mime-db/master/db.json" ) @@ -100,8 +101,7 @@ async def filter_event(self, event): # accept file download requests from other modules if "filedownload" in event.tags: return True - h = self.hash_event(event) - if h in self.files_downloaded: + if self.hash_event(event) in self.urls_downloaded: return False, f"Already processed {event}" return True @@ -128,7 +128,8 @@ async def download_file(self, url, content_type=None): result = await self.helpers.download(url, warn=False, filename=file_destination, max_size=self.max_filesize) if result: self.info(f'Found "{orig_filename}" at "{base_url}", downloaded to {file_destination}') - self.files_downloaded.add(hash(url)) + self.files_downloaded += 1 + self.urls_downloaded.add(hash(url)) def make_filename(self, url, content_type=None): # first, try to determine original filename @@ -161,5 +162,5 @@ def make_filename(self, url, content_type=None): return orig_filename, self.download_dir / filename, base_url async def report(self): - if self.files_downloaded: - self.success(f"Downloaded {len(self.files_downloaded):,} file(s) to {self.download_dir}") + if self.files_downloaded > 0: + self.success(f"Downloaded {self.files_downloaded:,} file(s) to {self.download_dir}")