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

自动同意好友申请的功能有吗 #2464

Open
2 tasks done
daifhafhia opened this issue Jan 10, 2025 · 3 comments
Open
2 tasks done

自动同意好友申请的功能有吗 #2464

daifhafhia opened this issue Jan 10, 2025 · 3 comments

Comments

@daifhafhia
Copy link

前置确认

  • 我确认我运行的是最新版本的代码,并且安装了所需的依赖,在FAQS中也未找到类似问题。

⚠️ 搜索issues中是否已存在类似问题

  • 我已经搜索过issues和disscussions,没有跟我遇到的问题相关的issue

操作系统类型?

Windows

运行的python版本是?

python 3.9

使用的chatgpt-on-wechat版本是?

Latest Release

运行的channel类型是?

wx(个人微信, itchat)

复现步骤 🕹

No response

问题描述 😯

想找到自动同意好友的功能

终端日志 📒

<此处粘贴终端日志>
@chenjingwei0103
Copy link

@itchat.msg_register(FRIENDS)
def add_friend(msg):
if msg['RecommendInfo']['Content'] == conf().get("auto_accept_friend_request"):
username = msg['RecommendInfo']['UserName']
v4 = msg['RecommendInfo']['Ticket']

    # 检查是否已经发送过欢迎消息
    if username in WechatChannel().welcomed_friends:
        logger.debug(f"已经发送过欢迎消息给用户: {username}")
        return
    
    # 接受好友请求
    itchat.instance.accept_friend(username, v4)
    time.sleep(1)
    
    # 获取新好友的信息
    new_friend = itchat.instance.search_friends(userName=username)
    if new_friend:
        # 发送欢迎消息
        welcome_text = conf().get("usage_instructions", "您好!我是您的AI助手,请问有什么可以帮您?")
        itchat.instance.send(welcome_text, toUserName=new_friend['UserName'])
        logger.info(f"发送欢迎消息给新好友: {new_friend['NickName']}")
        
        # 记录并保存已发送欢迎消息的好友
        WechatChannel().welcomed_friends.add(username)
        WechatChannel()._save_welcomed_friends()

再wechat_channel.py中添加msg['RecommendInfo']['Content'] == conf().get("auto_accept_friend_request") 这一行可以去掉,因为我是设置了固定好友申请的内容才会自动添加好友

@chenjingwei0103
Copy link

不建议重启了,现在itchat好像不能用了

@daifhafhia
Copy link
Author

不建议重启了,现在itchat好像不能用了

对,能运行一旦重启就不能用了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants