Implement relay, channel and alias management
This commit is contained in:
@@ -23,6 +23,15 @@ def allRelaysActive(net):
|
||||
|
||||
|
||||
def getChanFree(net, new):
|
||||
"""
|
||||
Get a dictionary with the free channel spaces for
|
||||
each relay, and a channel limit.
|
||||
Example return:
|
||||
({1: 99}, 100)
|
||||
:param net: network
|
||||
:param new: list of newly provisioned relays to skip
|
||||
:return: ({relay: channel spaces}, channel limit)
|
||||
"""
|
||||
chanfree = {}
|
||||
chanlimits = set()
|
||||
for i in main.network[net].relays.keys():
|
||||
@@ -123,16 +132,38 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||
|
||||
def joinSingle(net, channel):
|
||||
if allRelaysActive(net):
|
||||
chanfree = getChanFree(net, [])
|
||||
print("chanfree", chanfree)
|
||||
for i in chanfree[0]:
|
||||
if chanfree[0][i] < 0:
|
||||
print("JOIN CHAN")
|
||||
# Use the algorithm to allocate our channel to a relay
|
||||
eca = emptyChanAllocate(net, [channel], None, [])
|
||||
if not len(eca.keys()) == 1:
|
||||
return False
|
||||
num = list(eca.keys())[0]
|
||||
name = f"{net}{num}"
|
||||
if name not in main.IRCPool:
|
||||
return False
|
||||
main.IRCPool[name].join(channel)
|
||||
return num
|
||||
else:
|
||||
error("All relays for %s are not active" % net)
|
||||
return False
|
||||
|
||||
|
||||
def partSingle(net, channel):
|
||||
"""
|
||||
Iterate over all the relays of net and part channels matching channel.
|
||||
:param net:
|
||||
:param channel:
|
||||
:return:
|
||||
"""
|
||||
parted = []
|
||||
for i in main.network[net].relays.keys():
|
||||
name = f"{net}{i}"
|
||||
if name in main.IRCPool.keys():
|
||||
if channel in main.IRCPool[name].channels:
|
||||
main.IRCPool[name].part(channel)
|
||||
parted.append(str(i))
|
||||
return parted
|
||||
|
||||
|
||||
def nukeNetwork(net):
|
||||
# purgeRecords(net)
|
||||
# p = main.g.pipeline()
|
||||
|
||||
@@ -6,6 +6,7 @@ from core.bot import IRCBotFactory
|
||||
from modules import alias
|
||||
from modules.chankeep import nukeNetwork
|
||||
from modules.regproc import needToRegister
|
||||
from utils.deliver_relay_commands import deliverRelayCommands
|
||||
from utils.get import getRelay
|
||||
from utils.logging.log import log
|
||||
|
||||
@@ -48,6 +49,42 @@ class Network:
|
||||
# self.start_bot(num)
|
||||
return num, main.alias[num]["nick"]
|
||||
|
||||
def enable_relay(self, num):
|
||||
"""
|
||||
Enable a relay for this network.
|
||||
Send a command to ZNC to connect.
|
||||
"""
|
||||
self.relays[num]["enabled"] = True
|
||||
user = main.alias[num]["nick"]
|
||||
commands = {"status": ["Connect"]}
|
||||
name = f"{self.net}{num}"
|
||||
deliverRelayCommands(num, commands, user=user + "/" + self.net)
|
||||
main.saveConf("network")
|
||||
if name not in main.IRCPool.keys():
|
||||
self.start_bot(num)
|
||||
|
||||
def disable_relay(self, num):
|
||||
"""
|
||||
Disable a relay for this network.
|
||||
Send a command to ZNC to disconnect.
|
||||
Stop trying to connect to the relay.
|
||||
"""
|
||||
self.relays[num]["enabled"] = False
|
||||
user = main.alias[num]["nick"]
|
||||
# relay = main.network[spl[1]].relays[relayNum]
|
||||
commands = {"status": ["Disconnect"]}
|
||||
name = f"{self.net}{num}"
|
||||
deliverRelayCommands(num, commands, user=user + "/" + self.net)
|
||||
main.saveConf("network")
|
||||
if name in main.ReactorPool.keys():
|
||||
if name in main.FactoryPool.keys():
|
||||
main.FactoryPool[name].stopTrying()
|
||||
main.ReactorPool[name].disconnect()
|
||||
if name in main.IRCPool.keys():
|
||||
del main.IRCPool[name]
|
||||
del main.ReactorPool[name]
|
||||
del main.FactoryPool[name]
|
||||
|
||||
def killAliases(self, aliasList):
|
||||
for i in aliasList:
|
||||
name = self.net + str(i)
|
||||
|
||||
Reference in New Issue
Block a user