please help me edit this xchat python script

The XChat script below catches instances of “bug 20000” (for example) and replaces them with “http://bugzilla.mozilla.org/show_bug.cgi?id=20000”. __module_name__ = “bugzilla” __module_version__ = “0.1” __module_description__ = “Bugzilla Url Converter” __module_author__ = “Marc Liddell” BUGZILLA_URL = lambda num: “http://bugzilla.mozilla.org/show_bug.cgi?id=” + num.group(1) import xchat, re def echoBug(word, word_eol, userdata):   subs = re.sub( ‘[Bb][Uu][Gg]\s*([0-9]+)’, BUGZILLA_URL, word[1] )   if subs != … Continue reading “please help me edit this xchat python script”

The XChat script below catches instances of “bug 20000” (for example) and replaces them with “http://bugzilla.mozilla.org/show_bug.cgi?id=20000”.

__module_name__ = "bugzilla"
__module_version__ = "0.1"
__module_description__ = "Bugzilla Url Converter"
__module_author__ = "Marc Liddell"

BUGZILLA_URL = lambda num: "http://bugzilla.mozilla.org/show_bug.cgi?id=" + num.group(1)

import xchat, re

def echoBug(word, word_eol, userdata):
  subs = re.sub( '[Bb][Uu][Gg]\s*([0-9]+)', BUGZILLA_URL, word[1] )

  if subs != word[1]:
    xchat.emit_print(userdata[0], word[0], subs )
    return xchat.EAT_XCHAT

  else:
    return xchat.EAT_NONE

EVENTS = [
  ("Channel Action", 1),
  ("Channel Action Hilight", 1),
  ("Channel Message", 1),
  ("Channel Msg Hilight", 1)
]

for event in EVENTS:
  xchat.hook_print( event[0], echoBug, event)

I’d really like it to display “bug 20000 (http://bugzilla.mozilla.org/show_bug.cgi?id=20000)” instead. Can anyone help me out here? I’ve tried to change the BUGZILLA_URL line to

BUGZILLA_URL = lambda num: "bug " + num.group(1) + " (http://bugzilla.mozilla.org/show_bug.cgi?id=" + num.group(1) + ")"

and many, many other variations, but all are a no-go. Can someone help me make this script do what I want? 🙂 I’ve tried Googling for answers with no success. I’m sure its a minor detail I’m missing, but I’ve spent a long time on it now and can’t figure it out.

Any help would be sincerely appreciated.

UPDATE: I’ve posted a fixed, updated script here (see also the comments section). Note that it requires a working Python plugin for XChat.

8 thoughts on “please help me edit this xchat python script”

  1. Unfortunately, I can’t help you out with the Python thingy, but after you pointed me to the Perl version, I wrote my own version which just catches anything that matches Bug (numbers) and gives you the URL. It’s all _I_ was really looking for. Perhaps you’ll find it useful: http://users.telenet.be/ct/bugzilla-xchat.pl

  2. The problem seems to be (for me at least) that when you output “bug 20000 (http://bugzilla.mozilla.org/show_bug.cgi?id=20000)” this string gets run through all of your scripts again. So since the replacement string contains “bug 20000” the script gets called again, and again, and again, putting XChat in an infinite loop and causing a segfault. I don’t know if there’s a way to tell XChat not to run scripts on the output string (and you probably wouldn’t want to since then you couldn’t click on the URL), but a solution is to change BUGZILLA_URL to this:

    BUGZILLA_URL = lambda num: “bugg ” + num.group(1) + ” (http://bugzilla.mozilla.org/show_bug.cgi?id=” + num.group(1) + “)”

    Notice the “bugg” rather than “bug” Now you get “bugg 20000 ” so the script is not triggered again. Of course, you can change this however you want (“bug! 20000” or “bug…20000”, or anything that doesn’t match your regexp). Hope this helps.

  3. Perhaps you could put formatting around it (e.g. put the bug text in bold) and then match every bug link that isn’t preceded by a bold formatting character…

  4. The only problem with that updated script is that it doesn’t accept “bug 20000” (with two spaces) as a bug reference. When chatting it’s very easy to insert extra spaces, but the new script will only match one space (unlike the original which accepted any number of spaces, including 0). But it does fix the recursion problem, so I guess that’s a step forward.

Comments are closed.