Skip to content

Commit

Permalink
fix: 修复消息转发死循环问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassius0924 committed Mar 7, 2024
1 parent d031f8e commit a8e5e26
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
8 changes: 0 additions & 8 deletions wechatter/config/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ def validate_config(config):
logger.critical(error_msg)
raise ValueError(error_msg)

# 判断这个 rule 是否有 from_list_exclude 字段
if (
"from_list_exclude" in rule
and config["bot_name"] not in rule["from_list_exclude"]
):
# 加入机器人名字,防止机器人自己转发自己的消息,导致死循环刷屏
rule["from_list_exclude"].append(config["bot_name"])

# Discord 消息转发配置
ess_fields = ["from_list", "webhook_url"]
for i, rule in enumerate(config["discord_message_forwarding_rule_list"]):
Expand Down
1 change: 0 additions & 1 deletion wechatter/init_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ def init_logger(log_level: str = ""):
rotation="00:00",
encoding="utf-8",
format=LOGURU_FORMAT,
colorize=True,
)
4 changes: 4 additions & 0 deletions wechatter/message/message_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def forwarding_to_wechat(self, message_obj: Message):
"""
# TODO: 转发文件

# 判断发送者是否为自己
if message_obj.is_from_self:
return

# 判断是否设置了转发规则
if not self.all_message_rule and not self.specific_message_rules:
logger.warning(
Expand Down

0 comments on commit a8e5e26

Please sign in to comment.