Guest User

Untitled

a guest
Nov 22nd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1. #!/usr/bin/python
  2. import irclib
  3. irclib.DEBUG = True
  4. import time
  5. import re
  6. import search
  7.  
  8.  
  9. network = '' # irc.freenode.net for example
  10. port = # default is 6667
  11. nick = ''
  12. pw = ''
  13. name = ''
  14. chanToSay = "#Ghost" # Default chan to stay in
  15.  
  16. TRIGGERS = ['!g ', '!w ', '!tv ', '!tss ', '!user ', '!last5 ', '!catte',
  17. '']
  18.  
  19. class Ghost(irclib.SimpleIRCClient):
  20. """Ghost class extends SimpleIRCClient."""
  21.  
  22. def start(self, use_ssl=False):
  23. """start is a wrapper for self's irclib.ServerConnection.connect()
  24. The only parameter it accepts is a bool for use_ssl. The rest of
  25. the parameters should come from the config parser."""
  26. self.connect(network, port, nick, password=pw, username=name,
  27. ssl=use_ssl)
  28.  
  29. def say(self, thingToSay):
  30. """thingToSay should be a string for now"""
  31. self.connection.privmsg(chanToSay, thingToSay)
  32.  
  33. def join(self, chan):
  34. """join chan. chan should be string"""
  35. self.connection.join(chan)
  36. def nick(self, nick):
  37. """change nickname to nick. nick should be string"""
  38. self.connection.nick(nick)
  39.  
  40. def disconnect(self, arg="Exeunt Ghost"):
  41. """disconnect ghost"""
  42. self.connection.disconnect(arg)
  43.  
  44. def on_pubmsg(self, connection, event):
  45. msg = ''.join(event.arguments())
  46. trigs = [re.compile('^' + trig) for trig in TRIGGERS]
  47. for trig in trigs:
  48. if trig.match(msg):
  49. if '!g ' in msg:
  50. self.say(search.g(msg))
  51. else:
  52. self.say("Got it.")
  53.  
  54.  
  55.  
  56. Zombie = Ghost()
  57. Zombie.start(use_ssl=True)
  58. nick = 'Zombie'
  59. Zombie.nick(nick)
  60. time.sleep(10)
  61. Zombie.join(chanToSay)
  62. Zombie.ircobj.process_forever()
Add Comment
Please, Sign In to add comment