mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-18 08:02:51 +01:00
relay: fix bugs with removing nonexistant channels in DELINK, and linking a channel multiple times in LINK
This commit is contained in:
parent
1cbcec1001
commit
310a9201e2
@ -327,11 +327,8 @@ def link(irc, source, args):
|
||||
if remotenet not in utils.networkobjects:
|
||||
utils.msg(irc, source, 'Error: no network named %r exists.' % remotenet)
|
||||
return
|
||||
if (irc.name, localchan) in db:
|
||||
utils.msg(irc, source, 'Error: channel %r is already part of a relay.' % localchan)
|
||||
return
|
||||
for dbentry in db.values():
|
||||
if (irc.name, localchan) in dbentry['links']:
|
||||
localentry = findRelay((irc.name, localchan))
|
||||
if localentry:
|
||||
utils.msg(irc, source, 'Error: channel %r is already part of a relay.' % localchan)
|
||||
return
|
||||
try:
|
||||
@ -340,6 +337,12 @@ def link(irc, source, args):
|
||||
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
|
||||
return
|
||||
else:
|
||||
for link in entry['links']:
|
||||
if link[0] == irc.name:
|
||||
utils.msg(irc, source, "Error: remote channel '%s%s' is already"
|
||||
" linked here as %r." % (remotenet,
|
||||
channel, link[1]))
|
||||
return
|
||||
entry['links'].add((irc.name, localchan))
|
||||
initializeChannel(irc, localchan)
|
||||
utils.msg(irc, source, 'Done.')
|
||||
@ -367,11 +370,9 @@ def delink(irc, source, args):
|
||||
if not utils.isChannel(channel):
|
||||
utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
|
||||
return
|
||||
for dbentry in db.values():
|
||||
if (irc.name, channel) in dbentry['links']:
|
||||
entry = dbentry
|
||||
break
|
||||
if (irc.name, channel) in db: # We own this channel
|
||||
entry = findRelay((irc.name, channel))
|
||||
if entry:
|
||||
if entry[0] == irc.name: # We own this channel.
|
||||
if remotenet is None:
|
||||
utils.msg(irc, source, "Error: you must select a network to delink, or use the 'destroy' command no remove this relay entirely.")
|
||||
return
|
||||
@ -382,9 +383,11 @@ def delink(irc, source, args):
|
||||
entry['links'].remove(link)
|
||||
removeChannel(utils.networkobjects[remotenet], link[1])
|
||||
else:
|
||||
entry['links'].remove((irc.name, channel))
|
||||
db[entry]['links'].remove((irc.name, channel))
|
||||
removeChannel(irc, channel)
|
||||
utils.msg(irc, source, 'Done.')
|
||||
else:
|
||||
utils.msg(irc, source, 'Error: no such relay %r.' % channel)
|
||||
|
||||
def initializeAll(irc):
|
||||
utils.started.wait()
|
||||
|
Loading…
Reference in New Issue
Block a user