【问题标题】:IRC Bot Python | Identify NicknameIRC 机器人 Python |识别昵称
【发布时间】:2015-11-21 19:54:19
【问题描述】:

这是我的麻烦:Bot 很好地加载了 IRC 信息,但是当它假设要识别自己时,他没有。

以下是代码的相关部分。我猜问题出在第 9 行,但我不知道为什么。

import socket

server = #ServerName
channel = #ChannelName
botnick = #BotName
password = #Password (string)

def connect(channel, password): # This function is used on connect.
  ircsock.send("PRIVMSG" + " :NICKSERV Identify " + password +"\n") #Problem Here
  ircsock.send("JOIN "+ channel +"\n")

ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":Just testing .\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")

connect(channel, password) #Join the channel and identify the nick using the functions we previously defined

提前致谢。

解决方案: 通过将connect函数设置为posted,是第一个被调用的 然后服务器在 USER / NICK 之前尝试连接。

    def create_connection():
    global ircsock
    ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
    ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":This bot is a result of GStones mastery .\n") # user authentication
    ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
    time.sleep(5)
    connect(channel, password) # Join the channel and identify the nick using the functions we previously defined

create_connection()

谢谢i\OFF

【问题讨论】:

  • ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  • bot进入irc服务器但未执行connect函数,所以NickServ请求识别命令:“注意Botman:此昵称已注册。请选择不同的昵称,或通过/msg识别NickServ 识别 "
  • 也尝试使用不同的botnick。

标签: python sockets bots irc identify


【解决方案1】:

你还没有创建套接字,所以连接不会建立。

ircsock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) 创建一个套接字。

另外,在使用ircsock.send()之前,您需要连接到服务器。

ircsock.connect ((server, serverPort)) 连接到服务器。 这个例子应该可以工作:

import socket

server = #ServerName
serverPort = #Server Port number
channel = #ChannelName
botnick = #BotName
password = #Password (string)

def connect(channel, password): # This function is used on connect.
  ircsock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
  ircsock.connect ((server, serverPort))
  ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":Just testing .\n") # user authentication
  ircsock.send("NICK "+ botnick +"\n")
  ircsock.send("PRIVMSG" + " NICKSERV :identify " + password +"\n") #Problem Here
  ircsock.send("JOIN "+ channel +"\n")

connect(channel, password) #Join the channel and identify the nick using the functions we previously defined

【讨论】:

  • 我省略了那部分代码。我已经编辑了与套接字连接的帖子。不过还是谢谢你的帮助。
  • 好的,我不知道这一点,因为在原始帖子中您没有提到那部分代码。请尝试来自 sideshowbarker 的答案并告诉我们它是否有效?
  • 我很抱歉。已经试过了。不幸的是它失败了。代码运行无误,bot访问irc但不识别nick
  • 尝试对一些免费的 IRC 聊天服务器和频道使用相同的代码。可能是代码工作正常,但 IRC 服务器或频道设置阻止了机器人。只是猜测。
  • 看起来不是这样,因为机器人执行其他功能,如 ping 和简单的 hello 交互。无论如何我会尝试的。
猜你喜欢
  • 2014-06-12
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 2017-08-17
  • 2011-07-28
  • 2021-11-01
  • 2019-09-30
  • 1970-01-01
相关资源
最近更新 更多