Skip to content

Commit

Permalink
Use authorisation header, if provided, with St Jude scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrss committed Sep 23, 2023
1 parent 2f474c0 commit 5ca70a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions botto/clients/stjude_scoreboard.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import logging
from typing import Literal
from typing import Literal, Optional

import aiohttp

log = logging.getLogger(__name__)


class StJudeScoreboardClient:
def __init__(self):
def __init__(self, token: Optional[str]):
super().__init__()
self._url = "https://stjude-scoreboard.snailedit.org/api/co-founders"
self._token = token

async def update_score(self, co_founder: Literal["myke", "stephen"], score: int):
async with aiohttp.ClientSession() as session:
url = f"{self._url}/{co_founder}"
await session.put(url, json={"score": score}, raise_for_status=True)
headers = (
{"Authorization": f"Bearer {self._token}"}
if self._token is not None
else None
)
await session.put(
url, json={"score": score}, headers=headers, raise_for_status=True
)
3 changes: 3 additions & 0 deletions botto/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def parse(config):
if clickup_enabled_guilds := decode_base64_env("TLDBOTTO_CLICKUP_ENABLED_GUILDS"):
defaults["clickup_enabled_guilds"] = clickup_enabled_guilds

if st_jude_scoreboard_key := decode_base64_env("ST_JUDE_SCOREBOARD_KEY"):
defaults["st_jude_scoreboard_key"] = st_jude_scoreboard_key

defaults["clickup_enabled_guilds"] = set(defaults["clickup_enabled_guilds"])

if id := os.getenv("TLDBOTTO_ID"):
Expand Down
4 changes: 3 additions & 1 deletion botto/slash_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def setup_slash(
):
client.tree.clear_commands(guild=None)
client.tree.clear_commands(guild=client.snailed_it_beta_guild)
st_jude_scoreboard_client = StJudeScoreboardClient()
st_jude_scoreboard_client = StJudeScoreboardClient(
token=config.get("st_jude_scoreboard_key")
)

@client.tree.command(
name="ping",
Expand Down

0 comments on commit 5ca70a2

Please sign in to comment.