Skip to content

Commit

Permalink
Merge pull request #13 from BFrizzleFoShizzle/main
Browse files Browse the repository at this point in the history
feat: add support for GOG, use cache for Steam, and fix for lack of "timeupdated" and multiple branch tracking bug for Steam
  • Loading branch information
kurokobo authored Apr 18, 2023
2 parents b89a568 + 253931f commit 73662a2
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 30 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Game Update Notifier

A bot that will let you know via Discord as soon as a new version of your favorite game on Steam, Epic Games, and Microsoft Store are released.
A bot that will let you know via Discord as soon as a new version of your favorite game on Steam, Epic Games, Microsoft Store, and GOG are released.

This bot tracks actual package updates, instead of updates of any news feeds like blog posts or release notes, so you can be the first to know the release of the new patches.

Expand All @@ -23,6 +23,7 @@ This bot tracks actual package updates, instead of updates of any news feeds lik
- [Steam](#steam)
- [Epic Games](#epic-games)
- [Microsoft Store](#microsoft-store)
- [GOG](#gog)
- [Prepare Environment Variables (`.env`)](#prepare-environment-variables-env)
- [Run the Bot](#run-the-bot)
- [Data Persistence](#data-persistence)
Expand All @@ -37,6 +38,7 @@ This bot tracks actual package updates, instead of updates of any news feeds lik
| ✅ Steam | ✅ Not required | ✅ Unrestricted |
| ✅ Microsoft Store | ✅ Not required | ✅ Unrestricted |
| ✅ Epic Games | ⚠️ Required | ⚠️ Only products that you own |
| ✅ GOG | ✅ Not required | ✅ Unrestricted |

### Notification Destination

Expand Down Expand Up @@ -141,6 +143,20 @@ KEY App Id Market Name
Keep the value of the `KEY` column (`<App Id>:<Platform>`) of the row of the platform you want to track. This value can be used to prepare `.env` file in later steps.
#### GOG
Both the **App ID** and **Branch** can be found by searching via product name using the helper script in this repository. The main release branch is usually `null`.
```bash
$ docker-compose run --rm notifier helper/app_finder.py -p gog -n Kenshi
KEY App Id Name Branch
--------------------------------------------------- ---------- ---------- ----------------------------------------
1193046833:"experimental - latest unstable version" 1193046833 Kenshi "experimental - latest unstable version"
1193046833:null 1193046833 Kenshi null
1409800471:null 1409800471 Mahokenshi null
```
Keep the value of the `KEY` column (`<App Id>:<Branch>`) of the row of the branch you want to track. This value can be used to prepare `.env` file in later steps.
### Prepare Environment Variables (`.env`)
Copy `sample.env` as `.env` and fill in the each lines to suit your requirements. Follow the instructions in the `.env` file.
Expand Down
29 changes: 29 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from modules.discord import Discord
from modules.epicgames import EpicGames
from modules.msstore import MSStore
from modules.gog import GOG

dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)
Expand Down Expand Up @@ -49,6 +50,13 @@ def main():
if not os.getenv("EPICGAMES_APP_IDS") == ""
]

WATCH_GOG = os.getenv("WATCH_GOG").lower() == "true"
GOG_APP_IDS = [
x.strip()
for x in os.getenv("GOG_APP_IDS").strip('"').strip("'").split(",")
if not os.getenv("GOG_APP_IDS") == ""
]

DISCORD_WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL")
DISCORD_MENTION_ROLE_IDS = [
x.strip()
Expand Down Expand Up @@ -110,6 +118,24 @@ def main():
EPICGAMES_APP_IDS, epicgames_notifier, IGNORE_FIRST_NOTIFICATION
)

if WATCH_GOG:
gog_notifier = Discord(
webhook_url=DISCORD_WEBHOOK_URL,
role_ids=DISCORD_MENTION_ROLE_IDS,
user_ids=DISCORD_MENTION_USER_IDS,
platform="GOG",
# TODO update this if necessary
thumb_url=(
#"https://github.com/kurokobo/game-update-notifier/raw/main/"
#"assets/gog.png"

"https://github.com/BFrizzleFoShizzle/game-update-notifier/raw/main/"
"assets/gog.png"
),
embed_color="c62ee8",
)
gog = GOG(GOG_APP_IDS, gog_notifier, IGNORE_FIRST_NOTIFICATION)

while True:
logger.info("Loop start: {}".format(datetime.now()))

Expand All @@ -122,6 +148,9 @@ def main():
if WATCH_EPICGAMES:
epicgames.check_update()

if WATCH_GOG:
gog.check_update()

logger.info("Will sleep {} seconds".format(CHECK_INTERVAL_SEC))
time.sleep(CHECK_INTERVAL_SEC)

Expand Down
Binary file added assets/gog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
- WATCH_EPICGAMES=${WATCH_EPICGAMES}
- EPICGAMES_APP_IDS=${EPICGAMES_APP_IDS}

- WATCH_GOG=${WATCH_GOG}
- GOG_APP_IDS=${GOG_APP_IDS}

- DISCORD_WEBHOOK_URL=${DISCORD_WEBHOOK_URL}
- DISCORD_MENTION_ROLE_IDS=${DISCORD_MENTION_ROLE_IDS}
- DISCORD_MENTION_USER_IDS=${DISCORD_MENTION_USER_IDS}
Expand Down
65 changes: 59 additions & 6 deletions helper/app_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def gather_steam(id):
_table = []
for _branch in _product_info["apps"][_id]["depots"]["branches"]:
_name = _product_info["apps"][_id]["common"]["name"]
_updated_time = _product_info["apps"][_id]["depots"]["branches"][_branch][
"timeupdated"
]
_updated_time = -1
if "timeupdated" in _product_info["apps"][_id]["depots"]["branches"][_branch]:
_updated_time = _product_info["apps"][_id]["depots"]["branches"][_branch]["timeupdated"]
_row = [
"{}:{}".format(_id, _branch),
_id,
Expand Down Expand Up @@ -93,17 +93,60 @@ def gather_epicgames():

print(tabulate(_table, _header))

def gather_gog_id(id):
# get name
_response = requests.get("https://api.gog.com/products/" + str(id))
_response.close()
_name = _response.json()["title"]

# get branch info
_response = requests.get("https://content-system.gog.com/products/"
+ str(id)
+ "/os/windows/builds?generation=2")
_response.close()
_product_info = _response.json()

_header = ["KEY", "App Id", "Name", "Branch"]
_table = []
_branches = []
for _product in _product_info["items"]:
_branch = _product["branch"]
_branch_str = ("null" if _branch is None else "\"" + _branch + "\"")
if not _product["branch"] in _branches:
_key = str(id) + ":" + _branch_str
_table.append([_key, id, _name, _branch_str])
_branches.append(_product["branch"])

return (_table, _header)

def gather_gog_name(name):
_endpoint = "https://embed.gog.com/games/ajax/filtered"
_params = {
"search": name
}
_response = requests.get(url=_endpoint, params=_params)
_response.close()
_search_matches = _response.json()

_table = []
_keys = []
for _product in _search_matches["products"]:
(_id_table, _keys) = gather_gog_id(_product["id"])
_table += _id_table
print(tabulate(_table, _keys))



def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--platform",
type=str,
choices=["steam", "epicgames", "msstore"],
choices=["steam", "epicgames", "msstore", "gog"],
help=(
"specify the name of the platform that you want to gather. "
"choices: steam, epicgames, msstore"
"choices: steam, epicgames, msstore, gog"
),
)
parser.add_argument(
Expand All @@ -117,7 +160,13 @@ def main():
"-i",
"--id",
type=str,
help="specify the id of the game. required for steam or msstore",
help="specify the id of the game. required for steam or msstore, optional for gog",
)
parser.add_argument(
"-n",
"--name",
type=str,
help="specify the searched name of the game. only used for gog",
)
args = parser.parse_args()

Expand All @@ -130,6 +179,10 @@ def main():
if args.platform == "epicgames":
gather_epicgames()

if args.platform == "gog" and args.id is not None:
print(tabulate(*gather_gog_id(args.id)))
elif args.platform == "gog" and args.name is not None:
gather_gog_name(args.name)

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions helper/list_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def main():
json_epicgames = "../cache/epicgames/latest_result.json"
json_msstore = "../cache/msstore/latest_result.json"
json_steam = "../cache/steam/latest_result.json"
json_gog = "../cache/gog/latest_result.json"

current_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(current_path)
Expand All @@ -41,6 +42,7 @@ def main():
_table = append_cache(_table, "Epic Games", json_epicgames)
_table = append_cache(_table, "Microsoft Store", json_msstore)
_table = append_cache(_table, "Steam", json_steam)
_table = append_cache(_table, "GOG", json_gog)

print(tabulate(_table, _header))

Expand Down
Loading

0 comments on commit 73662a2

Please sign in to comment.