I have an IRC bot that I wrote using the Twisted Python IRC protocols. I want to be able to run commands while still allowing the bot to listen and execute other commands simultaneously.
For example, let's say I have command that will print a large text file to a channel. If I wanted to stop the command while it was running by entering "!stop" into the channel, how could I accomplish this? Or let's say I want to do "!print largefile" in one channel and then go to a different channel and type "!print anotherfile" and have it print that file to the other channel before even finishing printing the first file.
I'm thinking that I would use threading for this purpose? I'm not quite sure.
EDIT (to clarify):
def privmsg(self, user, channel, msg):
nick = user.split('!', 1)[0]
parts = msg.split(' ')
trigger = parts[0]
data = parts[1:]
if trigger == '!printfile':
myfile = open('/files/%s' % data[0], 'r')
for line in myfile:
line = line.strip('/r/n')
self.msg(channel, line)
if trigger == '!stop':
CODE TO STOP THE CURRENTLY RUNNING PRINTFILE COMMAND
If I wanted to run !printfile
in two channels at once or stop the printfile command while it is running, what should I do?