Git-HandClup / plugin_midjourney

一个Midjourneyd插件,支持imagine、upscale、variation、blend、describe五个基本命令
25 stars 5 forks source link

能把chat_channel.py贴出来吗?改半天改不正确,我真拉胯 #3

Open KenGrofork opened 1 year ago

Git-HandClup commented 1 year ago

wechat_channel的文件中,条件:reply.type == ReplyType.IMAGE_URL的时候,将里面的代码替换成这个就可以了


            content = reply.content.split("?id=")
            for index, item in enumerate(content):
                if index > 0:
                    itchat.send("图片ID为:" + item, toUserName=receiver)
                    logger.info("[WX] sendMsg={}, receiver={}".format(reply, receiver))
                else:
                    proxy = conf().get("proxy", "")
                    proxies = {"http": proxy, "https": proxy}
                    pic_res = requests.get(item, proxies=proxies, stream=True)
                    image_storage = io.BytesIO()
                    for block in pic_res.iter_content(1024):
                        image_storage.write(block)
                    image_storage.seek(0)
                    itchat.send_image(image_storage, toUserName=receiver)
                    logger.info("[WX] sendImage url={}, receiver={}".format(item, receiver))```
KenGrofork commented 1 year ago

def _decorate_reply(self, context: Context, reply: Reply) -> Reply: if reply and reply.type: e_context = PluginManager().emit_event( EventContext( Event.ON_DECORATE_REPLY, {"channel": self, "context": context, "reply": reply}, ) ) reply = e_context["reply"] desire_rtype = context.get("desire_rtype") if not e_context.is_pass() and reply and reply.type: if reply.type in self.NOT_SUPPORT_REPLYTYPE: logger.error("[WX]reply type not support: " + str(reply.type)) reply.type = ReplyType.ERROR reply.content = "不支持发送的消息类型: " + str(reply.type)

            if reply.type == ReplyType.TEXT:
                reply_text = reply.content
                if desire_rtype == ReplyType.VOICE and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE:
                    reply = super().build_text_to_voice(reply.content)
                    return self._decorate_reply(context, reply)
                if context.get("isgroup", False):
                    reply_text = "@" + context["msg"].actual_user_nickname + " " + reply_text.strip()
                    reply_text = conf().get("group_chat_reply_prefix", "") + reply_text
                else:
                    reply_text = conf().get("single_chat_reply_prefix", "") + reply_text
                reply.content = reply_text
            elif reply.type == ReplyType.ERROR or reply.type == ReplyType.INFO:
                reply.content = "[" + str(reply.type) + "]\n" + reply.content
            elif reply.type == ReplyType.IMAGE_URL or reply.type == ReplyType.VOICE or reply.type == ReplyType.IMAGE:
                pass
            else:
                logger.error("[WX] unknown reply type: {}".format(reply.type))
                return
        if desire_rtype and desire_rtype != reply.type and reply.type not in [ReplyType.ERROR, ReplyType.INFO]:
            logger.warning("[WX] desire_rtype: {}, but reply type: {}".format(context.get("desire_rtype"), reply.type))
        return reply
KenGrofork commented 1 year ago

elif reply.type == ReplyType.IMAGE_URL or reply.type == ReplyType.VOICE or reply.type == ReplyType.IMAGE: pass这段怎么改

Git-HandClup commented 1 year ago

我没有对这个文件的代码进行改动,我只改动了wechat_channel.py