微信群聊机器人插件,微信机器人聊天工具,微信群自动聊天脚本

简介: 代码说明:这个微信机器人系统包含主程序、群管理模块和多个插件。主程序基于itchat库实现微信登录和消息处理

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:9281

代码说明:这个微信机器人系统包含主程序、群管理模块和多个插件。主程序基于itchat库实现微信登录和消息处理,群管理模块扩展了群聊特有功能,插件系统可灵活扩展功能。使用时需要先安装itchat库(pip install itchat)。

import itchat
import time
import random
from threading import Thread
from queue import Queue

class WeChatBot:
def init(self):
self.msg_queue = Queue()
self.reply_rules = {
"你好": ["你好呀!", "嗨~", "欢迎找我聊天"],
"时间": lambda: f"现在是{time.strftime('%Y-%m-%d %H:%M:%S')}",
"天气": self.get_weather
}
self.auto_reply_enabled = True
self.keywords = ["机器人", "助手", "智能"]

def login(self):
    itchat.auto_login(hotReload=True, enableCmdQR=2)
    print("微信机器人登录成功")

def get_weather(self):
    weathers = ["晴天", "多云", "小雨", "大风", "雾霾"]
    return f"今天天气可能是{random.choice(weathers)}"

def message_handler(self, msg):
    if msg['Type'] != 'Text' or not msg.get('Text'):
        return

    content = msg['Text'].strip()
    sender = itchat.search_friends(userName=msg['FromUserName'])
    name = sender.get('NickName', '未知用户')

    print(f"收到来自[{name}]的消息: {content}")

    reply = None
    for keyword, response in self.reply_rules.items():
        if keyword in content:
            if callable(response):
                reply = response()
            else:
                reply = random.choice(response)
            break

    if not reply and any(kw in content for kw in self.keywords):
        reply = "我是智能助手,有什么可以帮你的吗?"

    if reply:
        itchat.send(reply, toUserName=msg['FromUserName'])

def auto_reply_thread(self):
    while True:
        if self.auto_reply_enabled and not self.msg_queue.empty():
            msg = self.msg_queue.get()
            self.message_handler(msg)
        time.sleep(0.1)

def run(self):
    self.login()
    itchat.run(blockThread=False)

    Thread(target=self.auto_reply_thread, daemon=True).start()

    @itchat.msg_register(itchat.content.TEXT)
    def text_reply(msg):
        self.msg_queue.put(msg)

    while True:
        time.sleep(1)

if name == "main":
bot = WeChatBot()
bot.run()

wechat_bot import WeChatBot
import re

class GroupManager(WeChatBot):
def init(self):
super().init()
self.group_rules = {
"签到": self.handle_check_in,
"投票": self.handle_vote,
"禁言": self.handle_mute
}
self.group_members = {}
self.votes = {}

def handle_check_in(self, msg):
    group_id = msg['FromUserName']
    user_id = msg['ActualUserName']

    if group_id not in self.group_members:
        self.group_members[group_id] = set()

    if user_id in self.group_members[group_id]:
        return f"@{msg['ActualNickName']} 您今天已经签到过了哦~"

    self.group_members[group_id].add(user_id)
    return f"@{msg['ActualNickName']} 签到成功!当前签到人数: {len(self.group_members[group_id])}"

def handle_vote(self, msg):
    content = msg['Text']
    match = re.search(r"投票 (.+?) (.+)", content)
    if not match:
        return "投票格式错误,请使用: 投票 主题 选项1 选项2"

    topic = match.group(1)
    options = match.group(2).split()

    if topic in self.votes:
        return f"投票主题'{topic}'已存在"

    self.votes[topic] = {
        'options': options,
        'votes': {opt: 0 for opt in options},
        'voters': set()
    }

    options_text = "\n".join(f"{i+1}. {opt}" for i, opt in enumerate(options))
    return f"投票创建成功:\n主题: {topic}\n选项:\n{options_text}\n请回复'投票 主题 选项编号'参与投票"

def handle_mute(self, msg):
    # 实现禁言逻辑
    return "禁言功能需要特殊权限"

def message_handler(self, msg):
    if msg.get('IsAt') and msg['FromUserName'].startswith('@@'):
        # 处理群消息
        content = msg['Text'].replace(f"@{msg['ToUserName']}", "").strip()

        for keyword, handler in self.group_rules.items():
            if keyword in content:
                reply = handler(msg)
                if reply:
                    itchat.send(reply, toUserName=msg['FromUserName'])
                return

    super().message_handler(msg)

if name == "main":
manager = GroupManager()
manager.run()

json
import os
from datetime import datetime

class AutoReplyPlugin:
def init(self, config_file="reply_config.json"):
self.config_file = config_file
self.reply_config = self.load_config()
self.last_save = datetime.now()

def load_config(self):
    if os.path.exists(self.config_file):
        with open(self.config_file, 'r', encoding='utf-8') as f:
            return json.load(f)
    return {"rules": {}, "blacklist": []}

def save_config(self):
    with open(self.config_file, 'w', encoding='utf-8') as f:
        json.dump(self.reply_config, f, ensure_ascii=False, indent=2)

def add_rule(self, keyword, replies):
    self.reply_config['rules'][keyword] = replies
    if (datetime.now() - self.last_save).seconds > 60:
        self.save_config()
        self.last_save = datetime.now()

def match_reply(self, content):
    for keyword, replies in self.reply_config['rules'].items():
        if keyword in content:
            return random.choice(replies)
    return None

def is_blacklisted(self, user_id):
    return user_id in self.reply_config['blacklist']
相关文章
|
4月前
|
算法 Java API
用录像代替视频聊天,虚拟视频聊天软件微信QQ, 微信第三方插件虚拟视频插件
核心视频处理模块使用JavaCV实现视频捕获、特效处理和虚拟设备输出 Xposed模块通过Hook微信摄像头相关方法实现视频流替换
|
5月前
|
机器人 数据安全/隐私保护 Python
微信自动转发机器人,微信群自动发消息机器人,微信全自动群发软件
展示一个使用Python进行基础网页自动化的示例代码,仅供学习自动化技术原理使用。
|
4月前
|
域名解析 人工智能 机器人
AppFlow:企业微信支持流式群聊机器人
企业微信近日更新,新增群聊机器人功能,支持与自定义大模型对话。通过@机器人,可实现流式输出,提升交互效率。只需简单配置,即可将AI能力集成至群聊,完成即时消息解析与业务联动。
939 1
AppFlow:企业微信支持流式群聊机器人
|
4月前
|
Shell Android开发 Python
微信多开脚本,微信双开器脚本插件,autojs开源代码分享
AutoJS脚本实现安卓端微信多开,通过无障碍服务 Python脚本提供跨平台解决方案,自动检测微信安装路径
|
5月前
|
JSON 机器人 API
微信机器人自动回复插件,vx自动回复机器人脚本助手,python框架分享
这个微信机器人系统包含三个主要模块:主程序基于itchat实现微信消息监听和自动回复功能
|
5月前
|
调度 Android开发 数据安全/隐私保护
微信养号是什么意思?有脚本吗
Python实现微信养号自动化操作指南 作者前言
|
5月前
|
机器学习/深度学习 JSON 运维
微信抢红包脚本会封号吗?
微信抢红包脚本通常通过以下几种技术方式实现:
|
5月前
|
监控 数据库 数据安全/隐私保护
微信自动抢红包永久免费软件, 自动抢红包软件微信,脚本插件抢红包【python】
该实现包含三个核心模块:主监控程序、数据库记录模块和配置模块。主程序使用itchat监听微信消息
|
5月前
|
Android开发 数据安全/隐私保护 Python
微信抢红包脚本安卓插件,微信xposed抢红包模块, magisk微信抢红包模块
这个代码实现了一个完整的微信抢红包自动化工具,包含红包检测、自动点击、日志记录等功能
|
5月前
|
消息中间件 人工智能 机器人
vx自动回复机器人,ai自动回复机器人,微信自动回复脚本插件
这个微信自动回复机器人包含主程序、配置管理、工具函数和单元测试模块。主程序使用itchat库实现微信登录和消息处理

热门文章

最新文章