Advertisement
triclops200

Untitled

Jan 13th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import xchat, re, urllib, time, subprocess, sys, signal
  2. from subprocess import check_output
  3.  
  4. __module_name__="guileInterface"
  5. __module_version__="0.1"
  6. __module_description__ = "An interface to the guile program"
  7.  
  8. class TimeoutException(Exception):
  9.     pass
  10.  
  11.  
  12. def guileCall(word, word_eol, userdata):
  13.     def thandler(signum, frame):
  14.         raise TimeoutException()
  15.  
  16.     text = word[1].split()
  17.     if text[0] == "'s":
  18.         t = " ".join(text[1:])
  19.         old_handler = signal.signal(signal.SIGALRM, thandler)
  20.         signal.alarm(5)
  21.         try:
  22.             output = check_output(
  23.                 ["guile","-l","/home/jsvlrt/.xchat2/std.scm","-c",t],
  24.                 stderr=subprocess.STDOUT
  25.                 )
  26.         except subprocess.CalledProcessError as e:
  27.             output = e.output
  28.         finally:
  29.             signal.signal(signal.SIGALRM, old_handler)
  30.         signal.alarm(0)
  31.         for line in output.split("\n"):
  32.             if(line[:3] != ";;;"):
  33.                 xchat.command("say " + line)
  34.    
  35.  
  36. hook3 = xchat.hook_print("Your Message",guileCall)
  37. def cleanupGuile(word, word_eol, userdata):
  38.     xchat.unhook(hook3)
  39. xchat.hook_command("cguile",cleanupGuile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement