Advertisement
triclops200

Untitled

Jan 13th, 2013
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import xchat, re, urllib, time, subprocess, sys, signal, os
  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",os.environ["HOME"]+"/.xchat2/std.scm","-c",t],
  24.                 stderr=subprocess.STDOUT
  25.                 )
  26.         except subprocess.CalledProcessError as e:
  27.             xchat.prnt(e.output)
  28.             output=""
  29.         finally:
  30.             signal.signal(signal.SIGALRM, old_handler)
  31.         signal.alarm(0)
  32.         for line in output.split("\n"):
  33.             if(line[:3] != ";;;"):
  34.                 xchat.command("say " + line)
  35.    
  36.  
  37. hook3 = xchat.hook_print("Your Message",guileCall)
  38. def cleanupGuile(word, word_eol, userdata):
  39.     xchat.unhook(hook3)
  40. xchat.hook_command("cguile",cleanupGuile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement