2008-02-21 07:06:33 -05: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/
|
|
|
|
"""
|
|
|
|
|
2012-01-12 09:21:49 -05:00
|
|
|
import threading, time
|
|
|
|
|
|
|
|
def setup(phenny):
|
2013-03-21 08:04:14 -04:00
|
|
|
print("Setting up phenny")
|
2012-02-10 19:10:34 -05:00
|
|
|
# by clsn
|
|
|
|
phenny.data = {}
|
|
|
|
refresh_delay = 300.0
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2012-02-10 19:10:34 -05:00
|
|
|
if hasattr(phenny.config, 'refresh_delay'):
|
|
|
|
try: refresh_delay = float(phenny.config.refresh_delay)
|
|
|
|
except: pass
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2012-02-10 19:10:34 -05:00
|
|
|
def close():
|
|
|
|
print("Nobody PONGed our PING, restarting")
|
|
|
|
phenny.handle_close()
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2012-02-10 19:10:34 -05:00
|
|
|
def pingloop():
|
|
|
|
timer = threading.Timer(refresh_delay, close, ())
|
|
|
|
phenny.data['startup.setup.timer'] = timer
|
|
|
|
phenny.data['startup.setup.timer'].start()
|
2018-03-14 13:31:10 -04:00
|
|
|
phenny.proto.ping(phenny.config.host)
|
2012-02-10 19:10:34 -05:00
|
|
|
phenny.data['startup.setup.pingloop'] = pingloop
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2012-02-10 19:10:34 -05:00
|
|
|
def pong(phenny, input):
|
|
|
|
try:
|
|
|
|
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
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2013-03-21 08:04:14 -04:00
|
|
|
def startup(phenny, input):
|
|
|
|
import time
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2013-03-21 08:04:14 -04: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']()
|
2012-01-12 09:21:49 -05:00
|
|
|
|
2018-03-14 13:31:10 -04:00
|
|
|
if hasattr(phenny.config, 'serverpass'):
|
|
|
|
phenny.proto.pass_(phenny.config.serverpass)
|
2008-03-08 06:35:25 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
if hasattr(phenny.config, 'password'):
|
|
|
|
phenny.msg('NickServ', 'IDENTIFY %s' % phenny.config.password)
|
2012-02-17 22:10:05 -05:00
|
|
|
time.sleep(5)
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:09:34 -05:00
|
|
|
# Cf. http://swhack.com/logs/2005-12-05#T19-32-36
|
2018-03-14 13:31:10 -04:00
|
|
|
for channel in phenny.channels:
|
|
|
|
phenny.proto.join(channel)
|
2012-02-17 22:10:05 -05:00
|
|
|
time.sleep(0.5)
|
2008-02-21 07:06:33 -05:00
|
|
|
startup.rule = r'(.*)'
|
|
|
|
startup.event = '251'
|
|
|
|
startup.priority = 'low'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-01-03 14:09:34 -05:00
|
|
|
print(__doc__.strip())
|