2019-12-24 10:13:01 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
2020-01-11 22:10:57 +00:00
|
|
|
_name = "Hostmasks"
|
|
|
|
|
2019-12-24 10:13:01 +00:00
|
|
|
@utils.hook("new.user")
|
|
|
|
def new_user(self, event):
|
|
|
|
userhost = event["user"].userhost()
|
|
|
|
if not userhost == None:
|
|
|
|
known_hostmasks = event["user"].get_setting("known-hostmasks", [])
|
|
|
|
if not userhost in known_hostmasks:
|
|
|
|
known_hostmasks.append(userhost)
|
|
|
|
event["user"].set_setting("known-hostmasks", known_hostmasks)
|
2020-01-11 22:10:57 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.maskfind")
|
|
|
|
@utils.kwarg("min_args", 1)
|
|
|
|
@utils.kwarg("help", "Find all nicknames that used a given hostmask")
|
|
|
|
@utils.kwarg("usage", "<hostmask>")
|
|
|
|
@utils.kwarg("permission", "maskfind")
|
|
|
|
def maskfind(self, event):
|
|
|
|
all_userhosts = event["server"].get_all_user_settings("known-hostmasks")
|
|
|
|
nicknames = set([])
|
|
|
|
hostmask_str = event["args_split"][0]
|
|
|
|
hostmask = utils.irc.hostmask_parse(hostmask_str)
|
|
|
|
|
2020-01-11 22:20:35 +00:00
|
|
|
searched = 0
|
2020-01-11 22:10:57 +00:00
|
|
|
for nickname, userhosts in all_userhosts:
|
2020-01-11 22:20:35 +00:00
|
|
|
searched += len(userhosts)
|
2020-01-11 22:10:57 +00:00
|
|
|
for userhost in userhosts:
|
|
|
|
if hostmask.match(userhost):
|
2020-01-11 22:25:21 +00:00
|
|
|
nicknames.add((nickname, userhost))
|
2020-01-11 22:10:57 +00:00
|
|
|
|
|
|
|
if nicknames:
|
2020-01-11 22:25:21 +00:00
|
|
|
outs = []
|
|
|
|
for nickname, userhost in sorted(nicknames):
|
2020-01-11 22:28:46 +00:00
|
|
|
outs.append("%s (%s)" % (utils.irc.bold(nickname), userhost))
|
2020-01-11 22:20:35 +00:00
|
|
|
event["stdout"].write("%s (%d/%d): %s" %
|
2020-01-11 22:25:21 +00:00
|
|
|
(hostmask_str, len(nicknames), searched, ", ".join(outs)))
|
2020-01-11 22:10:57 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("Hostmask not found")
|