__module_name__ = "xchat-give-talk" __module_version__ = "1.0" __module_description__ = "Walk through a text file line by line with the /next command" import xchat TALKS = {} TALK_POINTER = {} TALK_NAMES = {} def talkload(words, word_eol, userdata): fn = " ".join(words[1:]) channel = xchat.get_info("channel") try: fp = open(fn) except IndexError: xchat.prnt("Couldn't load talk '%s'" % fn) return TALKS[channel] = [x for x in fp.read().split("\n") if x] TALK_POINTER[channel] = 0 TALK_NAMES[channel] = fn fp.close() xchat.prnt("Talk %s loaded. Use /talknext to start displaying it and /talkinfo for information about it." % fn) def next(words, word_eol, userdata): channel = xchat.get_info("channel") if TALK_POINTER[channel] >= len(TALKS[channel]): xchat.prnt("No next line; talk is finished") return xchat.command("say " + TALKS[channel][TALK_POINTER[channel]]) TALK_POINTER[channel] += 1 def info(words, word_eof, userdata): channel = xchat.get_info("channel") xchat.prnt("Current talk for %s: %s" % (channel, TALK_NAMES[channel])) if TALK_POINTER[channel] == 0: xchat.prnt("Have not started displaying this talk yet") else: xchat.prnt("Last line displayed: %s" % TALKS[channel][TALK_POINTER[channel]-1]) if TALK_POINTER[channel] == len(TALKS[channel]): xchat.prnt("This talk is finished") else: xchat.prnt("Next line to be displayed: %s" % TALKS[channel][TALK_POINTER[channel]]) xchat.prnt("Currently on line %s out of %s" % (TALK_POINTER[channel], len(TALKS[channel]))) xchat.hook_command("talkload", talkload, help="/talkload ") xchat.hook_command("talknext", next, help="/talknext - shows the next line in the current talk") xchat.hook_command("talkinfo", info, help="/talkinfo - shows info about the current talk") xchat.prnt("Ready to load talks.") xchat.prnt("Use /talkload to load a talk for this channel")