Make the stats command aware of duplicate networks

This commit is contained in:
Mark Veidemanis 2018-10-21 17:14:50 +01:00
parent 7cd6bc3616
commit 3bf361134f
3 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import main import main
import modules.counters as count import modules.counters as count
import modules.userinfo as userinfo import modules.userinfo as userinfo
from string import digits
class Stats: class Stats:
def __init__(self, register): def __init__(self, register):
@ -15,8 +16,12 @@ class Stats:
for i in main.IRCPool.keys(): for i in main.IRCPool.keys():
numChannels += len(main.IRCPool[i].channels) numChannels += len(main.IRCPool[i].channels)
numWhoEntries += userinfo.getNumTotalWhoEntries() numWhoEntries += userinfo.getNumTotalWhoEntries()
stats.append("Servers: %s" % len(main.pool.keys())) stats.append("Registered servers:")
stats.append("Online servers: %s" % len(main.IRCPool.keys())) stats.append(" Total: %s" % len(main.pool.keys()))
stats.append(" Unique: %s" % len(main.nets()))
stats.append("Online servers:")
stats.append(" Total: %s" % len(main.IRCPool.keys()))
stats.append(" Unique: %s" % len(main.liveNets()))
stats.append("Channels: %s" % numChannels) stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries) stats.append("User records: %s" % numWhoEntries)
counterEvents = count.getEvents() counterEvents = count.getEvents()
@ -33,14 +38,20 @@ class Stats:
stats = [] stats = []
numChannels = 0 numChannels = 0
numWhoEntries = 0 numWhoEntries = 0
found = False
numNodes = 0
if spl[1] in main.IRCPool.keys(): for i in main.IRCPool.keys():
if "".join([x for x in i if not x in digits]) == spl[1]:
numChannels += len(main.IRCPool[spl[1]].channels) numChannels += len(main.IRCPool[spl[1]].channels)
else: found = True
numNodes += 1
if not found:
failure("Name does not exist: %s" % spl[1]) failure("Name does not exist: %s" % spl[1])
numWhoEntries += userinfo.getNumWhoEntries(spl[1]) numWhoEntries += userinfo.getNumWhoEntries(spl[1])
stats.append("Channels: %s" % numChannels) stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries) stats.append("User records: %s" % numWhoEntries)
stats.append("Endpoints: %s" % numNodes)
counterEvents = count.getEvents(spl[1]) counterEvents = count.getEvents(spl[1])
if counterEvents == None: if counterEvents == None:
stats.append("No counters records") stats.append("No counters records")

View File

@ -76,7 +76,7 @@ class IRCBot(IRCClient):
def privmsg(self, user, channel, msg): def privmsg(self, user, channel, msg):
nick, ident, host = self.parsen(user) nick, ident, host = self.parsen(user)
userinfo.editUser(self.net, channel, nick, user) #userinfo.editUser(self.net, channel, nick, user)
count.event(self.net, "privmsg") count.event(self.net, "privmsg")
keyword.actKeyword(user, channel, msg, self.nickname, "MSG", self.name) keyword.actKeyword(user, channel, msg, self.nickname, "MSG", self.name)

10
main.py
View File

@ -31,8 +31,14 @@ def nets():
if not "pool" in globals(): if not "pool" in globals():
return return
networks = set() networks = set()
for i in pool: for i in pool.keys():
networks.add("".join([x for x in i if not i in digits])) networks.add("".join([x for x in i if not x in digits]))
return networks
def liveNets():
networks = set()
for i in IRCPool.keys():
networks.add("".join([x for x in i if not x in digits]))
return networks return networks
def register(command, function): def register(command, function):