mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-12 05:02:33 +01:00
relay: (de)initialize channels using shared initialize/removechannel()
This commit is contained in:
parent
0dc0770d6d
commit
3c2d0dbe3f
@ -63,11 +63,18 @@ def loadDB():
|
|||||||
db = {}
|
db = {}
|
||||||
|
|
||||||
def exportDB(scheduler):
|
def exportDB(scheduler):
|
||||||
scheduler.enter(60, 1, exportDB, argument=(scheduler,))
|
scheduler.enter(30, 1, exportDB, argument=(scheduler,))
|
||||||
log.debug("Relay: exporting links database to %s", dbname)
|
log.debug("Relay: exporting links database to %s", dbname)
|
||||||
with open(dbname, 'wb') as f:
|
with open(dbname, 'wb') as f:
|
||||||
pickle.dump(db, f, protocol=4)
|
pickle.dump(db, f, protocol=4)
|
||||||
|
|
||||||
|
def initializechannel(irc, channel):
|
||||||
|
irc.proto.joinClient(irc, irc.pseudoclient.uid, channel)
|
||||||
|
|
||||||
|
def removechannel(irc, channel):
|
||||||
|
if channel not in map(str.lower, irc.serverdata['channels']):
|
||||||
|
irc.proto.partClient(irc, irc.pseudoclient.uid, channel)
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def create(irc, source, args):
|
def create(irc, source, args):
|
||||||
"""<channel>
|
"""<channel>
|
||||||
@ -88,7 +95,7 @@ def create(irc, source, args):
|
|||||||
utils.msg(irc, source, 'Error: you must be opered in order to complete this operation.')
|
utils.msg(irc, source, 'Error: you must be opered in order to complete this operation.')
|
||||||
return
|
return
|
||||||
db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(), 'blocked_nets': set()}
|
db[(irc.name, channel)] = {'claim': [irc.name], 'links': set(), 'blocked_nets': set()}
|
||||||
irc.proto.joinClient(irc, irc.pseudoclient.uid, channel)
|
initializechannel(irc, channel)
|
||||||
utils.msg(irc, source, 'Done.')
|
utils.msg(irc, source, 'Done.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -110,8 +117,7 @@ def destroy(irc, source, args):
|
|||||||
|
|
||||||
if (irc.name, channel) in db:
|
if (irc.name, channel) in db:
|
||||||
del db[(irc.name, channel)]
|
del db[(irc.name, channel)]
|
||||||
if channel not in map(str.lower, irc.serverdata['channels']):
|
removechannel(irc, channel)
|
||||||
irc.proto.partClient(irc, irc.pseudoclient.uid, channel)
|
|
||||||
utils.msg(irc, source, 'Done.')
|
utils.msg(irc, source, 'Done.')
|
||||||
else:
|
else:
|
||||||
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
||||||
@ -161,6 +167,7 @@ def link(irc, source, args):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
entry['links'].add((irc.name, localchan))
|
entry['links'].add((irc.name, localchan))
|
||||||
|
initializechannel(irc, localchan)
|
||||||
utils.msg(irc, source, 'Done.')
|
utils.msg(irc, source, 'Done.')
|
||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
@ -199,8 +206,10 @@ def delink(irc, source, args):
|
|||||||
for link in entry['links'].copy():
|
for link in entry['links'].copy():
|
||||||
if link[0] == remotenet:
|
if link[0] == remotenet:
|
||||||
entry['links'].remove(link)
|
entry['links'].remove(link)
|
||||||
|
removechannel(utils.networkobjects[remotenet], link[1])
|
||||||
else:
|
else:
|
||||||
entry['links'].remove((irc.name, channel))
|
entry['links'].remove((irc.name, channel))
|
||||||
|
removechannel(irc, channel)
|
||||||
utils.msg(irc, source, 'Done.')
|
utils.msg(irc, source, 'Done.')
|
||||||
|
|
||||||
def relay(homeirc, func, args):
|
def relay(homeirc, func, args):
|
||||||
@ -226,10 +235,12 @@ def main(irc):
|
|||||||
# execution, in order to get a repeating loop.
|
# execution, in order to get a repeating loop.
|
||||||
thread = threading.Thread(target=scheduler.run)
|
thread = threading.Thread(target=scheduler.run)
|
||||||
thread.start()
|
thread.start()
|
||||||
for chanpair in db:
|
for chanpair, entrydata in db.items():
|
||||||
network, channel = chanpair
|
network, channel = chanpair
|
||||||
ircobj = utils.networkobjects[network]
|
initializechannel(utils.networkobjects[network], channel)
|
||||||
ircobj.proto.joinClient(ircobj, irc.pseudoclient.uid, channel)
|
for link in entrydata['links']:
|
||||||
|
network, channel = link
|
||||||
|
initializechannel(utils.networkobjects[network], channel)
|
||||||
for network, ircobj in utils.networkobjects.items():
|
for network, ircobj in utils.networkobjects.items():
|
||||||
if ircobj.name != irc.name:
|
if ircobj.name != irc.name:
|
||||||
irc.proto.spawnServer(irc, '%s.relay' % network)
|
irc.proto.spawnServer(irc, '%s.relay' % network)
|
||||||
|
Loading…
Reference in New Issue
Block a user