Made DM more reliable (now doesn't rely on a pre-existing DM channel)
This commit is contained in:
parent
fe058e2ca8
commit
6f9deef681
|
|
@ -21,13 +21,14 @@ def alert_user(slack: SlackClient, brother: scroll_util.Brother, saywhat: str) -
|
||||||
DM a brother saying something. Wrapper around several simpler methods
|
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)
|
# 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):
|
for slack_id in identifier.lookup_brother_userids(brother):
|
||||||
dm_id = slack_util.im_channel_for_id(slack, slack_id)
|
slack_util.send_message(slack, saywhat, slack_id)
|
||||||
if dm_id:
|
succ = True
|
||||||
# Give a dummy msg dict, since we won't actually be using anything in it
|
|
||||||
slack_util.send_message(slack, saywhat, dm_id)
|
# Warn if we never find
|
||||||
else:
|
if not succ:
|
||||||
print("Warning: unable to find dm for brother {}".format(brother))
|
print("Warning: unable to find dm for brother {}".format(brother))
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,9 @@ class RemindJobs(slack_util.Passive):
|
||||||
# For each, send them a DM
|
# For each, send them a DM
|
||||||
success = False
|
success = False
|
||||||
for slack_id in assignee_ids:
|
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())
|
msg = "{}, you still need to do {}".format(a.assignee.name, a.job.pretty_fmt())
|
||||||
if dm_id:
|
success = True
|
||||||
success = True
|
slack_util.send_message(slack, msg, slack_id)
|
||||||
slack_util.send_message(slack, msg, dm_id)
|
|
||||||
|
|
||||||
# Warn on failure
|
# Warn on failure
|
||||||
if not success:
|
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)
|
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]:
|
def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
|
||||||
"""
|
"""
|
||||||
Generator that yields messages from slack.
|
Generator that yields messages from slack.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue