Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algalon Yttrium #14

Merged
merged 36 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e1776a9
Hopefully fix broken forceupdate command
Ghostopheles Apr 2, 2024
be51250
Make ribbit commands fast as heck boy
Ghostopheles Apr 2, 2024
d156a78
Remove 'cdn' prefix from all commands
Ghostopheles Apr 2, 2024
06e5664
Make config objects singleton
Ghostopheles Apr 2, 2024
6cc689f
User DM alerts
Ghostopheles Apr 2, 2024
b63cdd4
Delimited user watchlist input
Ghostopheles Apr 3, 2024
59d3006
More user DM work
Ghostopheles Apr 4, 2024
5bdb1e6
Add live config file, DM update fixups
Ghostopheles May 1, 2024
11decc4
Update CHANGELOG.md
Ghostopheles May 1, 2024
0c00531
Update README.md
Ghostopheles May 1, 2024
b4b73e5
Add `catalogs` support
Ghostopheles May 1, 2024
72a88bd
Update README and CHANGELOG
Ghostopheles May 1, 2024
0a03c41
Add watchdog/healthcheck thing
Ghostopheles May 4, 2024
cd64ff9
sneaky getlocale
Ghostopheles May 4, 2024
1ae0abe
Convert owner ID to int
Ghostopheles May 4, 2024
ae50bed
Better config organization
Ghostopheles May 4, 2024
5935fee
Update timestamp func
Ghostopheles May 4, 2024
a82f982
Move to `discord.SlashCommand`s
Ghostopheles May 4, 2024
bfd769c
Update command names
Ghostopheles May 4, 2024
fc7fa03
hahahaha
Ghostopheles May 4, 2024
664058a
le funni
Ghostopheles May 4, 2024
43998e6
Fix command links
Ghostopheles May 4, 2024
53bfb0c
Cleanup
Ghostopheles May 4, 2024
30c8486
madge
Ghostopheles May 4, 2024
dd61349
this is not how this works
Ghostopheles May 4, 2024
2f74b96
don't look
Ghostopheles May 4, 2024
8841bef
I'm over it
Ghostopheles May 4, 2024
7f7af47
Actually start the loop
Ghostopheles May 4, 2024
d6a8ca2
Fix broken CDN urls
Ghostopheles May 5, 2024
6885c1c
Fix game enum handling
Ghostopheles May 6, 2024
7a5f1af
diddly darn no good dumb type conversion nonsense stupidity
Ghostopheles May 6, 2024
14f4abf
Fix busted DM owner check
Ghostopheles May 6, 2024
1791647
Change cog load order
Ghostopheles May 6, 2024
eb688fb
smarter owner-only flag
Ghostopheles May 6, 2024
295e3c3
Move watchdog function
Ghostopheles May 11, 2024
9e51493
Remove unnecessary nano
Ghostopheles May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Changelog v1.9 - Yttrium

## Added

- Algalon is now able to DM users when a build update appears. These DMs are purposefully slimmed down to allow them to be readable on mobile push notifications.
- Added a live config file that can be used to update certain configuration values without needing to rebuild and redeploy the bot. Namely, product names can now be updated live.
- Added support for Battlenet `catalogs`.

## Removed

- The `cdn` prefix on all of the slash commands has been deleted.

## Fixed

- Update checking is now significantly faster.
- Global config objects are now handled more efficiently.

# Changelog v1.8 - Niobium

## Added
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ WORKDIR /usr/algalon

COPY requirements.txt requirements.txt
RUN python3 -m pip install -U -r requirements.txt
RUN apt-get update && apt-get install -y nano

COPY . .

Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# better-algalon
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![LastUpdate](https://img.shields.io/github/last-commit/Ghostamoose/better-algalon?style=flat-square) [![Docker](https://github.com/Ghostamoose/better-algalon/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/Ghostamoose/better-algalon/actions/workflows/docker-publish.yml)

v1.8 - Niobium
v1.9 - Yttrium

A bot that watches Blizzard's CDN and automatically posts new build updates to specified Discord channels.

Expand All @@ -20,8 +20,8 @@ A lock indicates that the given branch is encrypted and not accessible to the pu
| wowt | Retail PTR |
| wowxptr | Retail PTR 2 |
| wow_beta | Beta |
| wow_classic | WotLK Classic |
| wow_classic_ptr | WotLK Classic PTR |
| wow_classic | Cata Classic |
| wow_classic_ptr | Cata Classic PTR |
| wow_classic_beta | Classic Beta |
| wow_classic_era | Classic Era |
| wow_classic_era_beta | Classic Era Beta |
Expand Down Expand Up @@ -61,6 +61,11 @@ A lock indicates that the given branch is encrypted and not accessible to the pu
| gryphonb | Warcraft Rumble Beta |
| gryphondev :lock: | Warcraft Rumble Internal |

### Battle.net
| Branch Name | Readable Name |
| ----------- | ----------- |
| catalogs | Catalogs |

## Commands

Algalon provides a number of commands to control your guild's (server) watchlist.
Expand All @@ -71,21 +76,29 @@ Algalon provides a number of commands to control your guild's (server) watchlist

`/cdndata`: Returns a paginator containing the currently cached CDN data.

`/cdnlastupdate`: Returns a timestamp displaying when Algalon last checked for CDN updates.
`/lastupdate`: Returns a timestamp displaying when Algalon last checked for CDN updates.

`/cdnbranches`: Returns a formatted list of all observable branches.
`/branches`: Returns a formatted list of all observable branches.

#### Watchlist Controls

`/cdnaddtowatchlist`*: Adds a specific branch to your guild's watchlist. Specify multiple branches at once by separating them with a comma.
`/addtowatchlist`*: Adds a specific branch to your guild's watchlist. Specify multiple branches at once by separating them with a comma.

`/cdnremovefromwatchlist`*: Removes a specific branch to your guild's watchlist.
`/removefromwatchlist`*: Removes a specific branch to your guild's watchlist.

`/cdnwatchlist`: Returns your guild's current watchlist.
`/watchlist`: Returns your guild's current watchlist.

#### Notification Channel Controls

`/cdnsetchannel`*: Sets the channel in which it's invoked as the notification channel for your guild. Optionally, specify a game to set the notification channel for that game. Defaults to Warcraft.
`/setchannel`*: Sets the channel in which it's invoked as the notification channel for your guild. Optionally, specify a game to set the notification channel for that game. Defaults to Warcraft.

`/getchannel`: Returns the current notification channel for your guild. Optionally, specify a game to get the notification channel for that game. Defaults to Warcraft.

#### User DM Updates

`/subscribe`: Subscribes the user to DM updates for the given branches. Supports comma-delimited input.

`/unsubscribe`: Unsubscribes the user from DM updates for the given branches. Supports comma-delimited input.

`/cdngetchannel`: Returns the current notification channel for your guild. Optionally, specify a game to get the notification channel for that game. Defaults to Warcraft.
`/subscribed`: Returns all the branches you're currently subscribed to.

4 changes: 2 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
except ImportError:
pass

OWNER_ID = os.getenv("OWNER_ID")
OWNER_ID = int(os.getenv("OWNER_ID"))

DIR = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -113,7 +113,7 @@ async def send_cog_help(self, cog):
class CDNBot(bridge.Bot):
"""This is the almighty CDN bot, also known as Algalon. Inherits from `discord.ext.bridge.Bot`."""

COGS_LIST = ["admin", "watcher", "nux"]
COGS_LIST = ["watcher", "nux", "admin"]

def __init__(self, command_prefix, help_command=None, **options):
command_prefix = command_prefix or "!"
Expand Down
49 changes: 43 additions & 6 deletions cogs/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import os
import logging
import discord

from discord.ext import bridge, commands
from time import time
from discord.ext import bridge, commands, tasks

from .config import LiveConfig

logger = logging.getLogger("discord.admin")

DEBUG_GUILDS = [318246001309646849]
DEBUG_GUILDS = [
242364846362853377,
1101764045964578896,
318246001309646849,
1144396478840844439,
]

HOME_GUILD = 318246001309646849


class AdminCog(commands.Cog):
def __init__(self, bot: bridge.Bot):
self.bot = bot

@commands.is_owner()
@bridge.bridge_command(name="reload", guild_ids=DEBUG_GUILDS)
@bridge.bridge_command(name="reload", guild_ids=[HOME_GUILD], guild_only=True)
async def reload_cog(self, ctx: bridge.BridgeApplicationContext, cog_name: str):
"""Reloads a currently loaded cog."""

Expand Down Expand Up @@ -42,7 +53,7 @@ async def reload_cog(self, ctx: bridge.BridgeApplicationContext, cog_name: str):
)

@commands.is_owner()
@bridge.bridge_command(name="guilds", guild_ids=DEBUG_GUILDS, guild_only=True)
@bridge.bridge_command(name="guilds", guild_ids=[HOME_GUILD], guild_only=True)
async def get_all_guilds(self, ctx: bridge.BridgeApplicationContext):
"""Dumps details for all guilds Algalon is a part of."""
message = "```\n"
Expand All @@ -63,12 +74,38 @@ async def get_all_guilds(self, ctx: bridge.BridgeApplicationContext):
)

@commands.is_owner()
@bridge.bridge_command(name="forceupdate", guild_ids=DEBUG_GUILDS, guild_only=True)
@bridge.bridge_command(name="forceupdate", guild_ids=[HOME_GUILD], guild_only=True)
async def force_update_check(self, ctx: bridge.BridgeApplicationContext):
"""Forces a CDN check."""
watcher = self.bot.get_cog("CDNCog")
await ctx.defer()
await watcher.cdn_auto_refresh()
await ctx.respond("Update in progress...")
await ctx.respond("Updates complete.")

@bridge.bridge_command(
name="alien",
guild_ids=DEBUG_GUILDS,
)
async def alien(self, ctx: bridge.BridgeApplicationContext):
"""secre"""
await ctx.respond("behind you")

@commands.is_owner()
@commands.message_command(
name="Perceive",
guild_ids=DEBUG_GUILDS,
)
async def Perceive(
self, ctx: bridge.BridgeApplicationContext, message: discord.Message
):
diffs = 1141816184405229608
fatcathuh = 1140450046748397691
emoji = self.bot.get_emoji(fatcathuh)
if emoji is None:
emoji = self.bot.get_emoji(diffs)

await message.add_reaction(emoji)
await ctx.respond("gottem", ephemeral=True, delete_after=5)


def setup(bot):
Expand Down
2 changes: 1 addition & 1 deletion cogs/api/blizzard_tact.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def is_encrypted(self, branch: str, product_config_hash: str):
try:
response = await client.get(url)
except httpx.ConnectTimeout as exc:
self.logger.error("TACT CDN info request timed out.")
self.logger.error(f"TACT CDN info request for {branch} timed out.")
return None

if response.status_code != 200:
Expand Down
14 changes: 8 additions & 6 deletions cogs/cdn_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import sys
import time
import json
import httpx
import shutil
import logging
import asyncio

from .api.blizzard_tact import BlizzardTACTExplorer
from .config import CacheConfig, FETCH_INTERVAL
from .config import LiveConfig, CacheConfig
from .ribbit_async import RibbitClient

logger = logging.getLogger("discord.cdn.cache")
Expand All @@ -18,12 +17,15 @@ class CDNCache:
SELF_PATH = os.path.dirname(os.path.realpath(__file__))
PLATFORM = sys.platform
CONFIG = CacheConfig()
LIVE_CONFIG = LiveConfig()
TACT = BlizzardTACTExplorer()

def __init__(self):
self.cache_path = os.path.join(self.SELF_PATH, self.CONFIG.CACHE_FOLDER_NAME)
self.cdn_path = os.path.join(self.cache_path, self.CONFIG.CACHE_FILE_NAME)

self.fetch_interval = self.LIVE_CONFIG.get_fetch_interval()

if not os.path.exists(self.cache_path):
os.mkdir(self.cache_path)
self.init_cdn()
Expand Down Expand Up @@ -74,7 +76,7 @@ def compare_builds(self, branch: str, newBuild: dict) -> bool:

if file_json[self.CONFIG.indices.LAST_UPDATED_BY] != self.PLATFORM and (
time.time() - file_json[self.CONFIG.indices.LAST_UPDATED_AT]
) < (FETCH_INTERVAL * 60):
) < (self.fetch_interval * 60):
logger.info("Skipping build comparison, data is outdated")
return False

Expand All @@ -100,8 +102,6 @@ def compare_builds(self, branch: str, newBuild: dict) -> bool:
if file_json["buildInfo"][branch][area] != newBuild[area]:
logger.debug(f"Updated info found for {branch} @ {area}")
return True
else:
return False
else:
file_json["buildInfo"][branch][area] = newBuild[area]
return True
Expand Down Expand Up @@ -180,7 +180,9 @@ async def fetch_branch_ribbit(self, branch: str):
logger.error(f"No response for {branch}.")
return

_data = _data["us"]
region = "PUB-29" if branch == "catalogs" else "us"

_data = _data[region]
data = _data.__dict__()

logger.info(f"Comparing build data for {branch}")
Expand Down
Loading
Loading