Selaa lähdekoodia

Updates for LTA monitor.

pull/10/merge
Ben Kurtovic 8 vuotta sitten
vanhempi
commit
def74a600c
1 muutettua tiedostoa jossa 29 lisäystä ja 16 poistoa
  1. +29
    -16
      commands/lta_monitor.py

+ 29
- 16
commands/lta_monitor.py Näytä tiedosto

@@ -58,30 +58,43 @@ class LTAMonitor(Command):
if len(self._recent) > self._recent_max:
self._recent.pop(0)

block = self._get_block_for_ip(ip)
if not block:
return

msg = ("\x02[{note}]\x0F Joined user \x02{nick}\x0F is {type}blocked "
"on-wiki ([[User:{user}]]) because: {reason}")
self.say(self._report_chan, msg.format(nick=data.nick, **block))

log = ("Reporting block ({note}): {nick} is [[User:{user}]], "
"{type}blocked because: {reason}")
self.logger.info(log.format(nick=data.nick, **block))

def _get_block_for_ip(self, ip):
"""Return a dictionary of blockinfo for an IP."""
site = self.bot.wiki.get_site()
try:
result = site.api_query(action="query", list="blocks", bkip=ip,
bklimit=1, bkprop="user|reason|range")
result = site.api_query(
action="query", list="blocks|globalblocks", bkip=ip, bgip=ip,
bklimit=1, bglimit=1, bkprop="user|reason|range",
bgprop="address|reason|range")
except APIError:
return
blocks = result["query"]["blocks"]
if not blocks:
lblocks = result["query"]["blocks"]
gblocks = result["query"]["globalblocks"]
if not lblocks and not gblocks:
return
block = blocks[0]

if re.search(r"web[ _-]?host", block["reason"], re.IGNORECASE):
block["note"] = "webhost warning"
else:
block["note"] = "alert"
block = lblocks[0] if lblocks else gblocks[0]
if block["rangestart"] != block["rangeend"]:
block["type"] = "range"
else:
block["type"] = "IP-"
if not lblocks:
block["type"] = "globally " + block["type"]

msg = ("\x02[{note}]\x0F Joined user \x02{nick}\x0F is {type}blocked "
"on-wiki ([[User:{user}]]) because: {reason}")
self.say(self._report_chan, msg.format(nick=data.nick, **block))

log = ("Reporting block ({note}): {nick} is [[User:{user}]], "
"{type}blocked because: {reason}")
self.logger.info(log.format(nick=data.nick, **block))
if re.search(r"web[ _-]?host", block["reason"], re.IGNORECASE):
block["note"] = "webhost warning"
else:
block["note"] = "alert"
return block

Ladataan…
Peruuta
Tallenna