From 2852afd5f75a9553c9448ebbc53f998da49474fc Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 21 Nov 2018 20:02:36 +0000 Subject: [PATCH] Add IRCServer.Server.get_target, to get an IRCChannel if the given target is a channel name or an IRCUser --- src/IRCServer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/IRCServer.py b/src/IRCServer.py index 7ca9c293..b602575b 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -194,6 +194,15 @@ class Server(IRCObject.Object): for channel in user.channels: channel.remove_user(user) + def get_target(self, name: str + ) -> typing.Union[IRCChannel.Channel, IRCUser.User]: + if name[0] in self.channel_types: + if name in self.channels: + return self.channels.get(name) + else: + return self.get_user(name) + return None + def change_user_nickname(self, old_nickname: str, new_nickname: str): user = self.users.pop(utils.irc.lower(self.case_mapping, old_nickname)) user._id = self.get_user_id(new_nickname)