This repository has been archived on 2025-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
Novel/main.py

83 lines
2.5 KiB
Python
Raw Normal View History

2025-03-23 19:03:28 +01:00
#region Imports
import time, os, tomllib
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from utils.logger import Log
from utils.scanner import scan
from utils.discord import webhook
from utils.ai import ai_analyse
# ai_analyse("./test.py")
#endregion
def s(input_dict):
return [
{"name": key, "value": '\n'.join(' - ' + str(item) for item in items)}
for key, items in input_dict.items()
]
def c(d):
c=0
for key in d:
if isinstance(d[key], list):
c += len(d[key])
return c
#region Initialize
t = time.time()
with open("config.toml", "rb") as f:
data = tomllib.load(f)
path = data['DETECTION']['watchdogPath']
Log.v("""
____ ____
/ __ \\____ _/ __ \\____ ______
/ /_/ / __ `/ / / / __ `/ ___/
/ _, _/ /_/ / /_/ / /_/ / /
/_/ |_|\\__,_/_____/\\__,_/_/ (ver. {})
""".format(data['ver']))
#endregion
class MyHandler(FileSystemEventHandler):
def on_created(self, event):
if event.is_directory:
return None
else:
Log.v(f"file created: {event.src_path}")
r = scan(event.src_path)
if r[0]:
Log.s(f"Flagged {event.src_path}")
analyse = ai_analyse(event.src_path)
webhook(event.src_path, s(r[0]), f"Total Flagged Pattern: {str(c(r[0]))}\n\n{analyse}")
def on_moved(self, event):
Log.v(f"file moved : {event.src_path}")
r = scan(event.src_path)
if r[0]:
Log.s(f"Flagged {event.src_path}")
analyse = ai_analyse(event.src_path)
webhook(event.src_path, s(r[0]), f"Total Flagged Pattern: {str(c(r[0]))}\n\n{analyse}")
def on_deleted(self, event):
Log.v(f"file deleted {event.src_path}")
def on_modified(self, event):
if(event.src_path == "."):
return
Log.v(f"file modified : {event.src_path}")
r = scan(event.src_path)
if r[0]:
Log.s(f"Flagged {event.src_path}")
analyse = ai_analyse(event.src_path)
webhook(event.src_path, s(r[0]), f"Total Flagged Pattern: {str(c(r[0]))}\n\n{analyse}")
if __name__ == "__main__":
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=False)
observer.start()
Log.s(data['LANGUGAE']['english']['radarStarted'].format(str(round(time.time() - t, 5))))
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()