尝试建立Twitch Plays X时遇到“无法连接到抽搐”的问题

问题描述

我一直在遵循本指南,了解如何构建自己的“ Twitch Plays X”,这是一种控制流媒体PC的众包聊天。

当我通过LiClipse Workspace运行它时,它一直给我错误“无法连接到抽搐”。我安装了pywin32,pip和python(兼容版本)。我有main.py,twitch.py​​和keypresser.py。出于明显的原因,我已经隐藏了我的oauth代码。

main.py

#Define the imports
import twitch
import keypresser
t = twitch.Twitch();
k = keypresser.Keypresser();
 
#Enter your twitch username and oauth-key below,and the app connects to twitch with the details.
#Your oauth-key can be generated at http://twitchapps.com/tmi/
username = "twitchplaystrading";
key = "oauth:";
t.twitch_connect(username,key);
 
#The main loop
while True:
    #Check for new mesasages
    new_messages = t.twitch_recieve_messages();
 
    if not new_messages:
        #No new messages...
        continue
    else:
        for message in new_messages:
            #Wuhu we got a message. Let's extract some details from it
            msg = message['message'].lower()
            username = message['username'].lower()
            print(username + ": " + msg);
 
            #This is where you change the keys that shall be pressed and listened to.
            #The code below will simulate the key q if "q" is typed into twitch by someone
            #.. the same thing with "w"
            #Change this to make Twitch fit to your game!
            if msg == "!buy aapl": k.key_press("a");
            if msg == "!buy amzn": k.key_press("z");
            if msg == "!buy spy": k.key_press("s");            
            if msg == "!sell aapl": k.key_press("b");
            if msg == "!sell amzn": k.key_press("x");
            if msg == "!sell spy": k.key_press("d");
            if msg == "!close all": k.key_press("c");  

      

twitch.py​​

import socket
import sys
import re

class Twitch:

    user = "";
    oauth = "";
    s = None;

    def twitch_login_status(self,data):
        if not re.match(r'^:(testserver\.local|tmi\.twitch\.tv) NOTICE \* :Login unsuccessful\r\n$',data): return True
        else: return False

    def twitch_connect(self,user,key):
        self.user = user;
        self.oauth= key;
        print("Connecting to twitch.tv");
        s = socket.socket(socket.AF_INET,socket.SOCK_STREAM);
        s.settimeout(0.6);
        connect_host = "irc.twitch.tv";
        connect_port = 6667;
        try:
            s.connect((connect_host,connect_port));
        except:
            print("Failed to connect to twitch");
            sys.exit();
        print("Connected to twitch");
        print("Sending our details to twitch...");
        s.send('USER %s\r\n' % user);
        s.send('PASS %s\r\n' % key);
        s.send('NICK %s\r\n' % user);

        if not self.twitch_login_status(s.recv(1024)):
            print("... and they didn't accept our details");
            sys.exit();
        else:
            print("... they accepted our details");
            print("Connected to twitch.tv!")
            self.s = s;
            s.send('JOIN #%s\r\n' % user)
            s.recv(1024);

    def check_has_message(self,data):
        return re.match(r'^:[a-zA-Z0-9_]+\![a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\.tmi\.twitch\.tv|\.testserver\.local) PRIVMSG #[a-zA-Z0-9_]+ :.+$',data)

    def parse_message(self,data):
        return {
            'channel': re.findall(r'^:.+\![a-zA-Z0-9_]+@[a-zA-Z0-9_]+.+ PRIVMSG (.*?) :',data)[0],'username': re.findall(r'^:([a-zA-Z0-9_]+)\!','message': re.findall(r'PRIVMSG #[a-zA-Z0-9_]+ :(.+)',data)[0].decode('utf8')
        }

    def twitch_recieve_messages(self,amount=1024):
        data = None
        try: data = self.s.recv(1024);
        except: return False;

        if not data:
            print("Lost connection to Twitch,attempting to reconnect...");
            self.twitch_connect(self.user,self.oauth);
            return None

        #self.ping(data)

        if self.check_has_message(data):
            return [self.parse_message(line) for line in filter(None,data.split('\r\n'))];

keypresser.py

import socket
import sys
import re

class Twitch:

    user = "";
    oauth = "";
    s = None;

    def twitch_login_status(self,data.split('\r\n'))];

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...