Reformat legacy project
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from copy import deepcopy
|
||||
from math import ceil
|
||||
|
||||
from twisted.internet.threads import deferToThread
|
||||
|
||||
import main
|
||||
from modules import helpers
|
||||
from twisted.internet.threads import deferToThread
|
||||
from utils.logging.debug import debug, trace
|
||||
from utils.logging.log import error, log, warn
|
||||
|
||||
@@ -95,7 +94,11 @@ def getEnabledRelays(net):
|
||||
:rtype: list of int
|
||||
:return: list of enabled relay numbers
|
||||
"""
|
||||
enabledRelays = [x for x in main.network[net].relays.keys() if main.network[net].relays[x]["enabled"]]
|
||||
enabledRelays = [
|
||||
x
|
||||
for x in main.network[net].relays.keys()
|
||||
if main.network[net].relays[x]["enabled"]
|
||||
]
|
||||
# debug(f"getEnabledRelays() {net}: {enabledRelays}")
|
||||
return enabledRelays
|
||||
|
||||
@@ -259,7 +262,9 @@ def emptyChanAllocate(net, flist):
|
||||
chan_slots_used = getTotalChans(net)
|
||||
max_chans = getSumChanlimit(net) - chan_slots_used
|
||||
trunc_list = newlist[:max_chans]
|
||||
debug(f"emptyChanAllocate() {net}: newlist:{len(newlist)} trunc_list:{len(trunc_list)}")
|
||||
debug(
|
||||
f"emptyChanAllocate() {net}: newlist:{len(newlist)} trunc_list:{len(trunc_list)}"
|
||||
)
|
||||
|
||||
for i in chanfree.keys():
|
||||
for x in range(chanfree[i]):
|
||||
@@ -359,9 +364,13 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||
listinfo = minifyChans(net, listinfo)
|
||||
if not listinfo:
|
||||
return
|
||||
if relay <= main.config["ChanKeep"]["SigSwitch"]: # we can cover all of the channels
|
||||
if (
|
||||
relay <= main.config["ChanKeep"]["SigSwitch"]
|
||||
): # we can cover all of the channels
|
||||
coverAll = True
|
||||
elif relay > main.config["ChanKeep"]["SigSwitch"]: # we cannot cover all of the channels
|
||||
elif (
|
||||
relay > main.config["ChanKeep"]["SigSwitch"]
|
||||
): # we cannot cover all of the channels
|
||||
coverAll = False
|
||||
# if not sigrelay <= main.config["ChanKeep"]["MaxRelay"]:
|
||||
# error("Network %s is too big to cover: %i relays required" % (net, sigrelay))
|
||||
@@ -389,7 +398,9 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||
flist = [i[0] for i in listinfo_sort]
|
||||
|
||||
flist = flist[:max_chans]
|
||||
debug(f"keepChannels() {net}: joining {len(flist)}/{len(listinfo_sort)} channels")
|
||||
debug(
|
||||
f"keepChannels() {net}: joining {len(flist)}/{len(listinfo_sort)} channels"
|
||||
)
|
||||
trace(f"keepChannels() {net}: joining:{flist}")
|
||||
populateChans(net, flist)
|
||||
else:
|
||||
@@ -411,8 +422,12 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||
siglist = siglist[:max_chans]
|
||||
trace(f"keepChannels() {net}: truncated siglist:{siglist}")
|
||||
|
||||
trace(f"keepChannels() {net}: siglist:{siglist} max_chans:{max_chans} len_sig:{len(listinfo_sort)}")
|
||||
debug(f"keepChannels() {net}: joining {len(siglist)}/{len(listinfo_sort)} channels")
|
||||
trace(
|
||||
f"keepChannels() {net}: siglist:{siglist} max_chans:{max_chans} len_sig:{len(listinfo_sort)}"
|
||||
)
|
||||
debug(
|
||||
f"keepChannels() {net}: joining {len(siglist)}/{len(listinfo_sort)} channels"
|
||||
)
|
||||
trace(f"keepChannels() {net}: joining:{siglist}")
|
||||
populateChans(net, siglist)
|
||||
notifyJoin(net)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
import main
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
|
||||
def event(name, eventType):
|
||||
|
||||
@@ -64,7 +64,9 @@ def parsemeta(numName, c):
|
||||
)
|
||||
|
||||
|
||||
def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen
|
||||
def event(
|
||||
numName, c
|
||||
): # yes I'm using a short variable because otherwise it goes off the screen
|
||||
if dedup(numName, c):
|
||||
return
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from copy import deepcopy
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||
|
||||
import main
|
||||
from core.bot import IRCBotFactory
|
||||
from modules import alias
|
||||
from modules.chankeep import nukeNetwork
|
||||
from modules.provision import provisionRelay
|
||||
from modules.regproc import needToRegister
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||
from utils.deliver_relay_commands import deliverRelayCommands
|
||||
from utils.get import getRelay
|
||||
from utils.logging.log import log
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
from twisted.internet import reactor
|
||||
|
||||
import main
|
||||
import modules.regproc
|
||||
from twisted.internet import reactor
|
||||
from utils.deliver_relay_commands import deliverRelayCommands
|
||||
from utils.logging.log import warn
|
||||
|
||||
|
||||
def provisionUserNetworkData(num, nick, altnick, ident, realname, network, host, port, security):
|
||||
def provisionUserNetworkData(
|
||||
num, nick, altnick, ident, realname, network, host, port, security
|
||||
):
|
||||
commands = {}
|
||||
stage2commands = {}
|
||||
stage2commands["status"] = []
|
||||
commands["controlpanel"] = []
|
||||
user = nick.lower()
|
||||
commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"]))
|
||||
commands["controlpanel"].append(
|
||||
"AddUser %s %s" % (user, main.config["Relay"]["Password"])
|
||||
)
|
||||
commands["controlpanel"].append("AddNetwork %s %s" % (user, network))
|
||||
commands["controlpanel"].append("Set Nick %s %s" % (user, nick))
|
||||
commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick))
|
||||
commands["controlpanel"].append("Set Ident %s %s" % (user, ident))
|
||||
commands["controlpanel"].append("Set RealName %s %s" % (user, realname))
|
||||
if security == "ssl":
|
||||
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me
|
||||
commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port))
|
||||
commands["controlpanel"].append(
|
||||
"SetNetwork TrustAllCerts %s %s true" % (user, network)
|
||||
) # Don't judge me
|
||||
commands["controlpanel"].append(
|
||||
"AddServer %s %s %s +%s" % (user, network, host, port)
|
||||
)
|
||||
elif security == "plain":
|
||||
commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port))
|
||||
commands["controlpanel"].append(
|
||||
"AddServer %s %s %s %s" % (user, network, host, port)
|
||||
)
|
||||
if not main.config["ConnectOnCreate"]:
|
||||
stage2commands["status"].append("Disconnect")
|
||||
if main.config["Toggles"]["CycleChans"]:
|
||||
@@ -84,7 +93,9 @@ def provisionMultipleRelays(net, relaysNeeded):
|
||||
if not relaysNeeded:
|
||||
return []
|
||||
if not main.config["ChanKeep"]["Provision"]:
|
||||
warn(f"Asked to create {relaysNeeded} relays for {net}, but provisioning is disabled")
|
||||
warn(
|
||||
f"Asked to create {relaysNeeded} relays for {net}, but provisioning is disabled"
|
||||
)
|
||||
return []
|
||||
numsProvisioned = []
|
||||
for i in range(relaysNeeded):
|
||||
|
||||
@@ -145,9 +145,13 @@ def enableAuthentication(net, num, jump=True, run_now=False):
|
||||
return
|
||||
# uname = main.alias[num]["nick"] + "/" + net
|
||||
password = main.network[net].aliases[num]["password"]
|
||||
provision.provisionAuthenticationData(num, nick, net, auth, password) # Set up for auth
|
||||
provision.provisionAuthenticationData(
|
||||
num, nick, net, auth, password
|
||||
) # Set up for auth
|
||||
if jump:
|
||||
main.IRCPool[name].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
|
||||
main.IRCPool[name].msg(
|
||||
main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump"
|
||||
)
|
||||
if run_now:
|
||||
attemptManualAuthentication(net, num)
|
||||
if selectInst(net)["check"] is False:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from twisted.internet.threads import deferToThread
|
||||
|
||||
import main
|
||||
from modules import chankeep
|
||||
from twisted.internet.threads import deferToThread
|
||||
from utils.logging.debug import debug, trace
|
||||
from utils.logging.log import warn
|
||||
from utils.parsing import parsen
|
||||
@@ -175,7 +174,9 @@ def delUser(name, channel, nick, user):
|
||||
p.srem(namespace, nick)
|
||||
if channels == {channel.encode()}: # can we only see them on this channel?
|
||||
p.delete(chanspace) # remove channel tracking entry
|
||||
p.hdel("live.prefix." + name + "." + channel, nick) # remove prefix tracking entry
|
||||
p.hdel(
|
||||
"live.prefix." + name + "." + channel, nick
|
||||
) # remove prefix tracking entry
|
||||
p.hdel(mapspace, nick) # remove nick mapping entry
|
||||
if user:
|
||||
p.srem(gnamespace, user) # remove global userinfo entry
|
||||
@@ -200,7 +201,10 @@ def getUserByNick(name, nick):
|
||||
if main.r.hexists(mapspace, nick):
|
||||
return main.r.hget(mapspace, nick)
|
||||
else:
|
||||
warn("Entry doesn't exist: %s on %s - attempting auxiliary lookup" % (nick, mapspace))
|
||||
warn(
|
||||
"Entry doesn't exist: %s on %s - attempting auxiliary lookup"
|
||||
% (nick, mapspace)
|
||||
)
|
||||
# return False
|
||||
# legacy code below - remove when map is reliable
|
||||
usermatch = main.r.sscan(gnamespace, match=escape(nick) + "!*", count=999999999)
|
||||
@@ -230,10 +234,18 @@ def renameUser(name, oldnick, olduser, newnick, newuser):
|
||||
p.sadd("live.who." + name + "." + i, newnick)
|
||||
p.hdel(mapspace, oldnick)
|
||||
p.hset(mapspace, newnick, newuser)
|
||||
if main.r.exists("live.prefix." + name + "." + i): # if there's a prefix entry for the channel
|
||||
if main.r.hexists("live.prefix." + name + "." + i, oldnick): # if the old nick is in it
|
||||
mode = main.r.hget("live.prefix." + name + "." + i, oldnick) # retrieve old modes
|
||||
p.hset("live.prefix." + name + "." + i, newnick, mode) # set old modes to new nickname
|
||||
if main.r.exists(
|
||||
"live.prefix." + name + "." + i
|
||||
): # if there's a prefix entry for the channel
|
||||
if main.r.hexists(
|
||||
"live.prefix." + name + "." + i, oldnick
|
||||
): # if the old nick is in it
|
||||
mode = main.r.hget(
|
||||
"live.prefix." + name + "." + i, oldnick
|
||||
) # retrieve old modes
|
||||
p.hset(
|
||||
"live.prefix." + name + "." + i, newnick, mode
|
||||
) # set old modes to new nickname
|
||||
if main.r.exists(chanspace):
|
||||
p.rename(chanspace, newchanspace)
|
||||
else:
|
||||
@@ -299,6 +311,8 @@ def delChannels(net, channels): # we have left a channel
|
||||
if channel in dupes[net]:
|
||||
if dupes[net][channel] != 0:
|
||||
channels.remove(channel)
|
||||
debug(f"Not removing channel {channel} as {net} has {dupes[net][channel]} other relays covering it")
|
||||
debug(
|
||||
f"Not removing channel {channel} as {net} has {dupes[net][channel]} other relays covering it"
|
||||
)
|
||||
deferToThread(_delChannels, net, channels)
|
||||
# d.addCallback(testCallback)
|
||||
|
||||
Reference in New Issue
Block a user