fix: tests and linters (ruff)
This commit is contained in:
2 files changed
+22
-6
No files matched your search
@@ -2,9 +2,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from collections.abc import Iterator
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Iterator
|
from typing import Any
|
||||||
|
|
||||||
import psycopg
|
import psycopg
|
||||||
|
|
||||||
@@ -71,7 +72,11 @@ class PostgresDatabase:
|
|||||||
for key, entries in history.items():
|
for key, entries in history.items():
|
||||||
if key.isdigit() and isinstance(entries, list):
|
if key.isdigit() and isinstance(entries, list):
|
||||||
_import_history(connection, int(key), entries)
|
_import_history(connection, int(key), entries)
|
||||||
elif key == "history" and isinstance(entries, list) and first_guild_id is not None:
|
elif (
|
||||||
|
key == "history"
|
||||||
|
and isinstance(entries, list)
|
||||||
|
and first_guild_id is not None
|
||||||
|
):
|
||||||
_import_history(connection, first_guild_id, entries)
|
_import_history(connection, first_guild_id, entries)
|
||||||
|
|
||||||
for path in (base / "queues").glob("*.json"):
|
for path in (base / "queues").glob("*.json"):
|
||||||
@@ -109,7 +114,12 @@ def _upsert_guild(
|
|||||||
try:
|
try:
|
||||||
value = int(values[field])
|
value = int(values[field])
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
logger.error("Nieprawidłowa wartość %s serwera %s: %r", field, guild_id, values[field])
|
logger.error(
|
||||||
|
"Nieprawidłowa wartość %s serwera %s: %r",
|
||||||
|
field,
|
||||||
|
guild_id,
|
||||||
|
values[field],
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
connection.execute(f"UPDATE guilds SET {field}=%s WHERE id=%s", (value, guild_id))
|
connection.execute(f"UPDATE guilds SET {field}=%s WHERE id=%s", (value, guild_id))
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ class PostgresGuildConfig:
|
|||||||
|
|
||||||
def _ensure(self, guild_id: int) -> None:
|
def _ensure(self, guild_id: int) -> None:
|
||||||
with self._database.connect() as connection:
|
with self._database.connect() as connection:
|
||||||
connection.execute("INSERT INTO guilds(id) VALUES (%s) ON CONFLICT(id) DO NOTHING", (guild_id,))
|
connection.execute(
|
||||||
|
"INSERT INTO guilds(id) VALUES (%s) ON CONFLICT(id) DO NOTHING", (guild_id,)
|
||||||
|
)
|
||||||
|
|
||||||
def get_notification_channel_id(self, guild_id: int) -> int | None:
|
def get_notification_channel_id(self, guild_id: int) -> int | None:
|
||||||
with self._database.connect() as connection:
|
with self._database.connect() as connection:
|
||||||
@@ -32,10 +34,14 @@ class PostgresGuildConfig:
|
|||||||
if guild_id is None:
|
if guild_id is None:
|
||||||
return self._fallback_plays
|
return self._fallback_plays
|
||||||
with self._database.connect() as connection:
|
with self._database.connect() as connection:
|
||||||
row = connection.execute("SELECT default_plays FROM guilds WHERE id=%s", (guild_id,)).fetchone()
|
row = connection.execute(
|
||||||
|
"SELECT default_plays FROM guilds WHERE id=%s", (guild_id,)
|
||||||
|
).fetchone()
|
||||||
return int(row[0]) if row and row[0] is not None else self._fallback_plays
|
return int(row[0]) if row and row[0] is not None else self._fallback_plays
|
||||||
|
|
||||||
def set_default_plays(self, guild_id: int, value: int) -> None:
|
def set_default_plays(self, guild_id: int, value: int) -> None:
|
||||||
self._ensure(guild_id)
|
self._ensure(guild_id)
|
||||||
with self._database.connect() as connection:
|
with self._database.connect() as connection:
|
||||||
connection.execute("UPDATE guilds SET default_plays=%s WHERE id=%s", (int(value), guild_id))
|
connection.execute(
|
||||||
|
"UPDATE guilds SET default_plays=%s WHERE id=%s", (int(value), guild_id)
|
||||||
|
)
|
||||||
Reference in new issue
Block a user