summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Yu <andrew@andrewyu.org>2022-08-12 02:12:21 +0800
committerAndrew Yu <andrew@andrewyu.org>2022-08-12 02:12:21 +0800
commite88aab29b4d04e6a44d6bb96f0cba5dd1c0c21c2 (patch)
tree0f90ba867c5e76089e8c1672ddb7d434c082b51d
parentbdef092a15b48d368fd1b500a18104338af09d90 (diff)
downloadirc-mod-bot-e88aab29b4d04e6a44d6bb96f0cba5dd1c0c21c2.tar.gz
irc-mod-bot-e88aab29b4d04e6a44d6bb96f0cba5dd1c0c21c2.zip
Hopefully unbroke case sensitivity
-rw-r--r--bot.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/bot.py b/bot.py
index 57befde..a4bad69 100644
--- a/bot.py
+++ b/bot.py
@@ -315,7 +315,7 @@ def handle_join(
) -> None:
if msg.source is None:
raise ProtocolViolation("JOIN without source")
- if msg.source.nick == me.nick:
+ if msg.source.nick.lower() == me.nick.lower():
try:
channels[msg.args[0]].joined = True
except KeyError:
@@ -338,7 +338,7 @@ def handle_part(
) -> None:
if msg.source is None:
raise ProtocolViolation("PART without source")
- if msg.source.nick == me.nick:
+ if msg.source.nick.lower() == me.nick():
try:
channels[msg.args[0]].joined = False
except KeyError:
@@ -366,9 +366,10 @@ def handle_352(
msg: Message,
) -> None:
try:
- user = users[msg.args[5]]
+ user = users[msg.args[5].lower()]
except KeyError:
user = User(nick=msg.args[5], ident=msg.args[2], host=msg.args[3])
+ users[msg.args[5].lower()] = user
@register_irc_callback(b"NICK")
@@ -383,10 +384,10 @@ def handle_nick(
if msg.source is None:
raise ProtocolViolation("NICK without source")
del users[
- msg.source.nick
+ msg.source.nick.lower()
] # We can't rename dictionary keys, so we remove and readd it.
msg.source.nick = msg.args[0]
- users[msg.source.nick] = msg.source
+ users[msg.source.nick.lower()] = msg.source
@register_irc_callback(b"353") # NAMES
@@ -404,10 +405,10 @@ def handle_353(
if nick.startswith(b"@") or nick.startswith(b"+"):
nick = nick[1:]
try:
- user = users[nick]
+ user = users[nick.lower()]
except KeyError:
user = User(nick=nick)
- users[nick] = user
+ users[nick.lower()] = user
channel.users.append(user)
user.in_channels.append(channel)
if nick.startswith(b"@"):
@@ -503,7 +504,7 @@ def handle_privmsg(
if not text.startswith(PREFIX):
return
text = text[len(PREFIX) :]
- elif target == me.nick:
+ elif target.lower() == me.nick.lower():
channel = None
if text.startswith(PREFIX):
text = text[len(PREFIX) :]
@@ -556,7 +557,7 @@ def handle_privmsg(
return
else:
try:
- kickban_target = users[kickban_string]
+ kickban_target = users[kickban_string.lower()]
assert kickban_target.nick and kickban_target.ident and kickban_target.host
kickban_mask = b"*!%s@%s" % (kickban_target.ident if (not kickban_target.ident.startswith(b"~")) else b"*", kickban_target.host)
n = ban_mask(s, channel, kickban_mask, protect=[me, msg.source])
@@ -633,13 +634,13 @@ def handle_privmsg(
reply(s, msg, b"Access denied.")
return
whois_target_nick = chat_command[1]
- if whois_target_nick == me.nick:
+ if whois_target_nick.lower() == me.nick.lower():
reply(s, msg, b"That's me, right?")
return
- elif whois_target_nick == msg.source.nick:
+ elif whois_target_nick.lower() == msg.source.nick.lower():
reply(s, msg, b"You should know enough about yourself. But oh well...")
try:
- whois_target = users[whois_target_nick]
+ whois_target = users[whois_target_nick.lower()]
except KeyError:
reply(s, msg, b"I know nothing about %s." % whois_target_nick)
return
@@ -703,11 +704,11 @@ def handle_incoming_line(
] = parse_message(m)
source: Optional[User]
try:
- source = users[parsed[1][0]] if parsed[1][0] else None
+ source = users[parsed[1][0].lower()] if parsed[1][0] else None
except KeyError:
assert parsed[1][0]
source = User(nick=parsed[1][0])
- users[parsed[1][0]] = source
+ users[parsed[1][0].lower()] = source
if source:
# These assignments are to update the ident and the host from incoming messages to users in our database, though this may be a bit redundent to do every time.