Provide dedicated methods for protocol messages

This commit is contained in:
Robin Richtsfeld
2018-03-14 18:31:10 +01:00
parent 5b7a5981f1
commit bc5be32060
6 changed files with 105 additions and 42 deletions

View File

@@ -13,9 +13,7 @@ def join(phenny, input):
if input.sender.startswith('#'): return
if input.admin:
channel, key = input.group(1), input.group(2)
if not key:
phenny.write(['JOIN'], channel)
else: phenny.write(['JOIN', channel, key])
phenny.proto.join(channel, key)
join.rule = r'\.join (#\S+)(?: *(\S+))?'
join.priority = 'low'
join.example = '.join #example or .join #example key'
@@ -24,7 +22,7 @@ def autojoin(phenny, input):
"""Join the specified channel when invited by an admin."""
if input.admin:
channel = input.group(1)
phenny.write(['JOIN'], channel)
phenny.proto.join(channel)
autojoin.event = 'INVITE'
autojoin.rule = r'(.*)'
@@ -33,7 +31,7 @@ def part(phenny, input):
# Can only be done in privmsg by an admin
if input.sender.startswith('#'): return
if input.admin:
phenny.write(['PART'], input.group(2))
phenny.proto.part(input.group(2))
part.rule = (['part'], r'(#\S+)')
part.priority = 'low'
part.example = '.part #example'
@@ -43,7 +41,7 @@ def quit(phenny, input):
# Can only be done in privmsg by the owner
if input.sender.startswith('#'): return
if input.owner:
phenny.write(['QUIT'])
phenny.proto.quit()
__import__('os')._exit(0)
quit.commands = ['quit']
quit.priority = 'low'

View File

@@ -27,13 +27,11 @@ def setup(phenny):
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.proto.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()
@@ -50,16 +48,16 @@ def startup(phenny, input):
if phenny.data.get('startup.setup.pingloop'):
phenny.data['startup.setup.pingloop']()
if hasattr(phenny.config, 'serverpass'):
phenny.write(('PASS', phenny.config.serverpass))
if hasattr(phenny.config, 'serverpass'):
phenny.proto.pass_(phenny.config.serverpass)
if hasattr(phenny.config, 'password'):
phenny.msg('NickServ', 'IDENTIFY %s' % phenny.config.password)
time.sleep(5)
# Cf. http://swhack.com/logs/2005-12-05#T19-32-36
for channel in phenny.channels:
phenny.write(('JOIN', channel))
for channel in phenny.channels:
phenny.proto.join(channel)
time.sleep(0.5)
startup.rule = r'(.*)'
startup.event = '251'