Skip to content

Add support to ignore people in channel #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/lunchbox_bot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ defmodule LunchboxBot do
@base_endpoint "https://slack.com/api/"
@channel_info_path "/channels.info"
@post_message_path "/chat.postMessage"
@user_info_path "/users.info"
@default_greeting """
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
"""
@ignore_people ["hugh", "ricardo", "victor"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in env variables (or in a config file not pushed) as this is intended to be a public and easy-to-reuse tool.

Copy link
Contributor

@odarriba odarriba Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comma separated string as an ENV variable read from application's config file and parsed in the config function can be a good option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Slack give access to each users notification preferences for a channel? maybe ignore people who have notifications turned off

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or create a user group for people who can lunch and use that instead of all members of the channel

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using a user group, seems that it is possible, https://api.slack.com/methods/usergroups.list, what do you you think @pilu ?


def config do
%{
Expand All @@ -31,6 +33,13 @@ defmodule LunchboxBot do
case retrieve_users_in(token, channel) do
{:ok, ids} ->
ids
|> Enum.map(fn(id) ->
{:ok, %{"name" => real_name}} = retrieve_user_info(token, id)
{id, real_name}
end)
|> Enum.filter(fn({_, name}) ->
!Enum.member?(@ignore_people, name)
end)
|> Enum.shuffle
|> select_users
|> create_couples
Expand All @@ -57,7 +66,7 @@ defmodule LunchboxBot do
def build_text(couples, %{greeting: greeting}) do
text =
couples
|> Enum.map(fn({a, b}) ->
|> Enum.map(fn({{a,_}, {b,_}}) ->
"<@#{a}> with <@#{b}>"
end)
|> Enum.join("\n")
Expand Down Expand Up @@ -85,6 +94,20 @@ defmodule LunchboxBot do
end
end

def retrieve_user_info(token, user) do
case HTTPoison.post("#{@base_endpoint}#{@user_info_path}", {:form, [token: token, user: user]}) do
{:ok, resp} ->
info =
resp
|> Map.get(:body, "")
|> Poison.decode!
|> Map.get("user", %{})
{:ok, info}
error ->
error
end
end

def friday? do
Date.utc_today
|> Date.to_erl
Expand Down