抖音直播间刷屏打字脚本,快手小红书直播间刷屏弹幕,发言打字发消息插件【autojs】

270 阅读2分钟

下载地址:www.pan38.com/dow/share.p… 提取密码:2812

这个直播间打字机器人包含完整功能模块:1) 热键控制 2) 随机消息发送 3) 可配置参数 4) 消息库管理。使用时需要先安装依赖库,按F1启动/F2停止,消息和配置均可自定义修改。

import time import random import pyautogui from pynput import keyboard import threading import json import os from datetime import datetime

class LiveChatBot: def init(self): self.running = False self.messages = [] self.load_config() self.setup_hotkeys() self.load_messages()

def load_config(self):
    """加载配置文件"""
    self.config = {
        'start_hotkey': 'f1',
        'stop_hotkey': 'f2',
        'min_delay': 1.5,
        'max_delay': 3.0,
        'typing_speed': 0.05,
        'message_file': 'messages.json'
    }
    try:
        if os.path.exists('config.json'):
            with open('config.json', 'r') as f:
                self.config.update(json.load(f))
    except Exception as e:
        print(f"加载配置出错: {e}")

def load_messages(self):
    """加载预设消息"""
    try:
        if os.path.exists(self.config['message_file']):
            with open(self.config['message_file'], 'r') as f:
                self.messages = json.load(f)
        else:
            self.messages = [
                "主播好棒!",
                "666666",
                "关注了",
                "礼物走一波",
                "这个操作太秀了"
            ]
    except Exception as e:
        print(f"加载消息出错: {e}")

def setup_hotkeys(self):
    """设置全局热键监听"""
    self.listener = keyboard.GlobalHotKeys({
        '<' + self.config['start_hotkey'] + '>': self.start_bot,
        '<' + self.config['stop_hotkey'] + '>': self.stop_bot
    })
    self.listener.start()

def start_bot(self):
    """启动机器人"""
    if not self.running:
        self.running = True
        print(f"[{datetime.now()}] 机器人已启动")
        threading.Thread(target=self.run_bot, daemon=True).start()

def stop_bot(self):
    """停止机器人"""
    self.running = False
    print(f"[{datetime.now()}] 机器人已停止")

def run_bot(self):
    """主运行逻辑"""
    while self.running:
        try:
            # 随机选择消息
            msg = random.choice(self.messages)
            
            # 模拟打字
            pyautogui.write(msg, interval=self.config['typing_speed'])
            pyautogui.press('enter')
            
            # 随机延迟
            delay = random.uniform(
                self.config['min_delay'], 
                self.config['max_delay']
            )
            time.sleep(delay)
            
        except Exception as e:
            print(f"[{datetime.now()}] 发送消息出错: {e}")
            time.sleep(5)

def add_message(self, message):
    """添加新消息"""
    self.messages.append(message)
    self.save_messages()

def save_messages(self):
    """保存消息到文件"""
    try:
        with open(self.config['message_file'], 'w') as f:
            json.dump(self.messages, f, indent=4)
    except Exception as e:
        print(f"保存消息出错: {e}")

if name == "main": bot = LiveChatBot() print("直播间打字机器人已初始化") print(f"启动热键: F1, 停止热键: F2") print("按Ctrl+C退出程序")

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    bot.stop_bot()
    print("程序已退出")


"start_hotkey": "f1",
"stop_hotkey": "f2",
"min_delay": 1.5,
"max_delay": 3.0,
"typing_speed": 0.05,
"message_file": "messages.json"

} "start_hotkey": "f1", "stop_hotkey": "f2", "min_delay": 1.5, "max_delay": 3.0, "typing_speed": 0.05, "message_file": "messages.json" }