def make_app(): """ main entry point """ print "make_app()" import logging import sys from oyoyo_bot import db global app global config config = make_config() logging.basicConfig(level=getattr(logging, config['logging']['level']), format='%(asctime)s %(levelname)s %(message)s', filename=config['logging']['filename'], filemode=config['logging']['filemode']) db.engine = db.create_engine(config['database']['uri'], echo=config['database'].as_bool('echo')) db.Session.configure(bind=db.engine) db.session = db.Session() app = IRCApp() def serverOrDefault(server, key): try: return config[server][key] except KeyError: return config['server default'][key] args = [a for a in config['auth']['args'].strip().split(' ') if a] auth = loadAuthPlugin(config['auth']['plugin'], args) for key in config.iterkeys(): if not key.startswith('server ') or key == 'server default': continue server = key.split(' ', 1)[1] rooms = serverOrDefault(key, 'rooms').split(' ') identify = serverOrDefault(key, 'identify') def connect_cb(c): if identify: helpers.ns(c, "IDENTIFY", identify) for room in rooms: helpers.join(c, "#"+room) cli = IRCClient( nick=serverOrDefault(key, 'nick'), realname=serverOrDefault(key, 'realname'), host=server, port=int(serverOrDefault(key, 'port')), connect_cb=connect_cb) cli.command_handler = OyoyoBotCommandHandler( cli, BotCommands(cli), auth) app.addClient(cli, autoreconnect=True) db.meta.create_all(db.engine) extendConfig('oyoyo_bot.config') config.filename = 'lastrun.ini' config.write() # to just write a config if '-c' in sys.argv: return app.run() print "done."
def chanTopic(self, chan, topic): '''Update Chan topic''' newTopic = str(topic) # Split the new topic into segments newSegments = [item.strip() for item in newTopic.split('-')] # Fetch old topic segments, if any exist try: f = open('%s.txt' % chan, 'r') oldSegments = [item.strip() for item in f.readlines()] f.close() except IOError: oldSegments = [] # Save and tweet new segments for newSegment in newSegments: if newSegment not in oldSegments: f = open('%s.txt' % chan, 'a') f.write(newSegment + '\n') f.close() api['Channel'].PostUpdate(newSegment) cli = IRCClient(MyHandler, host="irc.server.org", port=6667, nick="TwitterBot") cli.blocking = True app = IRCApp() app.addClient(cli) app.run()