Making the PING-loop optional

master
Sean B. Palmer 2012-01-14 22:55:59 +00:00
parent 2575536078
commit 436d610ff4
2 changed files with 29 additions and 29 deletions

View File

@ -18,39 +18,39 @@ def setup(phenny):
try: refresh_delay = float(phenny.config.refresh_delay) try: refresh_delay = float(phenny.config.refresh_delay)
except: pass except: pass
def close(): def close():
print "Nobody PONGed our PING, restarting" print "Nobody PONGed our PING, restarting"
phenny.handle_close() phenny.handle_close()
def pingloop(): def pingloop():
timer = threading.Timer(refresh_delay, close, ()) timer = threading.Timer(refresh_delay, close, ())
phenny.data['startup.setup.timer'] = timer phenny.data['startup.setup.timer'] = timer
phenny.data['startup.setup.timer'].start() phenny.data['startup.setup.timer'].start()
# print "PING!" # print "PING!"
phenny.write(('PING', phenny.config.host)) phenny.write(('PING', phenny.config.host))
phenny.data['startup.setup.pingloop'] = pingloop phenny.data['startup.setup.pingloop'] = pingloop
def pong(phenny, input): def pong(phenny, input):
try: try:
# print "PONG!" # print "PONG!"
phenny.data['startup.setup.timer'].cancel() phenny.data['startup.setup.timer'].cancel()
time.sleep(refresh_delay + 60.0) time.sleep(refresh_delay + 60.0)
pingloop() pingloop()
except: pass except: pass
pong.event = 'PONG' pong.event = 'PONG'
pong.thread = True pong.thread = True
pong.rule = r'.*' pong.rule = r'.*'
phenny.variables['pong'] = pong phenny.variables['pong'] = pong
# Need to wrap handle_connect to start the loop. # Need to wrap handle_connect to start the loop.
inner_handle_connect = phenny.handle_connect inner_handle_connect = phenny.handle_connect
def outer_handle_connect(): def outer_handle_connect():
inner_handle_connect() inner_handle_connect()
if phenny.data.get('startup.setup.pingloop'): if phenny.data.get('startup.setup.pingloop'):
phenny.data['startup.setup.pingloop']() phenny.data['startup.setup.pingloop']()
phenny.handle_connect = outer_handle_connect phenny.handle_connect = outer_handle_connect
def startup(phenny, input): def startup(phenny, input):
if hasattr(phenny.config, 'serverpass'): if hasattr(phenny.config, 'serverpass'):

View File

@ -90,7 +90,7 @@ def tr2(phenny, input):
command = cmd command = cmd
phrase = command phrase = command
if (len(phrase) > 350) and (not context.admin): if (len(phrase) > 350) and (not input.admin):
return phenny.reply('Phrase must be under 350 characters.') return phenny.reply('Phrase must be under 350 characters.')
src, dest = args src, dest = args