support for hostmask matching, and a little bit better nickserv auth

This commit is contained in:
jan6 2022-10-22 20:26:48 +03:00
parent 345f689e3d
commit 6bdd3915e1
3 changed files with 28 additions and 11 deletions

View File

@ -23,6 +23,10 @@ class config(config):
port = 6697
ssl = True
nickserv_auth = True
nickserv_mask = (
"NickServ!NickServ@services.libera.chat" # the mask you receive from server
)
nickserv_path = "NickServ@services." # the mask you actually send commands to
# get password from secret file
nickserv_pass = open("pass.txt", "r").read().strip()
nickserv_recover = "RECOVER" # I recall it being GHOST on some networks?
@ -64,4 +68,7 @@ if __name__ == "config":
except ModuleNotFoundError:
print("\x1b[31m!!! you should probably set up local config !!!\x1b[0m")
except KeyError:
from local_config import config
try:
from local_config import config
except ModuleNotFoundError:
print("\x1b[31m!!! you should probably set up local config !!!\x1b[0m")

View File

@ -30,20 +30,20 @@ def stuff(bot, sock):
nick=config.self.nick,
passwd=config.server.nickserv_pass,
auth="nickserv",
nickservmask="NickServ",
nickserv_auth=config.server.nickserv_auth,
):
# TODO: handle auth that isn't nickserv
if auth.lower() == "nickserv": # line.source.split("!")[0]
# TODO: on most network can probably do "PRIVMSG NickServ@services. :help"
# TODO: support actually checking the nickserv mask properly
if nickservmask == "NickServ":
try:
nickservmask = config.server.nickserv_mask
except:
True
util.mesg(f"IDENTIFY {nick} {passwd}", nickservmask)
nick_override = True
util.mesg(f"{config.server.nickserv_recover} {nick}", nickservmask)
if nickserv_auth:
util.mesg(f"IDENTIFY {nick} {passwd}", config.server.nickserv_path)
nick_override = True
util.mesg(
f"{config.server.nickserv_recover} {nick}",
config.server.nickserv_path,
)
# attempt to re-nick just in case
send(irctokens.build("NICK", [config.self.nick]).format())
def configure():
@ -108,7 +108,8 @@ def stuff(bot, sock):
if mode == "init":
if line.command == "NOTICE":
if line.source.startswith("NickServ!"):
# if line.source.startswith("NickServ!"):
if util.maskmatch(line.source, config.server.nickserv_mask):
if config.server.nickserv_auth == True:
auth()
# mesg(
@ -173,6 +174,7 @@ def stuff(bot, sock):
or "https://" in cmd
or "http://" in cmd
):
# TODO: allow ignoring hostmasks
if line.hostmask.nickname in config.cmd.ignored_nicks:
continue
try:

View File

@ -1,5 +1,6 @@
import irctokens
import time
from fnmatch import fnmatchcase
class Util:
@ -84,3 +85,10 @@ class Util:
def notice(self, msg: str, t=None):
t, msg = self._m(msg, t)
self.send(irctokens.build("NOTICE", [t, str(msg)]).format())
def maskmatch(self, string, hostmask):
"""DOES NOT HANDLE CASEMAPPING (yet), just dumb case-sensitive match, only ? and * are special"""
pat = "[[]".join(
[x.replace("]", "[]]") for x in hostmask.split("[")]
) # escape all [ and ] into [[] and []]
return fnmatchcase(string, pat)