Created
July 6, 2012 20:30
-
-
Save epequeno/3062595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import irclib | |
irclib.DEBUG = True | |
import time | |
import re | |
import search | |
network = '' # irc.freenode.net for example | |
port = # default is 6667 | |
nick = '' | |
pw = '' | |
name = '' | |
chanToSay = "#Ghost" # Default chan to stay in | |
TRIGGERS = ['!g ', '!w ', '!tv ', '!tss ', '!user ', '!last5 ', '!catte', | |
''] | |
class Ghost(irclib.SimpleIRCClient): | |
"""Ghost class extends SimpleIRCClient.""" | |
def start(self, use_ssl=False): | |
"""start is a wrapper for self's irclib.ServerConnection.connect() | |
The only parameter it accepts is a bool for use_ssl. The rest of | |
the parameters should come from the config parser.""" | |
self.connect(network, port, nick, password=pw, username=name, | |
ssl=use_ssl) | |
def say(self, thingToSay): | |
"""thingToSay should be a string for now""" | |
self.connection.privmsg(chanToSay, thingToSay) | |
def join(self, chan): | |
"""join chan. chan should be string""" | |
self.connection.join(chan) | |
def nick(self, nick): | |
"""change nickname to nick. nick should be string""" | |
self.connection.nick(nick) | |
def disconnect(self, arg="Exeunt Ghost"): | |
"""disconnect ghost""" | |
self.connection.disconnect(arg) | |
def on_pubmsg(self, connection, event): | |
msg = ''.join(event.arguments()) | |
trigs = [re.compile('^' + trig) for trig in TRIGGERS] | |
for trig in trigs: | |
if trig.match(msg): | |
if '!g ' in msg: | |
self.say(search.g(msg)) | |
else: | |
self.say("Got it.") | |
Zombie = Ghost() | |
Zombie.start(use_ssl=True) | |
nick = 'Zombie' | |
Zombie.nick(nick) | |
time.sleep(10) | |
Zombie.join(chanToSay) | |
Zombie.ircobj.process_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment