mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-27 22:40:55 +00:00
⚡️ Refactor LiteyukiBot structure and add configuration loading
- Updated .gitignore to include .pytest_cache - Replaced FastAPI with Daemon in main.py for bot execution - Enhanced pyproject.toml with new dependencies and dev group - Added iniconfig package for pytest configuration - Created initial structure for liteyukibot with context management - Implemented configuration loading functions for YAML, JSON, and TOML - Added tests for configuration loading with temporary files - Set up GitHub Actions for pytest testing on push and pull requests
This commit is contained in:
0
liteyukibot/__init__.py
Normal file
0
liteyukibot/__init__.py
Normal file
0
liteyukibot/adapter/__init__.py
Normal file
0
liteyukibot/adapter/__init__.py
Normal file
44
liteyukibot/config.py
Normal file
44
liteyukibot/config.py
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
from typing import Any
|
||||
|
||||
import json
|
||||
import yaml
|
||||
import tomllib
|
||||
|
||||
|
||||
def load_from_yaml(file_path: str) -> dict[str, Any]:
|
||||
"""从yaml文件中加载配置并返回字典
|
||||
|
||||
Args:
|
||||
file_path (str): yaml文件路径
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: 配置字典
|
||||
"""
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
return yaml.safe_load(file)
|
||||
|
||||
def load_from_json(file_path: str) -> dict[str, Any]:
|
||||
"""从json文件中加载配置并返回字典
|
||||
|
||||
Args:
|
||||
file_path (str): json文件路径
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: 配置字典
|
||||
"""
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
return json.load(file)
|
||||
|
||||
def load_from_toml(file_path: str) -> dict[str, Any]:
|
||||
"""从toml文件中加载配置并返回字典
|
||||
|
||||
Args:
|
||||
file_path (str): toml文件路径
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: 配置字典
|
||||
"""
|
||||
with open(file_path, "rb") as file:
|
||||
return tomllib.load(file)
|
15
liteyukibot/context/__init__.py
Normal file
15
liteyukibot/context/__init__.py
Normal file
@ -0,0 +1,15 @@
|
||||
class Context:
|
||||
def __init__(self):
|
||||
self._context = {}
|
||||
|
||||
def set(self, key, value):
|
||||
self._context[key] = value
|
||||
|
||||
def get(self, key):
|
||||
return self._context.get(key)
|
||||
|
||||
def clear(self):
|
||||
self._context.clear()
|
||||
|
||||
def __repr__(self):
|
||||
return f"Context({self._context})"
|
0
liteyukibot/context/bot.py
Normal file
0
liteyukibot/context/bot.py
Normal file
0
liteyukibot/context/message.py
Normal file
0
liteyukibot/context/message.py
Normal file
0
liteyukibot/context/session.py
Normal file
0
liteyukibot/context/session.py
Normal file
0
liteyukibot/context/user.py
Normal file
0
liteyukibot/context/user.py
Normal file
16
liteyukibot/daemon.py
Normal file
16
liteyukibot/daemon.py
Normal file
@ -0,0 +1,16 @@
|
||||
import asyncio
|
||||
|
||||
|
||||
class Daemon:
|
||||
def __init__(self, **config):
|
||||
self.config = config
|
||||
|
||||
async def _run(self):
|
||||
"""liteyukibot入口函数
|
||||
"""
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""liteyukibot入口函数
|
||||
"""
|
||||
asyncio.run(self._run())
|
Reference in New Issue
Block a user