diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2018-04-12 23:38:11 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2018-04-13 00:05:08 +0200 |
commit | 6e5daa721162eec0299bacdfe006d47d2bee4a70 (patch) | |
tree | d5f82a63f24912d0983555ecbc7d80952bfc5ac5 | |
parent | 64bf34e280ad1db6ef092c73f0737fd7bfe71334 (diff) | |
download | wee-slack-6e5daa721162eec0299bacdfe006d47d2bee4a70.tar.gz |
Refactor finding a channel by members into a method
-rw-r--r-- | wee_slack.py | 13 |
1 files 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: |