2015-01-28 3 views
2

시작하려면 어디에서나 대답을 찾을 수 없습니다. 임포트 할 필요가있는 코드인지 아니면 제대로 수행되지 않은 코드인지 확실하지 않습니다. 너트 셸에서이 프로젝트를 통해 SMS 메시지로 더 나은 트 위치 팔로워 알리미를 만드는 방법과 다른 많은 것들이 있습니다.TypeError : 버퍼 인터페이스를 지원하지 않습니다. Twitch IRC Chat Bot

편집 : 다음과 같이 전체 충돌 로그는 다음과 같습니다

line 16 in <module> 
irc.send('PASS ' + password + '\r\n') 
TypeError: Does not support the buffer interface 

을 또한, 나는이를 얻을 수있는 파일을 클릭 반복적으로 두 번에 한을, 그래서 미안의 경우 조금 떨어져. 코드 크래시 로그를 작동시키지 못했습니다.

import socket #imports module allowing connection to IRC 
import threading #imports module allowing timing functions 

bot_owner = 'BetterFollowerBot' 
nick = 'BetterFollowerBot' 
channel = '#BetterFollowerBot' 
server = 'irc.twitch.tv' 
password = '~Took This Out~' 

queue = 0 #sets variable for anti-spam queue functionality 

irc = socket.socket() 
irc.connect((server, 6667)) #connects to the server 

#sends variables for connection to twitch chat 
irc.send('PASS ' + password + '\r\n') 
irc.send('USER ' + nick + ' 0 * :' + bot_owner + '\r\n') 
irc.send('NICK ' + nick + '\r\n') 
irc.send('JOIN ' + channel + '\r\n') 

def message(msg): #function for sending messages to the IRC chat 
    global queue 
    queue = queue + 1 
    print (queue) 
    if queue < 20: #ensures does not send >20 msgs per 30 seconds. 
     irc.send('PRIVMSG ' + channel + ' :' + msg + '\r\n') 
    else: 
     print ('Message deleted') 

def queuetimer(): #function for resetting the queue every 30 seconds 
    global queue 
    print ('queue reset') 
    queue = 0 
    threading.Timer(30,queuetimer).start() 
queuetimer() 

while True: 
    data = irc.recv(1204) #gets output from IRC server 
    user = data.split(':')[1] 
    user = user.split('!')[0] #determines the sender of the messages 
    print (data) 

    if data.find('PING') != -1: 
     irc.send(data.replace('PING', 'PONG')) #responds to PINGS from the server 
    if data.find('!test') != -1: #!test command 
     message('Hi') 
+0

가있는 라인 오류를 얻고있다, 당신은 전체 역 추적을 붙여 넣을 수 있을까? – Roberto

+0

예. 할 수 있습니다. 지금 추가 – EduCodes

+0

편집을 추가했습니다. – EduCodes

답변

2

당신은 bytes로 변환해야합니다

irc.send(bytes("PASS {}\r\n".format(password), 'utf-8')) 
irc.send(bytes('USER {} 0 * :{}\r\n'.format(nick,bot_owner),"utf-8")) 
irc.send(bytes('NICK {}\r\n'.format(nick),"utf-8")) 
irc.send(bytes('JOIN {}\r\n'.format(channel),"utf-8")) 

및 디코드 :

recv(1204).decode("utf-8") 
+0

이렇게하면이 오류가 발생합니다. http://imgur.com/IWA43LB – EduCodes

+0

너는 또한 해독 할 필요가있다 –

+0

오오 그래 ... 나는 해독 부분을 추가하는 것을 잊었다! 죄송합니다! – EduCodes

관련 문제