I created a bot which connect to the chan through socket like this
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((network,port))
irc = ssl.wrap_socket(socket)
Then i send some message when some actions are triggered, this works quite well but there is one messsage which is truncated, and my script don't return any error. Here is the code of this message :
def GimmeUrlInfos(channel,message):
link = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message)
response = urllib2.urlopen(link[0])
html = BeautifulSoup(response.read())
urlTitle = html.find('title')
irc.send("PRIVMSG %s Link infos:" % (channel) + urlTitle.contents[0] + "\r\n" )
The script look in the message if there is a link inside, if yes beautifulSoup get the title of the HTML page. So it's returns something like: Link infos: THis is the Title of the Webpage you give in your message
.
But it only returns
Link
at the channel. Is there some limitations or something ?
Here's my next guess, now that you've given us a little more information:
Your string looks like this:
PRIVMSG #mychannel Link infos: Title of Page\r\n
In IRC, arguments are split on spaces, except that an argument that starts with a colon can include spaces, and runs to the end of the line. So, your target is #mychannel
, your message is Link
, and the whole rest of the line is a bunch of extra arguments that are ignored.
To fix this, you want to send:
PRIVMSG #mychannel :Link infos: Title of Page\r\n
So, change your code like this:
irc.send("PRIVMSG %s :Link infos:" % (channel) + urlTitle.contents[0] + "\r\n" )
For more details on how messages are formatted in RFC, and on the PRIVMSG
command, see 2.3.1 Message format in 'pseudo' BNF and 4.4.1 Private messages in RFC 1459.