Made DM more reliable (now doesn't rely on a pre-existing DM channel)
This commit is contained in:
parent
fe058e2ca8
commit
6f9deef681
|
|
@ -21,12 +21,13 @@ def alert_user(slack: SlackClient, brother: scroll_util.Brother, saywhat: str) -
|
|||
DM a brother saying something. Wrapper around several simpler methods
|
||||
"""
|
||||
# We do this as a for loop just in case multiple people reg. to same scroll for some reason (e.g. dup accounts)
|
||||
succ = False
|
||||
for slack_id in identifier.lookup_brother_userids(brother):
|
||||
dm_id = slack_util.im_channel_for_id(slack, slack_id)
|
||||
if dm_id:
|
||||
# Give a dummy msg dict, since we won't actually be using anything in it
|
||||
slack_util.send_message(slack, saywhat, dm_id)
|
||||
else:
|
||||
slack_util.send_message(slack, saywhat, slack_id)
|
||||
succ = True
|
||||
|
||||
# Warn if we never find
|
||||
if not succ:
|
||||
print("Warning: unable to find dm for brother {}".format(brother))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -85,11 +85,9 @@ class RemindJobs(slack_util.Passive):
|
|||
# For each, send them a DM
|
||||
success = False
|
||||
for slack_id in assignee_ids:
|
||||
dm_id = slack_util.im_channel_for_id(slack, slack_id)
|
||||
msg = "{}, you still need to do {}".format(a.assignee.name, a.job.pretty_fmt())
|
||||
if dm_id:
|
||||
success = True
|
||||
slack_util.send_message(slack, msg, dm_id)
|
||||
slack_util.send_message(slack, msg, slack_id)
|
||||
|
||||
# Warn on failure
|
||||
if not success:
|
||||
|
|
|
|||
|
|
@ -41,16 +41,6 @@ def send_message(slack: SlackClient, text: str, channel: str, thread: str = None
|
|||
return slack.api_call("chat.postMessage", **kwargs)
|
||||
|
||||
|
||||
def im_channel_for_id(slack: SlackClient, user_id: str) -> Optional[str]:
|
||||
conversations = slack.api_call("conversations.list", types="im")
|
||||
if conversations["ok"]:
|
||||
channels = conversations["channels"]
|
||||
for channel in channels:
|
||||
if channel["is_im"] and channel["user"] == user_id:
|
||||
return channel["id"]
|
||||
return None
|
||||
|
||||
|
||||
def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
|
||||
"""
|
||||
Generator that yields messages from slack.
|
||||
|
|
|
|||
Loading…
Reference in New Issue