Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed Mar 2, 2025
1 parent 6505038 commit da9d067
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 127 deletions.
6 changes: 3 additions & 3 deletions core/animals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import environ
from typing import Any

from environs import env
from hikari import Embed
from loguru import logger

Expand Down Expand Up @@ -192,7 +192,7 @@ async def TheCatAPI() -> Embed | None:

data: dict[str, Any] | list[Any] | str | None = await GET(
"https://api.thecatapi.com/v1/images/search",
headers={"x-api-key": environ["CAT_API_KEY"]},
headers={"x-api-key": env.str("CAT_API_KEY")},
)

if not data:
Expand Down Expand Up @@ -260,7 +260,7 @@ async def TheDogAPI() -> Embed | None:

data: dict[str, Any] | list[Any] | str | None = await GET(
"https://api.thedogapi.com/v1/images/search",
{"x-api-key": environ["DOG_API_KEY"]},
{"x-api-key": env.str("DOG_API_KEY")},
)

if not data:
Expand Down
11 changes: 5 additions & 6 deletions core/reddit.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
from os import environ

import asyncpraw
from asyncpraw.reddit import Reddit
from environs import env
from loguru import logger


async def CreateClient() -> Reddit | None:
"""Create an authenticated Reddit client using the configured credentials."""

if not (username := environ.get("REDDIT_USERNAME")):
if not (username := env.str("REDDIT_USERNAME")):
logger.error("Failed to authenticate with Reddit, username is null")

return
elif not (password := environ.get("REDDIT_PASSWORD")):
elif not (password := env.str("REDDIT_PASSWORD")):
logger.error("Failed to authenticate with Reddit, password is null")

return
elif not (clientId := environ.get("REDDIT_CLIENT_ID")):
elif not (clientId := env.str("REDDIT_CLIENT_ID")):
logger.error("Failed to authenticate with Reddit, clientId is null")

return
elif not (clientSecret := environ.get("REDDIT_CLIENT_SECRET")):
elif not (clientSecret := env.str("REDDIT_CLIENT_SECRET")):
logger.error("Failed to authenticate with Reddit, clientSecret is null")

return
Expand Down
19 changes: 9 additions & 10 deletions n31l.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import os
from os import environ
from sys import exit, stdout

import dotenv
from arc import GatewayClient
from environs import env
from hikari import Activity, ActivityType, GatewayBot, Intents, Permissions, Status
from loguru import logger
from loguru_discord import DiscordSink
Expand All @@ -16,10 +15,10 @@
logger.info("N31L")
logger.info("https://github.com/EthanC/N31L")

if dotenv.load_dotenv():
if env.read_env(recurse=False):
logger.success("Loaded environment variables")

if level := environ.get("LOG_LEVEL"):
if level := env.str("LOG_LEVEL"):
logger.remove()
logger.add(stdout, level=level)

Expand All @@ -28,12 +27,12 @@
# Reroute standard logging to Loguru
logging.basicConfig(handlers=[Intercept()], level=0, force=True)

logger.add("error.log", level="ERROR", rotation=environ.get("LOG_FILE_SIZE", "100 MB"))
logger.add("error.log", level="ERROR", rotation=env.str("LOG_FILE_SIZE", "100 MB"))

if url := environ.get("LOG_DISCORD_WEBHOOK_URL"):
if url := env.url("LOG_DISCORD_WEBHOOK_URL"):
logger.add(
DiscordSink(url),
level=environ["LOG_DISCORD_WEBHOOK_LEVEL"],
DiscordSink(url.geturl()),
level=env.str("LOG_DISCORD_WEBHOOK_LEVEL"),
backtrace=False,
)

Expand All @@ -51,7 +50,7 @@
except Exception as e:
logger.opt(exception=e).debug("Defaulted to asyncio event loop")

if not environ.get("DISCORD_TOKEN"):
if not (token := env.str("DISCORD_TOKEN")):
logger.critical("Failed to initialize bot, DISCORD_TOKEN is not set")

exit(1)
Expand All @@ -64,7 +63,7 @@
isDebug: bool = True if (level and level == "DEBUG" or "TRACE") else False

bot: GatewayBot = GatewayBot(
environ["DISCORD_TOKEN"],
token,
allow_color=False,
banner=None,
suppress_optimization_warning=isDebug,
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ description = "N31L is a utilitarian bot for the Call of Duty server."
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"python-dotenv>=1.0.1",
"environs>=14.1.1",
"loguru>=0.7.3",
"loguru-discord>=1.4.0",
"hikari-arc>=1.4.0",
"httpx>=0.28.1",
"asyncpraw>=7.8.0",
"asyncpraw>=7.8.1",
"urlextract>=1.9.0",
"uvloop>=0.21.0; sys_platform != 'win32'",
]
Expand All @@ -21,7 +21,7 @@ build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"ruff>=0.8.3",
"ruff>=0.9.9",
"asyncpraw-stubs>=0.0.3",
]

Expand Down
Loading

0 comments on commit da9d067

Please sign in to comment.