I've searched extensively on this and only came up with bot specific clients. I know they're basically the same, but for what I want to do I just can't figure it out.
I am trying to program a python client, that is pure and simple on it's face. For example when run from the command line it will immediately connect invisibly and then print "say: " after it has established the connection. (username, server, etc. are already set) It will wait until the user has pressed -return/enter- and then it will send the message and then retrieve the messages that it has been logging to an array and print the last 8 lines/array values.
So the user will only see the messages on the channel, and be able to send messages. My issue is figuring out how to strip everything but the messages. I'm so sorry if I seem like I'm wanting someone to do this for me. I've looked and looked but I can't figure it out. Do I have to use a IRC module? I'm pretty sure that I'll end up using regex somehow, but I'm stumped. Thanks guys for reading my silly question!
import sys
import socket
import string
HOST="irc.freenode.net"
PORT=6667
NICK="MauBot"
IDENT="maubot"
REALNAME="MauritsBot"
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))
while 1:
readbuffer=readbuffer+s.recv(1024)
temp=string.split(readbuffer, "\n")
readbuffer=temp.pop( )
for line in temp:
line=string.rstrip(line)
line=string.split(line)
if(line[0]=="PING"):
s.send("PONG %s\r\n" % line[1])
You can connect to an IRC server using Telnet
.
There are libraries in Python to accomplish this.
See these links for more information:
Once you have connected to the IRC server, you can:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.