3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 19:52:53 +01:00

Declare IRCd casemapping in protocol modules, and respect these in utils.nickToUid

This adds a new utils.toLower(irc, text) function which returns the lowercased version of <text> based on <irc>'s declared case mapping.

Closes #75.
This commit is contained in:
James Lu 2015-07-22 20:31:45 -07:00
parent 8c1e1c18f1
commit 35cdfbf7e6
3 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,8 @@ from log import log
from classes import *
casemapping = 'ascii'
# Raw commands sent from servers vary from protocol to protocol. Here, we map
# non-standard names to our hook handlers, so plugins get the information they need.

View File

@ -17,6 +17,7 @@ from inspircd import handle_privmsg, handle_kill, handle_kick, handle_error, \
handle_quit, handle_nick, handle_save, handle_squit, handle_mode, handle_topic, \
handle_notice
casemapping = 'rfc1459'
hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE'}
def _send(irc, sid, msg):

View File

@ -122,9 +122,18 @@ def add_hook(func, command):
command = command.upper()
command_hooks[command].append(func)
def toLower(irc, text):
if irc.proto.casemapping == 'rfc1459':
text = text.replace('{', '[')
text = text.replace('}', ']')
text = text.replace('|', '\\')
text = text.replace('~', '^')
return text.lower()
def nickToUid(irc, nick):
nick = toLower(irc, nick)
for k, v in irc.users.items():
if v.nick == nick:
if toLower(irc, v.nick) == nick:
return k
def clientToServer(irc, numeric):