import asyncio
import sys # dis maeks it work onm micropenis w3indbows
from bleak import BleakScanner, BleakError
from datetime import datetime
import requests
from rich import print
import os

# im ngl like half of this was vibe coded i hate python i hate python i hate python i hate python

# you really do need to fille these out lmao
webhook_url = "https://discord.com/api/webhooks/1403525015818862602/frakefakefake"  # replace with your actual webhook URL
discord_tag_role = "<@&1369280290203373670>"  # replace with your actual Discord role ID (.\@rolename to get it)
webhook_username = "[DЯΣΛMMΛKΣЯ]"  # the name that will appear on the webhook message

# rice header :3
header = """


[magenta] ____  ______   _______  _______  _______  _______  _______  _______  _        _______  _______  ____
(  __)(  __  \\ (  ____ )(  ____ \\(  ___  )(       )(       )(  ___  )| \\    /\\(  ____ \\(  ____ )(__  )
| (   | (  \\  )| (    )|| (    \\/| (   ) || () () || () () || (   ) ||  \\  / /| (    \\/| (    )|   ) |
| |   | |   ) || (____)|| (__    | (___) || || || || || || || (___) ||  (_/ / | (__    | (____)|   | |
| |   | |   | ||     __)|  __)   |  ___  || |(_)| || |(_)| ||  ___  ||   _ (  |  __)   |     __)   | |
| |   | |   ) || (\\ (   | (      | (   ) || |   | || |   | || (   ) ||  ( \\ \\ | (      | (\\ (      | |
| (__ | (__/  )| ) \\ \\__| (____/\\| )   ( || )   ( || )   ( || )   ( ||  /  \\ \\| (____/\\| ) \\ \\__ __) |
(____)(______/ |/   \\__/(_______/|/     \\||/     \\||/     \\||/     \\||_/    \\/(_______/|/   \\__/(____)


[/magenta]https://github.com/[magenta]PrincessPi3[/magenta]


"""
# bunch of random prefixes for testing
## Flock: B4:1E:52
## Police: 00:25:DF, 00:58:28, 00:C0:D4, 84:70:03, C0:1C:6A
## VENDOR_PREFIXES = ['00:25:DF', '00:58:28', '00:C0:D4', '84:70:03', 'C0:1C:6A', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0B', '77', '99', '0A', '0B', '0C', '0D', '0E', '0F', 'AB', 'C0']
# live
VNDOR_PREFIXES = ['00:25:DF', '00:58:28', '00:C0:D4', '84:70:03','B4:1E:52']

async def main():
    os.system('cls' if os.name == 'nt' else 'clear') # clear the console
    print(header)
    
    # Check for Bluetooth availability on Windows
    if sys.platform == 'win32':
        try:
            # Test if Bluetooth adapter is available
            await BleakScanner.discover(timeout=1)
        except BleakError as e:
            print(f"[red]ERROR: {e}[/red]")
            print("[yellow]Windows Bluetooth Issue:[/yellow]")
            print("1. Enable Bluetooth in Settings > Devices > Bluetooth & devices")
            print("2. Ensure your computer has Bluetooth hardware")
            print("3. Update your Bluetooth drivers from Device Manager")
            print("4. Try running as Administrator")
            return
    
    print("Scanning for Police...")
    while True:
        try:
            devices = await BleakScanner.discover()
            # jfc i hate how pythopn be 
            filtered_devices = [device for device in devices if any(device.address.upper().startswith(prefix) for prefix in VENDOR_PREFIXES)]
            if filtered_devices:
                now = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] # includes miliseconds
                webhook_payload = {
                    "content": f"{discord_tag_role} VLAT HAS BEEN SPOTTED MAC: {filtered_devices[0].address} TIME: {now}",
                    "username": webhook_username
                }
                print(f"VLAT HAS BEEN SPOTTED MAC: {filtered_devices[0].address} TIME: {now}") # do not ask me to explain how vlat means cop idk there is no sober explination for it
                for i in range(10): # guess what fuckers you finna be spammed as shgit :snurp:
                    requests.post(webhook_url, json=webhook_payload)
                break
        except BleakError as e: # error handlking ig fuuuck
            print(f"[red]Error during scanning: {e}[/red]")
            await asyncio.sleep(10)  # wait before next scan

# hoooolly shit whjy does this tumor language do shjit like this smh my head
if __name__ == "__main__":    asyncio.run(main())