Properly handle channel casing
This commit is contained in:
parent
a3fd532b3a
commit
63d908a61a
@ -2,7 +2,7 @@ import time
|
|||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from src.context import IRCContext, Features
|
from src.context import IRCContext, Features, lower
|
||||||
from src.events import Event
|
from src.events import Event
|
||||||
from src import users
|
from src import users
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ def predicate(name):
|
|||||||
|
|
||||||
def get(name, *, allow_none=False):
|
def get(name, *, allow_none=False):
|
||||||
try:
|
try:
|
||||||
return _channels[name]
|
return _channels[lower(name)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if allow_none:
|
if allow_none:
|
||||||
return None
|
return None
|
||||||
@ -45,20 +45,22 @@ def add(name, cli, key=""):
|
|||||||
# another one (or some other weird stuff like that). Instead of
|
# another one (or some other weird stuff like that). Instead of
|
||||||
# jumping through hoops, we just disallow it here.
|
# jumping through hoops, we just disallow it here.
|
||||||
|
|
||||||
if name in _channels:
|
if lower(name) in _channels:
|
||||||
if cli is not _channels[name].client:
|
if cli is not _channels[lower(name)].client:
|
||||||
raise RuntimeError("different IRC client for channel {0}".format(name))
|
raise RuntimeError("different IRC client for channel {0}".format(name))
|
||||||
return _channels[name]
|
return _channels[lower(name)]
|
||||||
|
|
||||||
cls = Channel
|
cls = Channel
|
||||||
if predicate(name):
|
if predicate(name):
|
||||||
cls = FakeChannel
|
cls = FakeChannel
|
||||||
|
|
||||||
chan = _channels[name] = cls(name, cli)
|
chan = _channels[lower(name)] = cls(name, cli)
|
||||||
chan.join(key)
|
chan.join(key)
|
||||||
return chan
|
return chan
|
||||||
|
|
||||||
exists = _channels.__contains__
|
def exists(name):
|
||||||
|
"""Return True if a channel by the name exists, False otherwise."""
|
||||||
|
return lower(name) in _channels
|
||||||
|
|
||||||
def channels():
|
def channels():
|
||||||
"""Iterate over all the current channels."""
|
"""Iterate over all the current channels."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user