minetestbot-modules/startup.py

70 lines
1.9 KiB
Python
Raw Permalink Normal View History

2013-01-07 10:00:44 -08:00
#!/usr/bin/env python
"""
startup.py - Phenny Startup Module
Copyright 2008, Sean B. Palmer, inamidst.com
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import threading, time
2014-07-20 07:13:59 -07:00
def setup(phenny):
2013-05-09 12:16:00 -07:00
print("Setting up phenny")
2013-01-07 10:00:44 -08:00
# by clsn
phenny.data = {}
refresh_delay = 300.0
if hasattr(phenny.config, 'refresh_delay'):
try: refresh_delay = float(phenny.config.refresh_delay)
except: pass
def close():
2014-07-20 07:13:59 -07:00
print("Nobody PONGed our PING, restarting")
2013-01-07 10:00:44 -08:00
phenny.handle_close()
2014-07-20 07:13:59 -07:00
2013-01-07 10:00:44 -08:00
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
2014-07-20 07:13:59 -07:00
def startup(phenny, input):
2013-01-07 10:00:44 -08:00
import time
2013-05-09 12:16:00 -07:00
# Start the ping loop. Has to be done after USER on e.g. quakenet
if phenny.data.get('startup.setup.pingloop'):
phenny.data['startup.setup.pingloop']()
2014-07-20 07:13:59 -07:00
if hasattr(phenny.config, 'serverpass'):
2013-01-07 10:00:44 -08:00
phenny.write(('PASS', phenny.config.serverpass))
2014-07-20 07:13:59 -07:00
if hasattr(phenny.config, 'password'):
2013-01-07 10:00:44 -08:00
phenny.msg('NickServ', 'IDENTIFY %s' % phenny.config.password)
time.sleep(5)
# Cf. http://swhack.com/logs/2005-12-05#T19-32-36
2014-07-20 07:13:59 -07:00
for channel in phenny.channels:
2013-01-07 10:00:44 -08:00
phenny.write(('JOIN', channel))
time.sleep(0.5)
startup.rule = r'(.*)'
startup.event = '251'
startup.priority = 'low'
2014-07-20 07:13:59 -07:00
if __name__ == '__main__':
print(__doc__.strip())