<s> import time <EOL> from . . const import * <EOL> from . import EventManager <EOL> from . . model import DataDict , Channel , User <EOL> from . . import settings <EOL> manager = EventManager ( ) <EOL> @ manager . hookmsg ( PING ) <EOL> def on_ping ( connection , sender , tag ) : <EOL> connection . pong ( tag ) <EOL> @ manager . hookmsg ( CONNECTED ) <EOL> def on_connected ( connection , sender ) : <EOL> connection . welcome = u'<STR_LIT>' <EOL> connection . identifier = u'<STR_LIT>' <EOL> connection . loaded = False <EOL> connection . channels = DataDict ( ) <EOL> @ manager . hookmsg ( RPL_WELCOME ) <EOL> def on_welcome ( connection , * args ) : <EOL> welcome = args [ - <NUM_LIT:1> ] <EOL> connection . identifier = welcome . rsplit ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> connection . enqueue ( LOADED ) <EOL> @ manager . hookmsg ( JOIN ) <EOL> def on_join ( connection , sender , channel ) : <EOL> if not channel in connection . channels : <EOL> connection . channels . add ( Channel ( channel ) ) <EOL> @ manager . hookmsg ( ERROR ) <EOL> def on_error ( connection , * args ) : <EOL> if connection . quitting : <EOL> connection . disconnect ( ) <EOL> return <EOL> if connection . settings . autoreconnect : <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> connection . reconnect ( ) <EOL> else : <EOL> connection . disconnect ( ) </s>
