Revert "Reformat project"

This reverts commit 64e3e1160aa76d191740342ab3edc68807f890fb.
This commit is contained in:
2022-07-21 13:40:01 +01:00
parent 760e43b59a
commit 3229d9b806
57 changed files with 214 additions and 519 deletions

View File

@@ -1,38 +1,45 @@
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.words.protocols.irc import IRCClient
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from twisted.internet import reactor, task
from twisted.words.protocols.irc import (
symbolic_to_numeric,
numeric_to_symbolic,
lowDequote,
IRCBadMessage,
)
import sys
from string import digits
from random import randint
from copy import deepcopy
from datetime import datetime
from random import randint
from string import digits
from twisted.internet import reactor, task
from twisted.internet.defer import Deferred
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from twisted.internet.task import LoopingCall
from twisted.words.protocols.irc import (IRCBadMessage, IRCClient, lowDequote,
numeric_to_symbolic,
symbolic_to_numeric)
from modules import userinfo
from modules import counters
from modules import monitor
from modules import chankeep
from modules import regproc
import main
from core.relay import sendRelayNotification
from modules import chankeep, counters, monitor, regproc, userinfo
from utils.dedup import dedup
from utils.get import getRelay
from utils.logging.debug import *
import main
from utils.logging.log import *
from utils.logging.debug import *
from utils.logging.send import *
from utils.parsing import parsen
from twisted.internet.ssl import DefaultOpenSSLContextFactory
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
keyFN = main.certPath + main.config["Key"]
certFN = main.certPath + main.config["Certificate"]
contextFactory = DefaultOpenSSLContextFactory(
keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")
)
bot = IRCBotFactory(
net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2
)
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
bot = IRCBotFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
host, port = getRelay(num)
rct = reactor.connectSSL(host, port, bot, contextFactory)
@@ -158,9 +165,7 @@ class IRCBot(IRCClient):
self.listAttempted = False # we asked for a list
self.listSimple = False # after asking again we got the list, so use the simple
# syntax from now on
self.wantList = (
False # we want to send a LIST, but not all relays are active yet
)
self.wantList = False # we want to send a LIST, but not all relays are active yet
self.chanlimit = 0
self.prefix = {}
self.servername = None
@@ -192,14 +197,9 @@ class IRCBot(IRCClient):
if not i in self.channels:
if self.net in main.blacklist.keys():
if i in main.blacklist[self.net]:
debug(
"Not joining blacklisted channel %s on %s - %i"
% (i, self.net, self.num)
)
debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num))
continue
debug(
self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds"
)
debug(self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds")
reactor.callLater(sleeptime, self.join, i)
sleeptime += increment
if sleeptime == 10:
@@ -207,17 +207,11 @@ class IRCBot(IRCClient):
increment = 0.7
increment += 0.1
else:
error(
"%s - Cannot join channel we are already on: %s - %i"
% (i, self.net, self.num)
)
error("%s - Cannot join channel we are already on: %s - %i" % (i, self.net, self.num))
def checkChannels(self):
if not chankeep.allRelaysActive(self.net):
debug(
"Skipping channel check as we have inactive relays: %s - %i"
% (self.net, self.num)
)
debug("Skipping channel check as we have inactive relays: %s - %i" % (self.net, self.num))
return
if self.net in main.TempChan.keys():
if self.num in main.TempChan[self.net].keys():
@@ -231,9 +225,7 @@ class IRCBot(IRCClient):
cast["ts"] = str(datetime.now().isoformat())
# remove odd stuff
for i in list(
cast.keys()
): # Make a copy of the .keys() as Python 3 cannot handle iterating over
for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over
if cast[i] == "": # a dictionary that changes length with each iteration
del cast[i]
# remove server stuff
@@ -367,9 +359,7 @@ class IRCBot(IRCClient):
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
log("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
sendAll(
"%s - %i: password mismatch as %s" % (self.net, self.num, self.username)
)
sendAll("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
def _who(self, channel):
d = Deferred()
@@ -484,17 +474,12 @@ class IRCBot(IRCClient):
debug("Will not send LIST, unauthenticated: %s - %i" % (self.net, self.num))
return
if self.listAttempted:
debug(
"List request dropped, already asked for LIST - %s - %i"
% (self.net, self.num)
)
debug("List request dropped, already asked for LIST - %s - %i" % (self.net, self.num))
return
else:
self.listAttempted = True
if self.listOngoing:
debug(
"LIST request dropped, already ongoing - %s - %i" % (self.net, self.num)
)
debug("LIST request dropped, already ongoing - %s - %i" % (self.net, self.num))
return
else:
if nocheck:
@@ -519,9 +504,7 @@ class IRCBot(IRCClient):
self._tempList[1].append([channel, users, topic])
def irc_RPL_LISTEND(self, prefix, params):
if (
not len(self._tempList[0]) > 0
): # there are no callbacks, can't do anything there
if not len(self._tempList[0]) > 0: # there are no callbacks, can't do anything there
debug("We didn't ask for this LIST, discarding")
self._tempList[0].clear()
self._tempList[1].clear()
@@ -546,10 +529,7 @@ class IRCBot(IRCClient):
else:
if self.listRetried:
self.listRetried = False
debug(
"List received after retry - defaulting to simple list syntax: %s - %i"
% (self.net, self.num)
)
debug("List received after retry - defaulting to simple list syntax: %s - %i" % (self.net, self.num))
self.listSimple = True
def got_list(self, listinfo):
@@ -563,10 +543,7 @@ class IRCBot(IRCClient):
name = self.net + "1"
if main.IRCPool[name].wantList == True:
main.IRCPool[name].list(nocheck=True)
debug(
"Asking for a list for %s after final relay %i connected"
% (self.net, self.num)
)
debug("Asking for a list for %s after final relay %i connected" % (self.net, self.num))
if self.num == 1: # Only one instance should do a list
if self.chanlimit:
if allRelays:
@@ -583,9 +560,7 @@ class IRCBot(IRCClient):
]: # TODO: add check for register request sent, only send it once
if main.config["AutoReg"]:
if not self.authenticated:
self._regAttempt = reactor.callLater(
5, regproc.registerAccount, self.net, self.num
)
self._regAttempt = reactor.callLater(5, regproc.registerAccount, self.net, self.num)
# regproc.registerAccount(self.net, self.num)
try:
self.chanlimit = int(chanlimit)
@@ -593,9 +568,7 @@ class IRCBot(IRCClient):
warn("Invalid chanlimit: %s" % i)
if self.chanlimit == 0:
self.chanlimit = 200 # don't take the piss if it's not limited
if not regproc.needToRegister(
self.net
): # if we need to register, only recheck on auth confirmation
if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation
self.recheckList()
def seed_prefix(self, prefix):
@@ -696,9 +669,7 @@ class IRCBot(IRCClient):
if negativepass == True:
if self._negativePass == None:
self._negativePass = True
debug(
"Positive registration check - %s - %i" % (self.net, self.num)
)
debug("Positive registration check - %s - %i" % (self.net, self.num))
if sinst["ping"]:
debug("Sending ping - %s - %i" % (self.net, self.num))
self.msg(sinst["entity"], sinst["pingmsg"])
@@ -754,9 +725,7 @@ class IRCBot(IRCClient):
lc = self._getWho[channel]
lc.stop()
del self._getWho[channel]
userinfo.delChannels(
self.net, [channel]
) # < we do not need to deduplicate this
userinfo.delChannels(self.net, [channel]) # < we do not need to deduplicate this
# log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
# other bots have different nicknames so

View File

@@ -1,8 +1,7 @@
import logging
from json import dumps, loads
import logstash
import logging
from json import dumps, loads
import main
from utils.logging.log import *

View File

@@ -24,9 +24,7 @@ def parseCommand(addr, authed, data):
failure("No text was sent")
return
if spl[0] in main.CommandMap.keys():
main.CommandMap[spl[0]](
addr, authed, data, obj, spl, success, failure, info, incUsage, length
)
main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
return
incUsage(None)
return

View File

@@ -1,7 +1,6 @@
from copy import deepcopy
from twisted.internet.protocol import Protocol, Factory, ClientFactory
from json import dumps, loads
from twisted.internet.protocol import ClientFactory, Factory, Protocol
from copy import deepcopy
import main
from utils.logging.log import *
@@ -115,13 +114,8 @@ class Relay(Protocol):
def handleHello(self, parsed):
if parsed["key"] in main.tokens.keys():
if (
parsed["hello"] == main.tokens[parsed["key"]]["hello"]
and main.tokens[parsed["key"]]["usage"] == "relay"
):
self.sendMsg(
{"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]}
)
if parsed["hello"] == main.tokens[parsed["key"]]["hello"] and main.tokens[parsed["key"]]["usage"] == "relay":
self.sendMsg({"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]})
self.authed = True
else:
self.transport.loseConnection()
@@ -136,10 +130,7 @@ class Relay(Protocol):
def connectionLost(self, reason):
self.authed = False
log(
"Relay connection lost from %s:%s -- %s"
% (self.addr.host, self.addr.port, reason.getErrorMessage())
)
log("Relay connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
if self.addr in main.relayConnections.keys():
del main.relayConnections[self.addr]
else:

View File

@@ -1,9 +1,9 @@
from twisted.internet.protocol import ClientFactory, Factory, Protocol
from twisted.internet.protocol import Protocol, Factory, ClientFactory
import main
from core.parser import parseCommand
from utils.logging.log import *
from core.parser import parseCommand
class Server(Protocol):
def __init__(self, addr):
@@ -34,10 +34,7 @@ class Server(Protocol):
def connectionLost(self, reason):
self.authed = False
log(
"Connection lost from %s:%s -- %s"
% (self.addr.host, self.addr.port, reason.getErrorMessage())
)
log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
if self.addr in main.connections.keys():
del main.connections[self.addr]
else: