From 6e5daa721162eec0299bacdfe006d47d2bee4a70 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Thu, 12 Apr 2018 23:38:11 +0200 Subject: Refactor finding a channel by members into a method --- wee_slack.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index 6ebba2e..02b4dfc 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1060,6 +1060,12 @@ class SlackTeam(object): def buffer_prnt(self, data): w.prnt_date_tags(self.channel_buffer, SlackTS().major, tag("team"), data) + def find_channel_by_members(self, members, channel_type=None): + for channel in self.channels.itervalues(): + if channel.get_members() == members and ( + channel_type is None or channel.type == channel_type): + return channel + def get_channel_map(self): return {v.slack_name: k for k, v in self.channels.iteritems()} @@ -3217,12 +3223,7 @@ def command_talk(data, current_buffer, args): else: channel_type = 'im' - # Try finding the channel by type and members - for channel in team.channels.itervalues(): - if (channel.type == channel_type and - channel.get_members() == users): - chan = channel - break + chan = team.find_channel_by_members(users, channel_type=channel_type) # If the DM or MPDM doesn't exist, create it if not chan: -- cgit