#These 3 variables are required by the xchat module __module_name__ = "DeleteOnText" __module_version__ = "1.00" __module_description__ = "DeleteOnText" import xchat, os, re dot = {} def main(): global dot #Here are some of the main variables that you need to set #This is the path where all the other folders are dot["main_path"] = "/root/home/site/cache/" #This is the file that needs to be deleted dot["delete_file"] = "ignore-release" #This is the name of the bot thats announcing dot["irc-bot"] = "drftpd" #This is the channel the bot is in. dot["irc-chan"] = "#announce" #Here we compile the regex dot["regex"] = re.compile("COMPLETE in (.*) -> (.*)") #This is the function that gets called whenever theres a channel message def on_text(word, word_eol, userdata): # word and word_eol are lists of data, userdata is NoneType # Important things to note: # word[0] = The nick who said the message # word_eol[1] will be the text said in the channel. #Find where the message came from location = xchat.get_context() #Strip the nick of any color or special attributes nick = xchat.strip(word[0]) #This just makes sure there no extra bit in the text (like the + % & @ ~ etc) try: word_eol[2] chan_text = word_eol[1].replace(word_eol[2],'') except: chan_text = word_eol[1] #The channel text is now in a variable named chan_text # Is it the correct chan and username? if location.get_info('channel') == dot["irc-chan"] and nick == dot["irc-bot"]: #Now we match up the channel text with the regex #Example announce: # COMPLETE in 0DAY -> DirPath # text.group(1) would be 0DAY # text.group(2) would be DirPath text = dot["regex"].match(xchat.strip(chan_text)) #See if theres more than 1 dir in there dirtest = re.split('/', text.group(2)) try: dirtest[1] #If there is more than one dir in the announce, it will stop the script entirely and wait for the next channel message return except: pass #if the script gets this far it means that the announce is the right one, and we need to delete the file #here we remove any extra whitespace from the dir dir = text.group(2).replace(' ', '') #Here we make the full path to the ignore file fullpath = os.path.join(dot["main_path"], dir, dot["delete_file"]) #Here we print what we are doing print "Removing file: " + str(fullpath) #And here we remove the file os.remove(fullpath) #Then if you want the script to do anything else, you should put it below. #This will get things moving when the script is first loaded if (__name__ == "__main__"): main() #Prints a nice message when the script is loaded print "\0034 "+__module_name__+" "+__module_version__+" has been loaded\003" #This hooks all Channel Messages so that the on_text function will be called each time. xchat.hook_print('Channel Message', on_text) #Below is for printing a message when the script is unloaded def unload_cb(userdata): print "\0034 "+__module_name__+" "+__module_version__+" has been unloaded\003" xchat.hook_unload(unload_cb)