Advertisement
triclops200

GuilePlugin

Jan 9th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 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","./std.scm","-c",t],
  24.                 )
  25.         except Exception as e:
  26.             output = "error"
  27.         finally:
  28.             signal.signal(signal.SIGALRM, old_handler)
  29.         signal.alarm(0)
  30.         for line in output.split("\n"):
  31.             xchat.command("say " + line)
  32.    
  33.  
  34. hook3 = xchat.hook_print("Your Message",guileCall)
  35. def cleanupGuile(word, word_eol, userdata):
  36.     xchat.unhook(hook3)
  37. xchat.hook_command("cguile",cleanupGuile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement