I'm trying to add to my python IRC bot a function that when I type "join #channel-name" on IRC, the bot will join the channel.
Here's my code:
line23:
line56:
I would like to know what should I put there so the bot can join the channel.
Any help would be very appreciated.
Here's my code:
import socket server = "irc.freenode.net" # IRC server channel = "#syrius-test" # Channel botnick = "syrius-bot" # Nickname of the bot master = "syrius_" # Nickname of the bot's master exitcode = "bye " + botnick #Text that we will use to make the bot quit def ircwrite(message): global ircsock ircsock.send(str(message).encode('latin-1', 'ignore')) def ping(): ircwrite("PONG :pingis\n") def sendmsg(chan , msg): ircwrite("PRIVMSG "+ chan +" :"+ msg +"\n") def joinchan(channel): ircsock.send(bytes("JOIN "+ channel + "\n")) def join(): ircsock.send(bytes("JOIN %s")) def hello(): ircwrite("PRIVMSG "+ channel +" :Hello!\n") def quitting(): ircwrite("PRIVMSG "+ channel +" :Okay boss, leaving now.\n") ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock.connect((server, 6667)) ircwrite("USER "+ botnick +" "+ botnick +" "+ botnick +" :IRC bot coded by syrius.\n") ircwrite("NICK "+ botnick +"\n") joinchan(channel) while 1: ircmsg = ircsock.recv(2048).decode() # receive data from the server ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks. print(ircmsg) # Here we print what's coming from the server name = ircmsg.split('!',1)[0][1:] # We split out the name if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello() hello() if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond! ping() if name.lower() == master.lower() and ircmsg.find(":quit " + botnick) != -1: quitting() ircsock.send(bytes("QUIT \n", "UTF-8")) if name.lower() == master.lower() and ircmsg.find(":join %s") != -1: join() main()Of course the following code is incorrect :
line23:
Quote:def join():
ircsock.send(bytes("JOIN %s"))
line56:
Quote:if name.lower() == master.lower() and ircmsg.find(":join %s") != -1:
join()
I would like to know what should I put there so the bot can join the channel.
Any help would be very appreciated.