pesterchum/oyoyo/examplebot.py
karxi 5d839aae47 Revert "python 2 to 3 first shot"
This reverts commit 7bc57b8b7d.

Practically speaking, this reverts the Python 3 changes, since they're
broken.
2016-11-13 01:12:58 -05:00

46 lines
973 B
Python

#!/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()
print('Saying, "%s"' % to_say)
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:
conn.next() ## python 2
# next(conn) ## python 3
if __name__ == '__main__':
main()