pesterchum/oyoyo/examplebot.py

46 lines
974 B
Python
Raw Normal View History

2011-01-21 05:18:22 -05:00
#!/usr/bin/python
"""Example bot for oyoyo that responds to !say"""
import logging
import re
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers
HOST = 'irc.freenode.net'
PORT = 6667
NICK = 'oyoyo-example'
CHANNEL = '#oyoyo-test'
class MyHandler(DefaultCommandHandler):
def privmsg(self, nick, chan, msg):
msg = msg.decode()
match = re.match('\!say (.*)', msg)
if match:
to_say = match.group(1).strip()
2014-10-29 03:57:49 -04:00
print(('Saying, "%s"' % to_say))
2011-01-21 05:18:22 -05:00
helpers.msg(self.client, chan, to_say)
def connect_cb(cli):
helpers.join(cli, CHANNEL)
def main():
logging.basicConfig(level=logging.DEBUG)
cli = IRCClient(MyHandler, host=HOST, port=PORT, nick=NICK,
connect_cb=connect_cb)
conn = cli.connect()
while True:
2014-10-29 03:57:49 -04:00
next(conn) ## python 2
2011-01-21 05:18:22 -05:00
# next(conn) ## python 3
if __name__ == '__main__':
main()