视频号直播小号自动发评论脚本- vx: llike620

比如先准备这样的话术

00:00:12 第一!沙发!
00:00:28 从推荐来的,主播玩什么游戏啊?
00:00:45 今天怎么迟到了3分钟?
00:01:03 画质好清晰啊,什么设备?
00:01:19 主播声音好好听!
00:01:37 刚进来,这是在玩原神吗?
00:01:52 关注了,求眼熟~
00:02:08 哈哈哈这个操作笑死
00:02:25 能看看角色面板吗?
00:02:41 今天会抽奖吗?
00:02:57 学生党偷偷看直播+1
00:03:14 刚才那个连招太帅了!
00:03:31 主播多大了呀?
00:03:48 从B站来的,打卡!
00:04:05 这个bgm是什么歌?
00:04:22 手残党表示学不会
00:04:39 今天播到几点?
00:04:56 刚才失误了hhh
00:05:13 求好友位!
00:05:30 这个皮肤怎么获得?
00:05:47 吃饭了吗主播?
00:06:04 技术太强了吧
00:06:21 新人求带~
00:06:38 刚才那波666
00:06:55 卡了吗?画面不动了
00:07:12 今天状态不错啊
00:07:29 能说下键位设置吗?
00:07:46 关注半年了,第一次发言
00:08:03 同款鼠标!
00:08:20 刚才那个bgm好听
00:08:37 主播单身吗?
00:08:54 这个操作我练了好久
00:09:11 从微博来的+1
00:09:28 今天发型不错
00:09:45 刚才那个怪打了好久

执行python,就可以自动化的在微信的界面上模拟鼠标键盘操作了

import re
import time
import os
from datetime import datetime, timedelta
import uiautomation as uia
import pyperclip


def parse_text(text):
    """解析文本,返回(时间差, 话术)列表"""
    pattern = r'(\d{2}):(\d{2}):(\d{2})(.*)'
    result = []
    
    for line in text.split('\n'):
        if not line.strip():
            continue
        match = re.match(pattern, line)
        if match:
            h, m, s, msg = match.groups()
            time_delta = timedelta(
                hours=int(h),
                minutes=int(m),
                seconds=int(s)
            )
            result.append((time_delta, msg.strip()))
    
    return result

def start_commenting(comment):
    """发送评论到微信"""
    try:
        # 初始化微信窗口控制
        wechat_window = uia.PaneControl(
            Name="微信",
            ClassName="Chrome_WidgetWin_0"
        )
        wechat_window.SwitchToThisWindow()
        wechat_window.MoveToCenter()

        inputBox = wechat_window.TextControl(Name="聊一聊")
        inputBox.Click()
        pyperclip.copy(comment)
        inputBox.SendKeys('{Ctrl}a', waitTime=1)
        inputBox.SendKeys('{Ctrl}v', waitTime=1)
        inputBox.SendKeys('{Ctrl}{Enter}', waitTime=0)
        btn = wechat_window.TextControl(Name="评论")
        btn.Click()
    except Exception as e:
        print(f"发生错误: {e}")

def read_script_file(filename):
    """读取话术文件"""
    if not os.path.exists(filename):
        print(f"错误: 文件 {filename} 不存在")
        return None
    try:
        with open(filename, 'r', encoding='utf-8') as file:
            return file.read()
    except Exception as e:
        print(f"读取文件时出错: {e}")
        return None

def schedule_messages_single_thread(text):
    """单线程版消息调度"""
    messages = parse_text(text)
    start_time = datetime.now()
    
    # 转换为绝对时间并排序
    scheduled_messages = []
    for delta, msg in messages:
        scheduled_time = start_time + delta
        if scheduled_time > datetime.now():  # 只保留未过期的消息
            scheduled_messages.append((scheduled_time, msg))
    
    # 按时间排序
    scheduled_messages.sort(key=lambda x: x[0])
    
    print("当前时间:", start_time.strftime("%H:%M:%S"))
    print("待发送消息数量:", len(scheduled_messages))
    
    while scheduled_messages:
        now = datetime.now()
        next_time, next_msg = scheduled_messages[0]
        
        if now >= next_time:
            # 发送消息
            print(f"[{now.strftime('%H:%M:%S')}] 发送: {next_msg}")
            start_commenting(next_msg)
            scheduled_messages.pop(0)
        else:
            # 计算等待时间(最多1秒)
            wait_seconds = min((next_time - now).total_seconds(), 1)
            time.sleep(wait_seconds)
        
        # 检查是否被中断
        if not scheduled_messages:
            break

if __name__ == "__main__":
    script_file = "话术.txt"
    script_text = read_script_file(script_file)
    
    if script_text is None:
        exit(1)
    
    print("开始安排消息...")
    schedule_messages_single_thread(script_text)
    print("所有消息发送完成")

 

posted @ 2025-05-24 00:17  唯一客服系统开发笔记  阅读(34)  评论(0)    收藏  举报