Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加Feishu通道 #1336

Open
wants to merge 4 commits into
base: browser-version
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
logger.info("检测到 Wecom 配置,将启动 Wecom Bot 模式……")
from platforms.wecom_bot import start_task

bots.append(loop.create_task(start_task()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Duplicate task creation for bots may lead to unintended behavior.

It appears that start_task() is being called and appended to bots twice in succession without any conditional checks in between. This might result in the same task being started twice unintentionally.

if config.feishu:
logger.info("检测到 feishu 配置,将启动 Feishu bot 模式……")
from platforms.feishu_bot import start_task

bots.append(loop.create_task(start_task()))
try:
logger.info("[Edge TTS] 读取 Edge TTS 可用音色列表……")
Expand Down
16 changes: 16 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ class WecomBot(BaseModel):
"""企业微信应用 API 令牌 的 EncodingAESKey"""


class FeishuBot(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring common bot configuration properties into a base class.

The addition of the FeishuBot class and its integration into the Config class introduces a higher level of complexity, primarily due to the increase in configuration parameters and the pattern of adding platform-specific bot configurations. While the implementation is consistent with the existing pattern, it's worth considering strategies to manage and potentially reduce complexity as the configuration grows.

One approach could be to refactor common properties among bot configurations into a base class. This base class could encapsulate properties like token, debug, and others that are shared across different bot configurations. Subsequent platform-specific configurations, like FeishuBot, could then extend this base class, adding or overriding properties as necessary. This would not only reduce redundancy but also simplify the addition of new bot configurations in the future.

Here's a simplified example of how this could be structured:

class BaseBotConfig(BaseModel):
    port: int
    debug: bool = False
    token: str
    app_id: Optional[str] = None
    app_secret: Optional[str] = None
    encrypt_key: Optional[str] = None

class FeishuBot(BaseBotConfig):
    port: int = 9880
    app_id: str
    app_secret: str
    # Inherits debug, token, and encrypt_key from BaseBotConfig

class Config(BaseModel):
    # Other platform settings...
    feishu: Optional[FeishuBot] = None
    # Account Settings...

This approach could make the codebase easier to maintain and extend, especially as more configurations are added. It's a suggestion to consider how the current implementation might evolve and how to manage complexity effectively.

port: int = 9880
"""飞书回调端口号, 默认9880"""
debug: bool = False
"""是否开启debug,错误时展示日志"""
app_id: str
"""飞书应用 的 App ID"""
app_secret: str
"""飞书应用 的 Secret"""
token: str
"""飞书应用 API 加密策略 的 Verification Token"""
encrypt_key: Optional[str] = None
Comment on lines +81 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider adding type hints for clarity and consistency.

Adding type hints for the class attributes would enhance code readability and maintain consistency with the rest of the codebase.

"""飞书应用的加密策略 encrypt_key"""


class OpenAIParams(BaseModel):
temperature: float = 0.5
max_tokens: int = 4000
Expand Down Expand Up @@ -560,6 +575,7 @@ class Config(BaseModel):
discord: Optional[DiscordBot] = None
http: Optional[HttpService] = None
wecom: Optional[WecomBot] = None
feishu: Optional[FeishuBot] = None

# === Account Settings ===
openai: OpenAIAuths = OpenAIAuths()
Expand Down
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ class BotPlatform(Enum):
TelegramBot = "telegram"
HttpService = "http"
WecomBot = "wecom"
FeishuBot = "feishu"