jxxghp / MoviePilot-Plugins

MoviePilot官方插件市场
GNU General Public License v3.0
203 stars 275 forks source link

注册EventType.NoticeMessage事件后 函数会被重复触发两次 #514

Closed HankunYu closed 1 month ago

HankunYu commented 1 month ago
    @eventmanager.register(EventType.NoticeMessage)
    def send(self, event: Event):
        msg_body = event.event_data
        msg_type: NotificationType = msg_body.get("mtype")
        logger.info(f"msg_type: {msg_type.value}")

打印日志可以看到

INFO:    chain - 发送消息:channel=None,source=None,title=乱马½ (2024) S01 已添加订阅, text=评分:8.4,来自用户:Hankun,userid=None
DEBUG:   event.py - Triggering broadcast event: <Broadcast Event: notice.message, ID: 460ef501-eb1e-4f33-a68d-94ad779f3fdd, Priority: 10>
DEBUG:   event.py - Handler app.plugins.dingdingmsg.DingdingMsg.send is disabled. Skipping execution
DEBUG:   event.py - Handler app.plugins.iyuumsg.IyuuMsg.send is disabled. Skipping execution
DEBUG:   event.py - Handler app.plugins.barkmsg.BarkMsg.send is disabled. Skipping execution
DEBUG:   chain - 请求模块执行:post_message ...
DEBUG:   event.py - Handler app.plugins.ntfymsg.NtfyMsg.send is disabled. Skipping execution
DEBUG:   event.py - Handler app.plugins.pushplusmsg.PushPlusMsg.send is disabled. Skipping execution
DEBUG:   event.py - Handler app.plugins.feishumsg.FeiShuMsg.send is disabled. Skipping execution
INFO:    discord - msg_type: 订阅
DEBUG:   event.py - Handler app.plugins.pushdeermsg.PushDeerMsg.send is disabled. Skipping execution
DEBUG:   event.py - Handler app.plugins.webhook.WebHook.send is disabled. Skipping execution
INFO:    discord - msg_type: 订阅
DEBUG:   event.py - Handler app.plugins.workwechatmsg.WorkWechatMsg.send is disabled. Skipping execution
DEBUG:   event.py - Triggering broadcast event: <Broadcast Event: subscribe.added, ID: a46169d5-7902-4b87-afe3-d1e8ec1a3476, Priority: 10>
InfinityPacer commented 1 month ago

@HankunYu 最下面那个是订阅事件,不过的确事件参数没兼容v1,需要看下怎么调整

HankunYu commented 1 month ago
DEBUG:   event.py - Subscribed to broadcast event: notice.message - plugins.discord.Discord.send
DEBUG:   event.py - Subscribed to broadcast event: notice.message - app.plugins.discord.Discord.send

不知道为什么会订阅事件两次,我新建了一个插件做测试却没有这个问题。。。 大佬有什么头绪么。。。。 @InfinityPacer

InfinityPacer commented 1 month ago
try:
    import app.plugins.discord.discord_bot as discord_bot
    import app.plugins.discord.tokenes as tokenes
    from app.plugins.discord.cogs.moviepilot_cog import MPCog
except ImportError as e:
    logger.error(f"ImportError: {e}")

__init__.py discord_bot.py moviepilot_cog.py 上面这几个,把 import 改成 app.xxxxxx,不要直接 import plugin,v2 调整了事件逻辑,改成了完全限定名

HankunYu commented 1 month ago

感谢大佬