簡體   English   中英

使用Python連接到IRC

[英]Connecting to IRC using Python

我是編程新手,正在嘗試使用Python為Twitch創建一個簡單的“僅發送IRC”客戶端。

但是我從代碼開始就遇到了問題:(,顯然在使用命令連接並發送了密碼和用戶名后,我似乎沒有收到服務器的響應。

不知道我在做什么錯,任何幫助或指導將不勝感激。

編碼:

username = '~omitted~'
password = 'oauth:~omitted~'
channel = '#channelname'

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect(('irc.twitch.tv', 6667))
irc.recv(4096)
irc.send('PASS ' + password + '\r\n')
irc.send('NICK ' + username + '\r\n')
irc.send('USER ' + username + '\r\n')
irc.send('JOIN ' + channel + '\r\n')


while True:
    data = irc.recv(4096)
    print(data)
    if data.find('PONG') != -1:
        irc.send('PONG ' + data.split()[1] + '\r\n')

這是我用於irc日志記錄的代碼片段:

readbuffer = ''
s=socket.socket()
s.connect((HOST, PORT))
s.send('NICK %s\r\n' % NICK)
s.send('USER %s %s bla :%s\r\n' % (IDENT, HOST, REALNAME))

log = False
while 1:
  readbuffer = readbuffer + s.recv(1024)
  temp       = string.split(readbuffer, '\n')
  readbuffer = temp.pop()
  for line in temp:
    line = string.split(string.rstrip(line))
    if(line[0] == 'PING'):
      s.send('PONG %s\r\n' % line[1])
    else:
      if(line[-1]=='+x'):
        print ' '.join(line)
        s.send('JOIN #twitlive\r\n')
        log = True
      else:
        if not log:
          print ' '.join(line[3:])
        else:
          if len(line) > 3:
            fullname = ''
            name = ''
            if line[0].split('!')[0][0] == ':':
              fullname = line[0][1:]
              name = line[0].split('!')[0][1:]
            if line[3:][0][0] == ':':
              ...
              ...

也許您發現其中有用的東西

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM