fix clock and startup modules
parent
ee6ce7ba3e
commit
3d41e2f1d9
|
@ -281,7 +281,7 @@ tock.commands = ['tock']
|
|||
tock.priority = 'high'
|
||||
|
||||
def npl(phenny, input):
|
||||
"""Shows the time from NPL's SNTP server."""
|
||||
"""Shows the time from NPL's SNTP server."""
|
||||
# for server in ('ntp1.npl.co.uk', 'ntp2.npl.co.uk'):
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.sendto('\x1b' + 47 * '\0', ('ntp1.npl.co.uk', 123))
|
||||
|
@ -291,7 +291,7 @@ def npl(phenny, input):
|
|||
d = dec('0.0')
|
||||
for i in range(8):
|
||||
d += dec(buf[32 + i]) * dec(str(math.pow(2, (3 - i) * 8)))
|
||||
d -= dec(2208988800L)
|
||||
d -= dec(2208988800)
|
||||
a, b = str(d).split('.')
|
||||
f = '%Y-%m-%d %H:%M:%S'
|
||||
result = datetime.datetime.fromtimestamp(d).strftime(f) + '.' + b[:6]
|
||||
|
|
|
@ -10,47 +10,47 @@ http://inamidst.com/phenny/
|
|||
import threading, time
|
||||
|
||||
def setup(phenny):
|
||||
# by clsn
|
||||
phenny.data = {}
|
||||
refresh_delay = 300.0
|
||||
# by clsn
|
||||
phenny.data = {}
|
||||
refresh_delay = 300.0
|
||||
|
||||
if hasattr(phenny.config, 'refresh_delay'):
|
||||
try: refresh_delay = float(phenny.config.refresh_delay)
|
||||
except: pass
|
||||
if hasattr(phenny.config, 'refresh_delay'):
|
||||
try: refresh_delay = float(phenny.config.refresh_delay)
|
||||
except: pass
|
||||
|
||||
def close():
|
||||
print "Nobody PONGed our PING, restarting"
|
||||
phenny.handle_close()
|
||||
def close():
|
||||
print("Nobody PONGed our PING, restarting")
|
||||
phenny.handle_close()
|
||||
|
||||
def pingloop():
|
||||
timer = threading.Timer(refresh_delay, close, ())
|
||||
phenny.data['startup.setup.timer'] = timer
|
||||
phenny.data['startup.setup.timer'].start()
|
||||
# print "PING!"
|
||||
phenny.write(('PING', phenny.config.host))
|
||||
phenny.data['startup.setup.pingloop'] = pingloop
|
||||
def pingloop():
|
||||
timer = threading.Timer(refresh_delay, close, ())
|
||||
phenny.data['startup.setup.timer'] = timer
|
||||
phenny.data['startup.setup.timer'].start()
|
||||
# print "PING!"
|
||||
phenny.write(('PING', phenny.config.host))
|
||||
phenny.data['startup.setup.pingloop'] = pingloop
|
||||
|
||||
def pong(phenny, input):
|
||||
try:
|
||||
# print "PONG!"
|
||||
phenny.data['startup.setup.timer'].cancel()
|
||||
time.sleep(refresh_delay + 60.0)
|
||||
pingloop()
|
||||
except: pass
|
||||
pong.event = 'PONG'
|
||||
pong.thread = True
|
||||
pong.rule = r'.*'
|
||||
phenny.variables['pong'] = pong
|
||||
def pong(phenny, input):
|
||||
try:
|
||||
# print "PONG!"
|
||||
phenny.data['startup.setup.timer'].cancel()
|
||||
time.sleep(refresh_delay + 60.0)
|
||||
pingloop()
|
||||
except: pass
|
||||
pong.event = 'PONG'
|
||||
pong.thread = True
|
||||
pong.rule = r'.*'
|
||||
phenny.variables['pong'] = pong
|
||||
|
||||
# Need to wrap handle_connect to start the loop.
|
||||
inner_handle_connect = phenny.handle_connect
|
||||
# Need to wrap handle_connect to start the loop.
|
||||
inner_handle_connect = phenny.handle_connect
|
||||
|
||||
def outer_handle_connect():
|
||||
inner_handle_connect()
|
||||
if phenny.data.get('startup.setup.pingloop'):
|
||||
phenny.data['startup.setup.pingloop']()
|
||||
def outer_handle_connect():
|
||||
inner_handle_connect()
|
||||
if phenny.data.get('startup.setup.pingloop'):
|
||||
phenny.data['startup.setup.pingloop']()
|
||||
|
||||
phenny.handle_connect = outer_handle_connect
|
||||
phenny.handle_connect = outer_handle_connect
|
||||
|
||||
def startup(phenny, input):
|
||||
if hasattr(phenny.config, 'serverpass'):
|
||||
|
|
Loading…
Reference in New Issue