#! /usr/bin/env python __module_name__ = "welcome back!" __module_version__ = "0.1" __module_description__ = "WB script" import xchat from os.path import exists,expanduser from random import randint import string from urllib import unquote filename=expanduser("~") + "/.welcomes" def show_wb(word, word_eol, userdata): file=open(filename, "r") file.seek(0) lines=file.readlines() file.close selected=[] nick = word[0][1:] nick = nick[:nick.find("!")] for line in lines: if line.startswith(nick): selected.append(line[len(nick)+1:]) if len(selected) == 0: return xchat.EAT_NONE index=randint(0, len(selected)-1) xchat.command("msg " + word[2][1:] + " WB -" + nick + " (" + str(index + 1) + "/" + str(len(selected)) + ")- " + selected[index]) return xchat.EAT_NONE def add_wb(word, word_eol, userdata): if len(word) < 3: print "Insufficient number of parameters!" return xchat.EAT_ALL if exists(filename): file=open(filename, "a") else: file=open(filename, "wt") file.write(word[1] + "!" + word_eol[2] + "\n") print "Quote added for " + word[1] + ": " + word_eol[2] file.close return xchat.EAT_ALL xchat.hook_command("test", show_wb) xchat.hook_command("addquote", add_wb) xchat.hook_server("JOIN", show_wb) print 'WB loaded'