feat: initial discord meeting bot
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user