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

import xchat, re

def BUGZILLA_URL(match):
  url , num = "http://bugzilla.mozilla.org/show_bug.cgi?id=" , match.group(1)
  
  return "bug  %s (\00311%s%s\017)" % ( num , url , num )

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_ALL
    
  else:
    return xchat.EAT_NONE
  
EVENTS = [
  "Channel Action",
  "Channel Action Hilight",
  "Channel Message",
  "Channel Msg Hilight"
]

for event in EVENTS:
  xchat.hook_print( event, echoBug, (event,) )
  
print "Bugzilla plugin loaded."
