38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import main
|
|
from modules import chankeep
|
|
|
|
|
|
def get_first_relay(net):
|
|
"""
|
|
Get the first relay in the network.
|
|
:param net: the network
|
|
:param num: number or relay
|
|
:return: IRCPool instance for the IRC bot
|
|
"""
|
|
cur_relay = 0
|
|
max_relay = len(main.network[net].relays.keys()) + 1
|
|
activeRelays = chankeep.getActiveRelays(net)
|
|
while cur_relay != max_relay:
|
|
cur_relay += 1
|
|
if cur_relay not in activeRelays:
|
|
continue
|
|
name = net + str(cur_relay)
|
|
if name in main.IRCPool.keys():
|
|
return main.IRCPool[name]
|
|
return None
|
|
|
|
|
|
def is_first_relay(net, num):
|
|
"""
|
|
Determine if we are the first relay for the network.
|
|
:param net: the network
|
|
:param num: number or relay
|
|
:return: True if we are the first relay, False otherwise
|
|
"""
|
|
cur_relay = 0
|
|
max_relay = len(main.network[net].relays.keys())
|
|
while cur_relay > max_relay:
|
|
name = net + str(cur_relay)
|
|
if name in main.IRCPool.keys():
|
|
return cur_relay == num
|