Files
discord-meeting-bot/config.py
T

34 lines
930 B
Python

import json
import aiofiles
from pathlib import Path
from typing import Optional
CONFIG_PATH = Path("config.json")
async def load_config() -> dict:
if not CONFIG_PATH.exists():
return {}
async with aiofiles.open(CONFIG_PATH, "r") as f:
data = await f.read()
return json.loads(data)
async def save_config(config: dict) -> None:
async with aiofiles.open(CONFIG_PATH, "w") as f:
await f.write(json.dumps(config, indent=2))
async def get_output_channel(guild_id: int) -> Optional[int]:
config = await load_config()
return config.get(str(guild_id), {}).get("output_channel_id")
async def set_output_channel(guild_id: int, channel_id: int) -> None:
config = await load_config()
guild_key = str(guild_id)
guild_config = config.get(guild_key, {})
guild_config["output_channel_id"] = channel_id
config[guild_key] = guild_config
await save_config(config)