mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Remove aiofiles
This commit is contained in:
13
poetry.lock
generated
13
poetry.lock
generated
@@ -1,16 +1,5 @@
|
|||||||
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
|
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aiofiles"
|
|
||||||
version = "24.1.0"
|
|
||||||
description = "File support for asyncio."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "aiofiles-24.1.0-py3-none-any.whl", hash = "sha256:b4ec55f4195e3eb5d7abd1bf7e061763e864dd4954231fb8539a0ef8bb8260e5"},
|
|
||||||
{file = "aiofiles-24.1.0.tar.gz", hash = "sha256:22a075c9e5a3810f0c2e48f3008c94d68c65d763b9b03857924c99e57355166c"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aiohappyeyeballs"
|
name = "aiohappyeyeballs"
|
||||||
version = "2.3.5"
|
version = "2.3.5"
|
||||||
@@ -1042,4 +1031,4 @@ multidict = ">=4.0"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "27b0f4ead7c887aebd3b02cc312f47b4b3bb2c1c80f0f2d6cf5ce60494952fe8"
|
content-hash = "bc98a45353566e77b38104fd1dfd6ece7fa5f48823e9ca44181e96ea870d09de"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ discord-py = "^2.4.0"
|
|||||||
twitchapi = "^4.3.1"
|
twitchapi = "^4.3.1"
|
||||||
pydantic = "^2.9.2"
|
pydantic = "^2.9.2"
|
||||||
pydantic-settings = "^2.6.1"
|
pydantic-settings = "^2.6.1"
|
||||||
aiofiles = "^24.1.0"
|
|
||||||
httpx = "^0.27.2"
|
httpx = "^0.27.2"
|
||||||
icalendar = "^6.0.1"
|
icalendar = "^6.0.1"
|
||||||
pytz = "^2024.2"
|
pytz = "^2024.2"
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
from asyncio import Lock
|
|
||||||
import json
|
|
||||||
|
|
||||||
import aiofiles
|
|
||||||
|
|
||||||
from core.config import config
|
|
||||||
from core.mongo import mongo_manager
|
from core.mongo import mongo_manager
|
||||||
|
|
||||||
|
|
||||||
@@ -11,16 +5,10 @@ class TokenStorage:
|
|||||||
COLLECTION_NAME = "secrets"
|
COLLECTION_NAME = "secrets"
|
||||||
OBJECT_ID = "twitch_tokens"
|
OBJECT_ID = "twitch_tokens"
|
||||||
|
|
||||||
lock = Lock()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def save(acceess_token: str, refresh_token: str):
|
async def save(acceess_token: str, refresh_token: str):
|
||||||
data = {"access_token": acceess_token, "refresh_token": refresh_token}
|
data = {"access_token": acceess_token, "refresh_token": refresh_token}
|
||||||
|
|
||||||
async with TokenStorage.lock:
|
|
||||||
async with aiofiles.open(config.SECRETS_FILE_PATH, "w") as f:
|
|
||||||
await f.write(json.dumps(data))
|
|
||||||
|
|
||||||
async with mongo_manager.connect() as client:
|
async with mongo_manager.connect() as client:
|
||||||
db = client.get_default_database()
|
db = client.get_default_database()
|
||||||
collection = db[TokenStorage.COLLECTION_NAME]
|
collection = db[TokenStorage.COLLECTION_NAME]
|
||||||
@@ -38,15 +26,5 @@ class TokenStorage:
|
|||||||
collection = db[TokenStorage.COLLECTION_NAME]
|
collection = db[TokenStorage.COLLECTION_NAME]
|
||||||
|
|
||||||
data = await collection.find_one({"_id": TokenStorage.OBJECT_ID})
|
data = await collection.find_one({"_id": TokenStorage.OBJECT_ID})
|
||||||
if data is not None:
|
|
||||||
return data["access_token"], data["refresh_token"]
|
|
||||||
|
|
||||||
async with TokenStorage.lock:
|
return data["access_token"], data["refresh_token"]
|
||||||
async with aiofiles.open(config.SECRETS_FILE_PATH, "r") as f:
|
|
||||||
data_str = await f.read()
|
|
||||||
|
|
||||||
data = json.loads(data_str)
|
|
||||||
|
|
||||||
await TokenStorage.save(data["access_token"], data["refresh_token"])
|
|
||||||
|
|
||||||
return data["access_token"], data["refresh_token"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user