Utils.irc_lower and Utils.irc_equals take an IRCServer parameter
This commit is contained in:
parent
a8bf248d47
commit
80ec110640
5 changed files with 21 additions and 17 deletions
10
IRCBuffer.py
10
IRCBuffer.py
|
@ -9,7 +9,9 @@ class BufferLine(object):
|
|||
self.from_self = from_self
|
||||
|
||||
class Buffer(object):
|
||||
def __init__(self, bot):
|
||||
def __init__(self, bot, server):
|
||||
self.bot = bot
|
||||
self.server = server
|
||||
self.lines = []
|
||||
self.max_lines = 64
|
||||
self._skip_next = False
|
||||
|
@ -29,7 +31,8 @@ class Buffer(object):
|
|||
def find(self, pattern, **kwargs):
|
||||
from_self = kwargs.get("from_self", True)
|
||||
for_user = kwargs.get("for_user", "")
|
||||
for_user = Utils.irc_lower(for_user) if for_user else None
|
||||
for_user = Utils.irc_lower(self.server, for_user
|
||||
) if for_user else None
|
||||
not_pattern = kwargs.get("not_pattern", None)
|
||||
for line in self.lines:
|
||||
if line.from_self and not from_self:
|
||||
|
@ -37,7 +40,8 @@ class Buffer(object):
|
|||
elif re.search(pattern, line.message):
|
||||
if not_pattern and re.search(not_pattern, line.message):
|
||||
continue
|
||||
if for_user and not Utils.irc_lower(line.sender) == for_user:
|
||||
if for_user and not Utils.irc_lower(self.server, line.sender
|
||||
) == for_user:
|
||||
continue
|
||||
return line
|
||||
def skip_next(self):
|
||||
|
|
|
@ -3,7 +3,7 @@ import IRCBuffer, Utils
|
|||
|
||||
class Channel(object):
|
||||
def __init__(self, name, id, server, bot):
|
||||
self.name = Utils.irc_lower(name)
|
||||
self.name = Utils.irc_lower(server, name)
|
||||
self.id = id
|
||||
self.server = server
|
||||
self.bot = bot
|
||||
|
@ -15,7 +15,7 @@ class Channel(object):
|
|||
self.users = set([])
|
||||
self.modes = {}
|
||||
self.created_timestamp = None
|
||||
self.buffer = IRCBuffer.Buffer(bot)
|
||||
self.buffer = IRCBuffer.Buffer(bot, server)
|
||||
|
||||
def __repr__(self):
|
||||
return "IRCChannel.Channel(%s|%s)" % (self.server.name, self.name)
|
||||
|
|
|
@ -560,7 +560,7 @@ class LineHandler(object):
|
|||
|
||||
# we need a registered nickname for this channel
|
||||
def handle_477(self, event):
|
||||
channel_name = Utils.irc_lower(event["args"][1])
|
||||
channel_name = Utils.irc_lower(event["server"], event["args"][1])
|
||||
if channel_name in event["server"].attempted_join:
|
||||
self.bot.add_timer("rejoin", 5,
|
||||
channel_name=event["args"][1],
|
||||
|
|
16
IRCServer.py
16
IRCServer.py
|
@ -131,9 +131,9 @@ class Server(object):
|
|||
|
||||
def set_own_nickname(self, nickname):
|
||||
self.nickname = nickname
|
||||
self.nickname_lower = Utils.irc_lower(nickname)
|
||||
self.nickname_lower = Utils.irc_lower(self, nickname)
|
||||
def is_own_nickname(self, nickname):
|
||||
return Utils.irc_equals(nickname, self.nickname)
|
||||
return Utils.irc_equals(self, nickname, self.nickname)
|
||||
|
||||
def add_own_mode(self, mode, arg=None):
|
||||
self.own_modes[mode] = arg
|
||||
|
@ -146,7 +146,7 @@ class Server(object):
|
|||
self.add_own_mode(mode, arg)
|
||||
|
||||
def has_user(self, nickname):
|
||||
return Utils.irc_lower(nickname) in self.users
|
||||
return Utils.irc_lower(self, nickname) in self.users
|
||||
def get_user(self, nickname):
|
||||
if not self.has_user(nickname):
|
||||
user_id = self.get_user_id(nickname)
|
||||
|
@ -155,7 +155,7 @@ class Server(object):
|
|||
user=new_user, server=self)
|
||||
self.users[new_user.nickname_lower] = new_user
|
||||
self.new_users.add(new_user)
|
||||
return self.users[Utils.irc_lower(nickname)]
|
||||
return self.users[Utils.irc_lower(self, nickname)]
|
||||
def get_user_id(self, nickname):
|
||||
self.bot.database.users.add(self.id, nickname)
|
||||
return self.bot.database.users.get_id(self.id, nickname)
|
||||
|
@ -165,12 +165,12 @@ class Server(object):
|
|||
channel.remove_user(user)
|
||||
|
||||
def change_user_nickname(self, old_nickname, new_nickname):
|
||||
user = self.users.pop(Utils.irc_lower(old_nickname))
|
||||
user = self.users.pop(Utils.irc_lower(self, old_nickname))
|
||||
user._id = self.get_user_id(new_nickname)
|
||||
self.users[Utils.irc_lower(new_nickname)] = user
|
||||
self.users[Utils.irc_lower(self, new_nickname)] = user
|
||||
def has_channel(self, channel_name):
|
||||
return channel_name[0] in self.channel_types and Utils.irc_lower(
|
||||
channel_name) in self.channels
|
||||
self, channel_name) in self.channels
|
||||
def get_channel(self, channel_name):
|
||||
if not self.has_channel(channel_name):
|
||||
channel_id = self.get_channel_id(channel_name)
|
||||
|
@ -179,7 +179,7 @@ class Server(object):
|
|||
self.events.on("new").on("channel").call(
|
||||
channel=new_channel, server=self)
|
||||
self.channels[new_channel.name] = new_channel
|
||||
return self.channels[Utils.irc_lower(channel_name)]
|
||||
return self.channels[Utils.irc_lower(self, channel_name)]
|
||||
def get_channel_id(self, channel_name):
|
||||
self.bot.database.channels.add(self.id, channel_name)
|
||||
return self.bot.database.channels.get_id(self.id, channel_name)
|
||||
|
|
|
@ -3,12 +3,12 @@ import IRCBuffer, Utils
|
|||
|
||||
class User(object):
|
||||
def __init__(self, nickname, id, server, bot):
|
||||
self.server = server
|
||||
self.set_nickname(nickname)
|
||||
self._id = id
|
||||
self.username = None
|
||||
self.hostname = None
|
||||
self.realname = None
|
||||
self.server = server
|
||||
self.bot = bot
|
||||
self.channels = set([])
|
||||
|
||||
|
@ -18,7 +18,7 @@ class User(object):
|
|||
self.identified_account_id = None
|
||||
self.identified_account_id_override = None
|
||||
self.away = False
|
||||
self.buffer = IRCBuffer.Buffer(bot)
|
||||
self.buffer = IRCBuffer.Buffer(bot, server)
|
||||
|
||||
def __repr__(self):
|
||||
return "IRCUser.User(%s|%s)" % (self.server.name, self.name)
|
||||
|
@ -31,7 +31,7 @@ class User(object):
|
|||
|
||||
def set_nickname(self, nickname):
|
||||
self.nickname = nickname
|
||||
self.nickname_lower = Utils.irc_lower(nickname)
|
||||
self.nickname_lower = Utils.irc_lower(self.server, nickname)
|
||||
self.name = self.nickname_lower
|
||||
def join_channel(self, channel):
|
||||
self.channels.add(channel)
|
||||
|
|
Loading…
Reference in a new issue