diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86098f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +.fleet/ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..064780e --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# QueueNotify (program) +## Description +Program that sends you a text when your Solo Shuffle pops in World of Warcraft. Developed for Windows 11 (but 10 should work). + +**Please note that this program is in Alpha, and so you can expect errors to occur and things to be more difficult to set up for now. I've decided to release it despite the somewhat primitive state, as I think it will be useful for a lot of people who are able to follow the instructions below.** + +Report any problems in the [Issues](https://github.com/test/queue-notify/issues) tab, but please try searching things yourself first. + +## Installation +1. Install the QueueNotify addon via [CurseForge](https://www.curseforge.com/) or [Wago](https://addons.wago.io/) and then `/reload` +2. Install [Python 3 for Windows](https://www.python.org/downloads/) and ensure it's in your PATH. Note that this program has been tested on Python version 3.10 +3. Download this repo (`git clone https://github.com/test/queue-notify`, or [download the ZIP](https://github.com/test/queue-notify/archive/refs/heads/main.zip) and then extract it somewhere) +4. Open Command Prompt and `cd` into where you saved it, e.g., `cd C:\Users\test\Documents\queue-notify` +5. Run `pip install -r requirements.txt` and wait until complete. + + +## Setup +1. Install the [Telegram app](https://telegram.org/apps) on your phone and sign up +2. Open a new message to the user `@BotFather` and type `/newbot`. You will then be prompted to fill in some values +3. Enter a name such as `QueueNotify` +4. Enter some unique username like `queuenotify_123456_bot` +5. Write down the HTTP API token you get, and enter it under `token` in the `config.toml` file +6. Ensure the `path` to your WoW folder in `config.toml` is correct. You must use double backslashes, e.g., `"C:\\Program Files (x86)\\World of Warcraft"` +7. Run the program (from inside the directory, as before) with `python main.py`. You will need to run this whenever you want to begin monitoring after a restart +8. When running for the first time, it will prompt you to send a message to your bot. Do this by clicking the `t.me/{username}` link given to you by the BotFather +9. Stop monitoring by closing the Command Prompt window. + + +## Updates +It is likely that this program will change significantly, and so you should check back here for updates. Please also keep the addon updated. + + +## Changing account +If you wish to change your linked Telegram account, simply change the `chat_id` value in `config.toml` to `""` and re-run the program. diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..97ef3b5 --- /dev/null +++ b/config.toml @@ -0,0 +1,3 @@ +token = "" +path = "C:\\Program Files (x86)\\World of Warcraft" +chat_id = "" diff --git a/main.py b/main.py new file mode 100644 index 0000000..6df9ea8 --- /dev/null +++ b/main.py @@ -0,0 +1,27 @@ +from message import get_chat_id +from monitor import monitor +import toml + + +def load_config(): + config_path = "config.toml" + with open(config_path) as file: + config = toml.load(file) + if config["chat_id"] == "": + chat_id = None + while not chat_id: + input("Please send a message to the Telegram bot you created. Once done, wait 1 minute then press Enter.") + chat_id = get_chat_id(config["token"]) + config["chat_id"] = chat_id + with open(config_path, "w") as file: + toml.dump(config, file) + return config + + +def main(): + config = load_config() + monitor(config["path"], config["token"], config["chat_id"]) + + +if __name__ == "__main__": + main() diff --git a/message.py b/message.py new file mode 100644 index 0000000..d3b39cb --- /dev/null +++ b/message.py @@ -0,0 +1,17 @@ +import requests + + +def get_chat_id(token): + url = f"https://api.telegram.org/bot{token}/getUpdates" + data = requests.get(url).json() + try: + chat_id = data["result"][0]["message"]["chat"]["id"] + except IndexError: + return None + return str(chat_id) + + +def send_message(token, chat_id): + message = "Your Solo Shuffle is ready." + url = f"https://api.telegram.org/bot{token}/sendMessage?chat_id={chat_id}&text={message}" + requests.get(url) diff --git a/monitor.py b/monitor.py new file mode 100644 index 0000000..7d9811f --- /dev/null +++ b/monitor.py @@ -0,0 +1,38 @@ +from watchdog.observers import Observer +from watchdog.events import PatternMatchingEventHandler +import time +from message import send_message +import os + + +class ScanFolder: + def __init__(self, path, token, chat_id): + self.path = path + "\\_retail_\\Screenshots" + self.token = token + self.chat_id = chat_id + self.event_handler = PatternMatchingEventHandler(patterns=["*.tga"], ignore_patterns=None, + ignore_directories=False, case_sensitive=True) + self.event_handler.on_created = self.on_created + self.observer = Observer() + self.observer.schedule(self.event_handler, self.path, recursive=False) + self.observer.start() + + def on_created(self, event): + send_message(self.token, self.chat_id) + print("Sending message...") + if os.path.exists(event.src_path): + os.remove(event.src_path) + + def stop(self): + self.observer.stop() + self.observer.join() + + +def monitor(path, token, chat_id): + observer = ScanFolder(path, token, chat_id) + print("Monitoring...") + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7ef008f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +requests +toml +watchdog \ No newline at end of file