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.

This entry was posted in Mozilla. Bookmark the permalink.

8 Responses to please help me edit this xchat python script

  1. [ct] says:

    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. rrr says:

    Your lambda seems to work for me (if I understand what you want correctly). Try using the string below as an alternative (for an explanation see the re module reference)

    BUGZILLA_URL = “bug \g(http://bugzilla.mozilla.org/show_bug.cgi?id=\g)”

  3. rrr says:

    Try again:

    Replace the square brackets below with less than/greater than:

    BUGZILLA_URL = “bug \g[1](http://bugzilla.mozilla.org/show_bug.cgi?id=\g[1])”

  4. Ali Ebrahim says:

    Hmm, this last suggestion actually crashes my XChat. Thanks for trying, though.

  5. Adam Roben says:

    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.

  6. [ct] says:

    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…

  7. Ali Ebrahim says:

    Thanks everyone. It was the recursion that was the problem. The script author actually provided me with an updated version with a fix, and what he did was just have it output something like:

    “bug  20000 (http://bugzilla.mozilla.org/show_bug.cgi?id=20000)”

    (with two spaces between bug and the number).

    You can find his updated version of the script here.

  8. Adam Roben says:

    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.