我的 irc 连接有问题

问题描述 投票:0回答:1

我对代码不太了解,我正在遵循一个教程,代码工作正常,然后无缘无故地停止工作,我已经尝试解决这个问题好几天了。我尝试过搞乱一切,但没有任何效果。它本来应该连接到 Twitch 和我的聊天室,但我不知道为什么它不起作用。我还在 sublime text 中使用 python,直到几天前我的代码都运行良好,现在我的代码将不会再次恢复正常。我也对这篇文章的格式表示歉意,我是堆栈溢出新手,抱歉。 这是原始代码给出的反馈位于底部。 (占位符就在那里,因为我不想发布我自己的 twitch 聊天密钥,但您可以使用此网站获取您自己的)https://twitchapps.com/tmi/

import socket
import pyautogui
SERVER = "irc.twitch.tv"
PORT = 6667
PASS = "oauth:placeholder"
BOT = "twitchbot"
CHANNEL = "yamps_"
OWNER = "yamps_"
irc = socket.socket()
irc.connect((SERVER, PORT))
irc.send(("PASS " + PASS + "\n" +
            "NICK " + BOT + "\n" +
            "JOIN #" + CHANNEL + "\n").encode())
def gamecontrol():
    global message
    while true:
        if "up" in message.lower():
            pyautogui.keyDown('up')
        message = ""
        pyautogui.keyUp('up')
    else:
        pass
def twitch():
    def joinchat():
        Loading = True
    while Loading:
        readbuffer_join = irc.recv(1024)
        readbuffer_join = readbuffer_join.decode()
        for line in readbuffer_join.split("\n")[0:-1]:
            print(line)
            loading = loadingComplete(line)
def loadingComplete(line):
        if ("End of /NAMES list" in line):
            print("Bot has joined " + CHANNEL + "Channel")
            sendMessage(irc, "Chat room Joined")
            return False
        else:
                return True
def sendMessage(irc, message): 
    messageTemp = "PRIVMSG #" + CHANNEL  + message
    irc.send((messageTemp + "\n").encode())
def getUser(line):
    seperate = line.split(":", 2)
    user = seperate[1].split("!", 1)[0]
    print(user)
    return user 
    def getMessage(line):
        try:
            message = (line.split(":,2"))[2]
        except:
                message = ""
                return message
    def Console(line):
        if "PRIVMSG" in line:
            return False
        else:
            return True

while  True:
            try:
                readbuffer = irc.recv(1024).decode()
            except:
                readbuffer = ""
                for line in readbuffer.split("\r\n"):
                    if line == "":
                        continue
                        if "PING" in line and Console(line):
                            msgg = "PONG tmi.twitch.tv\r\n".encode()
                        irc.send(msgg)
                        print(msgg)
                        continue
                else:
                    print(line)
                    user = getuser(line)
                    message = getMessage(line)
                    print(user + message)
if _name_=='_main_':
    t1 = threading.Thread(target = twitch)
    t1. start()
    t2 = threading.Thread(target = gamecontrol)
    t2.start()
    
joinchat()
Traceback (most recent call last):
      File "/Users/macintosh/Downloads/Twitch Plays/main/untitled.py", line 10, in <module>
            TimeoutError: [Errno 60] Operation timed out
        [Finished in 75.3s with exit code 1]
        [cmd: ['python3', '-u', '/Users/macintosh/Downloads/Twitch Plays/main/untitled.py']]
        [dir: /Users/macintosh/Downloads/Twitch Plays/main]```

python twitch
1个回答
0
投票

如果有人关心的话我找到了答案

joinchat

函数没有正确缩进

© www.soinside.com 2019 - 2024. All rights reserved.