-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,371 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.9 | ||
FROM python:3.13 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
version: "3.8" | ||
services: | ||
|
||
bot: | ||
build: . | ||
env_file: .env | ||
restart: unless-stopped | ||
|
||
redis: | ||
image: valkey/valkey:8-alpine | ||
restart: unless-stopped | ||
healthcheck: | ||
test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ] | ||
start_period: 20s | ||
interval: 30s | ||
retries: 5 | ||
timeout: 3s | ||
volumes: | ||
- ./volumes/redis:/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[project] | ||
name = "Radia" | ||
version = "0.1.0" | ||
description = "Default template for PDM package" | ||
authors = [ | ||
{name = "Vincent Lee", email = "[email protected]"}, | ||
] | ||
dependencies = [ | ||
"discord-py", | ||
"asyncio", | ||
"sentry-sdk", | ||
"aiohttp", | ||
"aiographql-client", | ||
"motor", | ||
"dnspython", | ||
"pymongo", | ||
"gspread", | ||
"pandas", | ||
"ics", | ||
"pyyaml", | ||
"sendou-py>=1.2.12", | ||
"audioop-lts>=0.2.1", | ||
"aiohttp-client-cache>=0.12.4", | ||
"redis>=5.2.1", | ||
] | ||
requires-python = "==3.13.*" | ||
readme = "README.md" | ||
license = {text = "MIT"} | ||
|
||
|
||
[tool.pdm] | ||
distribution = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Initializes the Sendou connector.""" | ||
|
||
import logging | ||
import sendou | ||
from aiohttp_client_cache.backends import RedisBackend | ||
from os import environ | ||
|
||
from .objects import Tournament | ||
|
||
class Connector: | ||
def __init__(self): | ||
self.__api_key = environ.get("SENDOU_API_KEY") | ||
if not self.__api_key: | ||
logging.error("No Sendou API Key found.") | ||
raise ValueError("No Sendou API Key found.") | ||
if redis_uri := environ.get("REDIS_URI"): | ||
self.__redis_uri = redis_uri | ||
else: | ||
self.__redis_uri = "redis://redis:6379/" | ||
self.client = sendou.Client(self.__api_key) | ||
self.client.cache = RedisBackend(cache_name="sendou", redis_uri=self.__redis_uri, expire_after=300) | ||
logging.debug("Loaded sendou.connector") | ||
|
||
async def get_tournament(self, tournament_id: str): | ||
""" Get tournament object from sendou api. | ||
:param tournament_id: The sendou tournament ID | ||
:rtype: Tournament | ||
""" | ||
tournament_data = await self.client.get_tournament(tournament_id) | ||
teams = await tournament_data.get_teams() | ||
return Tournament(tournament_data, teams) | ||
|
||
async def get_teams(self, tournament_id: str): | ||
""" Helper function that simply returns the ".teams" attribute of a tournament. | ||
:return: List[Team] | ||
""" | ||
tourney = await self.get_tournament(tournament_id) | ||
return tourney.teams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .player import Player | ||
from .team import Team | ||
from .tournament import Tournament |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Battlefy player object.""" | ||
from typing import Optional | ||
|
||
import dateutil.parser | ||
from discord.ext import commands | ||
from sendou import TeamMember | ||
|
||
|
||
class Player: | ||
""" Function and utilities for managing players from the battlefy api. | ||
:param dict sendou: The sendou player data | ||
""" | ||
|
||
def __init__(self, sendou: Optional[TeamMember]): | ||
self.raw: Optional[TeamMember] = sendou | ||
self.member_converter = commands.MemberConverter() | ||
if self.raw: | ||
self.created_at = sendou.joined_at | ||
else: | ||
self.created_at = None | ||
@property | ||
def discord(self): | ||
return self.raw.discord_id | ||
|
||
async def get_discord(self, ctx): | ||
""" Return the discord member object using the discord field provided. | ||
:return Optional[discord.Member]: | ||
Returns None if the member isn't found in the server. | ||
""" | ||
if not self.raw.discord_id: | ||
return None | ||
try: | ||
return await self.member_converter.convert(ctx, self.raw.discord_id) | ||
except commands.BadArgument: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Sendou team object.""" | ||
from sendou import TournamentTeam | ||
from typing import List | ||
|
||
from .player import Player | ||
|
||
class Team: | ||
def __init__(self, sendou: TournamentTeam): | ||
self.raw: TournamentTeam = sendou | ||
self.id = sendou.id | ||
self.name = sendou.name | ||
self.logo = sendou.logo_url | ||
self.players: List[Player] = [Player(p) for p in sendou.members] | ||
|
||
@property | ||
def captain(self): | ||
return next(p for p in self.players if p.raw.captain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import sendou | ||
from typing import List | ||
|
||
from .team import Team | ||
|
||
|
||
class Tournament: | ||
"""Sendou tournament object.""" | ||
|
||
def __init__(self, sendou_data: sendou.Tournament, teams: List[sendou.TournamentTeam]): | ||
self.raw: sendou.Tournament = sendou_data | ||
self.id = sendou_data.id | ||
self.name = sendou_data.name | ||
self.registered_count = sendou_data.teams.registered_count | ||
self.teams: List[Team] = [Team(t) for t in teams] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.