Case-insensitively compare the bot's nick when checking for PMs

Closes #161.
This commit is contained in:
nyuszika7h 2015-09-06 11:46:49 +02:00
parent 2bd5acab53
commit 8a90145474
3 changed files with 38 additions and 5 deletions

View File

@ -1,9 +1,9 @@
# The bot commands implemented in here are present no matter which module is loaded
import traceback
import base64
import socket
import sys
import traceback
from oyoyo.parse import parse_nick
@ -19,7 +19,6 @@ sys.stderr.target_logger = log
hook = decorators.hook
def on_privmsg(cli, rawnick, chan, msg, notice = False):
try:
prefixes = getattr(var, "STATUSMSG_PREFIXES")
except AttributeError:
@ -28,11 +27,20 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
if botconfig.IGNORE_HIDDEN_COMMANDS and chan[0] in prefixes:
return
if (notice and ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
(chan == botconfig.NICK and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
try:
getattr(var, "CASEMAPPING")
except AttributeError:
var.CASEMAPPING = "rfc1459"
if not (notice and "!" not in rawnick and chan in ("*", "AUTH")):
# Not an on-connect message before RPL_ISUPPORT.
log("Server did not send a case mapping; falling back to rfc1459.")
if (notice and ((not var.irc_equals(chan, botconfig.NICK) and not botconfig.ALLOW_NOTICE_COMMANDS) or
(var.irc_equals(chan, botconfig.NICK) and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
return # not allowed in settings
if chan == botconfig.NICK:
if var.irc_equals(chan, botconfig.NICK):
chan = parse_nick(rawnick)[0]
for fn in decorators.COMMANDS[""]:

View File

@ -378,6 +378,24 @@ def check_priv(priv):
is_admin = check_priv("admin")
is_owner = check_priv("owner")
def irc_lower(nick):
mapping = {
"[": "{",
"]": "}",
"\\": "|",
"^": "~",
}
if CASEMAPPING == "strict-rfc1459":
mapping.pop("^")
elif CASEMAPPING == "ascii":
mapping = {}
return nick.lower().translate(str.maketrans(mapping))
def irc_equals(nick1, nick2):
return irc_lower(nick1) == irc_lower(nick2)
def plural(role):
bits = role.split()
bits[-1] = {"person": "people", "wolf": "wolves"}.get(bits[-1], bits[-1] + "s")

View File

@ -5877,6 +5877,13 @@ def getfeatures(cli, nick, *rest):
pass
if r.startswith("STATUSMSG="):
var.STATUSMSG_PREFIXES = list(r.split("=")[1])
if r.startswith("CASEMAPPING="):
var.CASEMAPPING = r.split("=")[1]
if var.CASEMAPPING not in ("rfc1459", "strict-rfc1459", "ascii"):
# This is very unlikely to happen, but just in case.
errlog("Unsupported case mapping: {0!r}; falling back to rfc1459.".format(var.CASEMAPPING))
var.CASEMAPPING = "rfc1459"
def mass_privmsg(cli, targets, msg, notice=False, privmsg=False):
if not notice and not privmsg: