import subprocess
import sys
import os
import time
import smtplib
from email.message import EmailMessage

# Auto-install pyttsx3 if not present
try:
    import pyttsx3
except ImportError:
    print("Installing required packages...")
    subprocess.run([sys.executable, "-m", "pip", "install", "pyttsx3"], capture_output=True)
    import pyttsx3

import webbrowser

engine = pyttsx3.init()

print(" ")
print("For best experience, make sure your volume is up all the way (or at least on)")
firstInput = input("Enter the Code please :D ")
print("nah that code actually did nothing")
time.sleep(3)
print("PS C:\\Users\\TrumanM.2028\\OneDrive - Meridian Technical Charter High School\\Desktop\\PTE Stuff\\Perry.py> ")
time.sleep(10)
print("HA! Got you! You thought it was over! April fools! (but on April 7)")
time.sleep(3)
while True:
    waitWhat = input("wait, what was that code you entered earlier? ")
    if waitWhat == firstInput:
        print("Hey! you remembered! good job :D")
        break
    else:
        print("brotha that aint what you said!")

print("that deserves to get you emailed... TRUMANITO")
time.sleep(1)
print("that's right Trumanito... I know who you are... I knew the WHOLE TIME...")
time.sleep(1)
print("btw gullible is on the ceiling")
time.sleep(1)
print("but that's off topic")
time.sleep(1)

GMAIL_USER = "AndersonS.2028@mtchs.org"
GMAIL_APP_PASSWORD = "pnml rqfj ghaf cbne"
subject = "TRUMANITO... YOUR COMPUTER IS CURRENTLY BEING HACKED"
emailAddress = "trumanM.2028@MTCHS.org"
message = ("Truman... I, the great and super cool man known as [insert really cool villain name here] "
           "have started hacking your computer... >:D The only way for you to stop me, is for you to "
           "find and assemble, the 5 [insert cool name of codes here] codes. Good luck, I hope you LOSE >:D")

try:
    msg = EmailMessage()
    msg["Subject"] = subject
    msg["From"] = GMAIL_USER
    msg["To"] = emailAddress
    msg.set_content(message)
    with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
        smtp.login(GMAIL_USER, GMAIL_APP_PASSWORD)
        smtp.send_message(msg)
except Exception as e:
    pass  # silently continue if email fails

time.sleep(1)

# First code... Google Baseball
print("Virus Detected")
engine.say("Virus Detected")
engine.runAndWait()

webbrowser.open("https://www.google.com/search?q=baseball+google")
time.sleep(5)
engine.say("get the highest score possible, then return to the Python script and input your high score")
engine.runAndWait()

while True:
    try:
        highScore = int(input("What was your highest score? "))
        if highScore < 15:
            print("rookie numbers... try again")
        elif 15 <= highScore < 100:
            print("I guess that's acceptable...")
            print("the first code is: Trumanito")
            break
        else:
            print("ok bro... holy overachiever here")
            print("the first code is: Trumanito")
            break
    except ValueError:
        print("bro put in a NUMBER...")

# Second test
print("I have a good test for you... DON'T COME BACK UNTIL YOU GOT 100%... Or ill come for u...")
time.sleep(1)
webbrowser.open("https://forms.gle/RiDmAczk2Yse5GvL8")
engine.say("Don't come back until you have gotten 100%!")
engine.runAndWait()

while True:
    oneHundred = input("did you get 100%? ")
    if oneHundred.strip().lower() in ("yes", "y"):
        print("good job ig... the second code is bombadillo")
        break
    else:
        print("u suck")

# Third test
print("the third test is HARD TRUST")
print("you gotta... win one game of MINECRAFT DISASTERS... on Hypixel :D")

# Try to launch Minecraft from common install locations
launcher_paths = [
    r"C:\Program Files (x86)\Minecraft Launcher\MinecraftLauncher.exe",
    r"C:\Program Files\Minecraft Launcher\MinecraftLauncher.exe",
    r"C:\XboxGames\Minecraft Launcher\Content\Minecraft.exe",
    os.path.expanduser(r"~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Minecraft Launcher.lnk"),
]

launched = False
for path in launcher_paths:
    if os.path.exists(path):
        subprocess.Popen([path])
        launched = True
        break

if not launched:
    subprocess.Popen("start minecraft", shell=True)

engine.say("Minecraft Disasters peak peak peak peak peak peak peak peak peak peak peak peak")
engine.runAndWait()

while True:
    minecraft = input("How'd you do? Did you win? ")
    if minecraft.strip().lower() in ("yes", "y"):
        print("Good job... the third code is, crocadillo")
        break
    else:
        print("bruh y'd you come back then... go beat the game i mean honestly...")

# Test four - cipher
print("...I have a really good fourth challenge")
time.sleep(1)
print("it's called")
time.sleep(1)
print("cipher :D:D:D:D")
time.sleep(1)
print("Udjuh jxu setu: Iywcq Reo, je sedjydku")
engine.say("P O V Ciphers")
engine.runAndWait()

while True:
    cipher = input("so uhh, what's the code, TRUMANITO? ")
    if cipher.strip() == "Sigma Boy":
        print("noice... the fourth code is, sigma")
        break
    else:
        print("u suck at ciphers TRUMANITO... I mean WHAAAAAAAAT? HAPPY EASTER!")

# Final test - patience
print("the final test...")
time.sleep(1)
print("the hardest test")
time.sleep(1)
print("A test of patience")
time.sleep(1)
print("There are many")
time.sleep(1)
print("time.sleeps")
time.sleep(1)
print("intermitten")
time.sleep(1)
print("with small bits of words")
time.sleep(1)
print("and you must")
time.sleep(1)
print("wait and read")
time.sleep(1)
print("each of them")
time.sleep(1)
print("seperately")
time.sleep(1)
print("L")
engine.say("the fifth code is... Zo")
engine.runAndWait()
time.sleep(3)
print("real L moment rn having to wait like this")
time.sleep(3)
print("Sounds like someone")
time.sleep(3)
print("is going to learn")
time.sleep(3)
print("to be patient")
time.sleep(3)
print("because we")
time.sleep(3)
print("still have")
time.sleep(3)
print("5")
time.sleep(3)
print("more")
time.sleep(3)
print("to")
time.sleep(3)
print("go")
time.sleep(3)

engine.say("input all of the codes")
engine.runAndWait()
print("Enter the Final Code:")

while True:
    finalCode = input("")
    if finalCode.strip() == "Trumanito Bombadillo Crocadillo Sigma Zo":
        print("CORRECT! I guess I won't hack your computer...")
        engine.say("virus neutralized")
        engine.runAndWait()
        break
    else:
        print("please try again...")
        engine.say("virus activating")
        engine.runAndWait()

print("oh well trumanito... I hope you had fun... :D")