-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Qwizi/ruff
Ruff
- Loading branch information
Showing
26 changed files
with
3,115 additions
and
1,236 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,15 @@ | ||
TOKEN= | ||
API_URL= | ||
API_TOKEN= | ||
TESTING=False | ||
TESTING=False | ||
REDIS_HOST=redis | ||
REDIS_PORT=6379 | ||
REDIS_DB=0 | ||
REDIS_PASSWORD= | ||
SENTRY_DSN= | ||
GUILD_ID= | ||
LOBBY_CHANNEL_ID= | ||
TEAM1_CHANNEL_ID= | ||
TEAM2_CHANNEL_ID= | ||
TEAM1_ROLE_ID= | ||
TEAM2_ROLE_ID= |
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,7 +1,8 @@ | ||
name: Publish Backend Docker image | ||
|
||
on: | ||
workflow_dispatch: | ||
release: | ||
types: [published] | ||
|
||
|
||
jobs: | ||
|
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,21 @@ | ||
repos: | ||
- repo: "https://github.com/astral-sh/ruff-pre-commit" | ||
rev: "v0.1.5" | ||
hooks: | ||
- id: "ruff" | ||
name: "Run the Ruff linter" | ||
types_or: ["python", "pyi"] | ||
args: ["--fix"] | ||
- id: "ruff-format" | ||
name: "Run the Ruff formatter" | ||
types_or: ["python", "pyi"] | ||
- repo: "https://github.com/python-poetry/poetry" | ||
rev: "1.7.0" | ||
hooks: | ||
- id: "poetry-lock" | ||
stages: ["push"] | ||
name: "Run Poetry lock hook" | ||
args: ["--no-update"] | ||
- id: "poetry-check" | ||
stages: ["push"] | ||
name: "Run Poetry check hook" |
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 @@ | ||
## CS2 Battle Discord Bot |
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 @@ | ||
"""Main bot package.""" |
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,66 @@ | ||
"""CS2 Battle Bot main module.""" | ||
|
||
import discord | ||
import redis | ||
import sentry_sdk | ||
from dotenv import load_dotenv | ||
from redis import ConnectionError, TimeoutError | ||
|
||
from bot.cogs.match import MatchCog | ||
from bot.logger import logger | ||
from bot.settings import settings | ||
|
||
load_dotenv() | ||
|
||
bot = discord.Bot(intents=discord.Intents.all()) | ||
sentry_sdk.init( | ||
dsn=settings.SENTRY_DSN, | ||
environment="production" if not settings.TESTING else "development", | ||
) | ||
|
||
|
||
@bot.event | ||
async def on_ready() -> None: | ||
"""Print a message when the bot is ready.""" | ||
logger.debug(f"We have logged in as {bot.user}") | ||
|
||
|
||
@bot.event | ||
async def on_application_command_error( | ||
ctx: discord.ApplicationContext, error: discord.DiscordException | ||
) -> None: | ||
""" | ||
Handle errors that occur while processing a command. | ||
Args: | ||
---- | ||
ctx (discord.ApplicationContext): The context in which the command was invoked. | ||
error (discord.DiscordException): The error that occurred. | ||
Returns: | ||
------- | ||
None: This function does not return anything. | ||
""" | ||
logger.error(repr(error)) | ||
sentry_sdk.capture_exception(error) | ||
await ctx.respond("An error occurred while processing the command.") | ||
|
||
|
||
try: | ||
_redis = redis.StrictRedis( | ||
host=settings.REDIS_HOST, | ||
port=settings.REDIS_PORT, | ||
db=settings.REDIS_DB, | ||
password=settings.REDIS_PASSWORD if settings.REDIS_PASSWORD else None, | ||
) | ||
response = _redis.ping() | ||
pubsub = _redis.pubsub() | ||
pubsub.psubscribe("event.*") | ||
bot.add_cog(MatchCog(bot, pubsub)) | ||
logger.debug(f"Connected to Redis: {response}") | ||
except (ConnectionError, TimeoutError) as e: | ||
logger.error(f"Redis connection error: {e}") | ||
# Handle the error appropriately, e.g., retrying or logging | ||
sentry_sdk.capture_exception(e) | ||
bot.run(settings.TOKEN) |
Oops, something went wrong.