How to receive files with python IRC bot?

Viewed 801

I've created a semi-functional IRC bot in python from the following sample code:

import socket
import time
import random
import os

def stringToBytes(s):
    blit = ""
    for char in s:
        blit += char
    return bytes(blit, "UTF-8")

server = "irc.irchighway.net"  # settings
channel = "#ebooks"
botnick = "NoobBot"

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # defines the socket

irc.connect((server, 6667))  # connects to the server
irc.send(stringToBytes("USER " + botnick + " " + botnick + " " + botnick + " :This is a fun bot!\n"))  # user authentication
irc.send(stringToBytes("NICK " + botnick + "\n"))  # sets nick
irc.send(stringToBytes("PRIVMSG nickserv :iNOOPE\r\n"))  # auth
time.sleep(4)
irc.send(stringToBytes("JOIN " + channel + "\n"))  # join the channel
irc.send(stringToBytes("PRIVMSG #ebooks @search save the cat\r\n")) 

while 1:  # puts it in a loop
    text = irc.recv(2040)  # receive the text
    text2 = str(text)[2:]
    text3 = text2.split(":")
    print(text3)

Just as a test, what these does is search for the book "save the cat" in the ebooks channel. It works, and I get the following showing up in my received text log:

['', 'Search!Search@ihw-4q5hcb.dyn.suddenlink.net NOTICE NoobBot ', '\x031,9\x16\x02<>\x02\x16 Your search for "\x0312,9save the cat\x031,9" has been accepted. Searching...\r\n\''] ['', 'Search!Search@ihw-4q5hcb.dyn.suddenlink.net NOTICE NoobBot ', '\x031,9\x16\x02<>\x02\x16 Your search for "\x0312,9save the cat\x031,9" returned 55 matches. Sending results to you as\x0312 SearchBot_results_for_ save the cat.txt.zip\x031,9. Search took 0.33 seconds.\r\n\''] ['', 'Search!Search@ihw-4q5hcb.dyn.suddenlink.net NOTICE NoobBot ', 'DCC Send SearchBot_results_for_ save the cat.txt.zip (173.80.26.71)\r\n', 'Search!Search@ihw-4q5hcb.dyn.suddenlink.net PRIVMSG NoobBot ', "\x01DCC SEND SearchBot_results_for__save_the_cat.txt.zip 2907707975 3107 3966\x01\r\n'"]

If I were running this in mIRC, I would be able to click the link to download the file, however I don't see the link to the actual file anywhere in this text. I'm new to IRC bots, so an example would be helpful.

I basically am just trying to make my own small client in python so that I can input searches and the client will download the resulting search text file when it's sent.

Any help is really appreciated

1 Answers
Related