-
Notifications
You must be signed in to change notification settings - Fork 2
Add dishwasher manager bot #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
rhumbertgz
wants to merge
30
commits into
m1dnight:master
Choose a base branch
from
rhumbertgz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
121e253
Avoid showing menu for other bots
rhumbertgz 4d2e0d3
Fix warnings for unused arguments
rhumbertgz 21e32ea
Update dependencies to avoid warning on Elixir 1.5
rhumbertgz b0d7bfc
Add initial version of the dishwasher-manager bot
rhumbertgz 4a7fd86
Add dishwasher-manager bot workers
rhumbertgz dc2c120
Update dependencies
rhumbertgz 73978c6
Add beta dishwasher-manager bot
rhumbertgz bd2aab7
Add support for individual message responses
rhumbertgz b88baa5
Add support for multiple help menus based on user's role
rhumbertgz bf821e6
Fix minor bugs
rhumbertgz 9284cbb
Add support for private messages
rhumbertgz 757ff2f
Add support for private messages
rhumbertgz 6d0fb1e
Full beta version
rhumbertgz 8c72396
Add dishwasher scheduler
rhumbertgz 1afd693
Add scheduler supervisor
rhumbertgz ef21e27
Add timezone parameter for cronex
rhumbertgz c391c56
Update dependencies
rhumbertgz 7d3fdfd
Update internal data structure for users and schedule
rhumbertgz 23077cf
Add initial values to users and schedule file
rhumbertgz 214b771
Remove print trace
rhumbertgz c29bf13
Format code
rhumbertgz 6a3d52f
Add dishwasher settings
rhumbertgz 816c2f6
Add github settings
rhumbertgz 838f6c9
Update scheduler messages
rhumbertgz 3ceaa05
Fix next manager functionality bug
rhumbertgz 1c44e3d
Fix warnings
rhumbertgz 69c2e10
Fix typo on the reminder message for the next dishwasher manager
rhumbertgz 85ce1da
Fix bugs on message patterns and generalize them
rhumbertgz 7cb5fb4
Update dependencies
rhumbertgz d02f285
Fix error after user-name changes
rhumbertgz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| [{cderoove,{<<"Coen De Roover">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 11,month => 9,year => 2017}}}, | ||
| {mathsaey,{<<"Mathijs Saey">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 18,month => 9,year => 2017}}}, | ||
| {thierry,{<<"Thierry Renaux">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 25,month => 9,year => 2017}}}, | ||
| {kevin,{<<"Kevin Pinte">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 2,month => 10,year => 2017}}}, | ||
| {fmyter,{<<"Florian Myter">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 9,month => 10,year => 2017}}}, | ||
| {tmoldere,{<<"Tim Molderez">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 16,month => 10,year => 2017}}}, | ||
| {joeri,{<<"Joeri De Koster">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 23,month => 10,year => 2017}}}, | ||
| {simon,{<<"Simon Van de Water">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 30,month => 10,year => 2017}}}, | ||
| {nathalie,{<<"Nathalie Oostvogels">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 6,month => 11,year => 2017}}}, | ||
| {jswalens,{<<"Janwillem Swalens">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 13,month => 11,year => 2017}}}, | ||
| {eljenso,{<<"Jens Nicolay">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 20,month => 11,year => 2017}}}, | ||
| {kennedy,{<<"Kennedy Kambona">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 27,month => 11,year => 2017}}}, | ||
| {qstieven,{<<"Quentin Stievenart">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 4,month => 12,year => 2017}}}, | ||
| {dirk,{<<"Dirk van Deun">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 11,month => 12,year => 2017}}}, | ||
| {jbsartor,{<<"Jennifer Sartor">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 18,month => 12,year => 2017}}}, | ||
| {jdeblese,{<<"Jonas De Bleser">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 8,month => 1,year => 2018}}}, | ||
| {nvgeele,{<<"Nils Van Geele">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 15,month => 1,year => 2018}}}, | ||
| {ascullpu,{<<"Angel Luis Scull Pupo">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 22,month => 1,year => 2018}}}, | ||
| {carmen,{<<"Carmen Torres Lopez">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 29,month => 1,year => 2018}}}, | ||
| {jezaman,{<<"Jesse Zaman">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 5,month => 2,year => 2018}}}, | ||
| {mvdcamme,{<<"Maarten Vandercammen">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 12,month => 2,year => 2018}}}, | ||
| {lachrist,{<<"Laurent Christophe">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 19,month => 2,year => 2018}}}, | ||
| {marmat,{<<"Matteo Marra">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 26,month => 2,year => 2018}}}, | ||
| {noah,{<<"Noah Van Es">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 5,month => 3,year => 2018}}}, | ||
| {svdvonde,{<<"Sam Van den Vonder">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 12,month => 3,year => 2018}}}, | ||
| {humberto,{<<"Humberto Rodriguez">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 19,month => 3,year => 2018}}}, | ||
| {cdetroye,{<<"Christophe De Troyer">>, | ||
| #{'__struct__' => 'Elixir.Date',calendar => 'Elixir.Calendar.ISO', | ||
| day => 26,month => 3,year => 2018}}}, | ||
| {elisagboix,{<<"Elisa Gonzalez">>, | ||
| #{'__struct__' => 'Elixir.Date', | ||
| calendar => 'Elixir.Calendar.ISO',day => 2,month => 4, | ||
| year => 2018}}}]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| [{'U03K40ETE',<<"Humberto Rodriguez">>}, | ||
| {'U08DX089E',<<"Christophe De Troyer">>}, | ||
| {'U02D6HWS1',<<"Elisa Gonzalez Boix">>}, | ||
| {'U0LV04PPT',<<"Ward Muylaert">>}, | ||
| {'U02C3FMQ2',<<"Wolfgang De Meuter">>}, | ||
| {'U94HUEHLJ',<<"Thomas Dupriez">>}, | ||
| {'U8PGUSQ3F',<<"Dario Di Nucci">>}, | ||
| {'U02QPK57T',<<"Coen De Roover">>}, | ||
| {'U02J6647B',<<"Mathijs Saey">>}, | ||
| {'U02J62LRF',<<"Thierry Renaux">>}, | ||
| {'U02BYG1E9',<<"Kevin Pinte">>}, | ||
| {'U02MXLBFX',<<"Florian Myter">>}, | ||
| {'U03QXV0QJ',<<"Tim Molderez">>}, | ||
| {'U03SKNNFB',<<"Joeri De Koster">>}, | ||
| {'U21S584KW',<<"Sam Van den Vonder">>}, | ||
| {'U02C2C9BD',<<"Nathalie Oostvogels">>}, | ||
| {'U02C3M0CL',<<"Janwillem Swalens">>}, | ||
| {'U02C36Q3E',<<"Jens Nicolay">>}, | ||
| {'U02J62SFM',<<"Kennedy Kambona">>}, | ||
| {'U02J7ERTW',<<"Quentin Stievenart">>}, | ||
| {'U02C53L03',<<"Dirk van Deun">>}, | ||
| {'U21RHEHR7',<<"Jonas De Bleser">>}, | ||
| {'U21SQKEFL',<<"Nils Van Geele">>}, | ||
| {'U0QSNFR96',<<"Angel Luis Scull Pupo">>}, | ||
| {'U15B9LJHL',<<"Carmen Torres">>}, | ||
| {'U02C36WBA',<<"Jesse Zaman">>}, | ||
| {'U088RMBMY',<<"Maarten Vandercammen">>}, | ||
| {'U03U17WCQ',<<"Laurent Christophe">>}, | ||
| {'U4U6994KG',<<"Matteo Marra">>}, | ||
| {'U6X6VGMF1',<<"Noah Van Es">>}, | ||
| {'U21S584KW',<<"Sam Van den Vonder">>}, | ||
| {'U6SH5G347',<<"Isaac Oteyo">>}, | ||
| {'U758VEE2E',<<"Yunior Pacheco Correa">>}]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| defmodule Bot.DiswasherManager do | ||
| require Logger | ||
| use Plugin | ||
|
|
||
| @boss Application.fetch_env!(:slack, :diswasher_duties_owner) | ||
| @channel Application.fetch_env!(:slack, :diswasher_duties_channel) | ||
| @private_channel :dishwasher_app | ||
| @channels [@channel, @private_channel ] | ||
|
|
||
| # The message "swap_with @x" is used to swap weekly duties with the user `x`. | ||
| def on_message(<<"swap_with"::utf8, user::bitstring>>, _channel, sender) do | ||
| user = String.trim(user) | ||
| case Brain.DishwasherManager.swap_duties(sender, user) do | ||
| :ok -> SlackManager.send_private_message("You swapped your dishwasher duties with @#{sender}.", user) | ||
| {:ok, "Duties swapped!"} | ||
| {:error, msg} -> {:ok, msg} | ||
| end | ||
| end | ||
|
|
||
| # The message "manager?" return the name uf the current dishwasher manager | ||
| def on_message(<<"manager?"::utf8>>, _channel, _sender) do | ||
| {:ok, manager, fullname} = Brain.DishwasherManager.manager?() | ||
|
|
||
| case manager do | ||
| :no_specified -> {:ok, "The schedule has not been created. Use the command 'help' for more information."} | ||
| _name -> {:ok, "The current dishwasher manager is `#{fullname}`"} | ||
| end | ||
| end | ||
|
|
||
| def on_message(<<"when?"::utf8>>, _channel, sender) do | ||
| {:ok, fullname, startDate} = Brain.DishwasherManager.when?(sender) | ||
|
|
||
| case fullname do | ||
| :invalid_user -> {:ok, "The schedule has not been created. Use the command 'help' for more information."} | ||
|
|
||
| _ -> from = Date.to_string(startDate) | ||
| to = startDate |> Date.add(4) |> Date.to_string() | ||
| {:ok, "Your next dishwasher duties will be from `#{from}` to `#{to}`"} | ||
| end | ||
| end | ||
|
|
||
| # Prints out all the outstanding orders. | ||
| # Restricted to admins only. | ||
| def on_message(<<"schedule"::utf8, _::bitstring>>, channel, _sender) when channel in @channels do | ||
| {:ok, schedule} = Brain.DishwasherManager.schedule() | ||
| build_schedule_list(schedule) | ||
| end | ||
|
|
||
| # Prints out all the outstanding orders. | ||
| # Restricted to admins only. | ||
| def on_message(<<"create_schedule"::utf8, startDate::bitstring>>, channel, @boss) when channel in @channels do | ||
| {:ok, schedule} = Brain.DishwasherManager.create_schedule(startDate) | ||
| build_schedule_list(schedule) | ||
| end | ||
|
|
||
| def on_message(<<"users"::utf8, _::bitstring>>, channel, @boss) when channel in @channels do | ||
| {:ok, users} = Brain.DishwasherManager.users() | ||
| build_user_list(users) | ||
| end | ||
|
|
||
| def on_message(<<"add_user"::utf8, userDetails::bitstring>>, channel, @boss) when channel in @channels do | ||
| case String.split(userDetails) do | ||
| [] -> {:noreply} | ||
| [user| fullname] -> :ok = Brain.DishwasherManager.add_user(user, fullname) | ||
| {:ok, "The user {#{user}, #{fullname}} has been saved."} | ||
| end | ||
| end | ||
|
|
||
| def on_message(<<"remove_user"::utf8, user::bitstring>>, channel, @boss) when channel in @channels do | ||
| :ok = Brain.DishwasherManager.remove_user(user) | ||
| {:ok, "The user #{user} has been removed."} | ||
| end | ||
|
|
||
| def on_message(<<"remove_users"::utf8>>, channel, @boss) when channel in @channels do | ||
| :ok = Brain.DishwasherManager.remove_users() | ||
| {:ok, "The user list was removed."} | ||
| end | ||
|
|
||
| def on_message(<<"remove_schedule"::utf8>>, channel, @boss) when channel in @channels do | ||
| :ok = Brain.DishwasherManager.remove_schedule() | ||
| {:ok, "The schedule was removed."} | ||
| end | ||
|
|
||
| def on_message(<<"set_manager"::utf8>>, channel, @boss) when channel in @channels do | ||
| {:ok, manager} = Brain.DishwasherManager.set_manager_of_the_week() | ||
| case manager do | ||
| :no_specified -> {:ok, "The schedule has not been created. Use the command 'help' for more information."} | ||
| name -> {:ok, "The current dishwasher manager is `#{name}`"} | ||
| end | ||
| end | ||
|
|
||
| def on_message(<<"wave"::utf8>>, channel, _sender) when channel in @channels do | ||
| wave_dishwasher_manager() | ||
| end | ||
|
|
||
| def on_message(<<":wave:"::utf8>>, channel, _sender) when channel in @channels do | ||
| wave_dishwasher_manager() | ||
| end | ||
|
|
||
| # Prints out help message. | ||
| def on_message(<<"help"::utf8>>, channel, @boss) when channel in @channels do | ||
| res = boss_help_menu() | ||
| {:ok, res} | ||
| end | ||
|
|
||
| # Prints out help message. | ||
| def on_message(<<"help"::utf8>>, channel, _sender) when channel in @channels do | ||
| res = user_help_menu() | ||
| {:ok, res} | ||
| end | ||
|
|
||
| def on_message(_text, _channel, _sender) do | ||
| {:noreply} | ||
| end | ||
|
|
||
|
|
||
| defp build_schedule_list(schedule) when schedule == %{} , do: {:ok, "There is no schedule ready. Use the command 'help' for more information."} | ||
|
|
||
| defp build_schedule_list(schedule) do | ||
| resp = schedule | ||
| |> Enum.map(fn {_k,{fullname, from}} -> | ||
| "- #{fullname} -> from: #{from} to: #{Date.add(from, 4)}" end) | ||
| |> Enum.join("\n") | ||
|
|
||
| {:ok, "```#{resp}```"} | ||
| end | ||
|
|
||
| defp build_user_list(users) when users == %{} , do: {:ok, "The list of user is empty. Use the command 'help' for more information."} | ||
|
|
||
| defp build_user_list(users) do | ||
| resp = users | ||
| |> Enum.map(fn {_, fullname} -> "- #{fullname}" end) | ||
| |> Enum.join("\n") | ||
|
|
||
| {:ok, "```#{resp}```"} | ||
| end | ||
|
|
||
| defp user_help_menu do | ||
| """ | ||
| ``` | ||
| swap_with : Swaps weekly duties with another person. | ||
| Example: "swap_with @cdtroye". | ||
| manager? : Shows the current dishwasher manager. | ||
| Example: "manager?" | ||
| schedule : Shows the current dishwasher schedule. | ||
| Example: "schedule" | ||
| wave : Sends a notification to the current dishwasher manager in case he has to do his duties. | ||
| Example: "wave" or ":wave:" | ||
| when? : Shows the dates of your the next dishwasher duties. | ||
| Example: "when? " | ||
| ``` | ||
|
|
||
| """ | ||
| end | ||
|
|
||
| defp boss_help_menu do | ||
| """ | ||
| ``` | ||
| swap_with : Swaps weekly duties with another person. | ||
| Example: "swap_with @cdtroye". | ||
| manager? : Shows the current dishwasher manager. | ||
| Example: "manager?" | ||
| schedule : Shows the current dishwasher schedule. | ||
| Example: "schedule" | ||
| create_schedule : Creates a dishwasher schedule starting from the date specified. | ||
| Example: "create_schedule 2017-09-07" | ||
| users : Shows the current list of users. | ||
| Example: "users" | ||
| add_user : Add a new user. The first argument is the "slack user name", | ||
| followed by its fullname. | ||
| Example: "add_user @humberto Humberto Rodriguez Avila" | ||
| remove_user : Remove an user. | ||
| Example: "remove_user @humberto" | ||
| set_manager : Set the manager for the current week. | ||
| Example: "set_manager" | ||
| ``` | ||
|
|
||
| """ | ||
| end | ||
|
|
||
|
|
||
| defp wave_dishwasher_manager do | ||
| {:ok, manager, fullname} = Brain.DishwasherManager.manager?() | ||
|
|
||
| case manager do | ||
| :no_specified -> {:ok, "As the schedule has not been created, there is not Dishwasher Manager."} | ||
| _name -> SlackManager.send_private_message(":wave: Hey Dishwasher Manager! Please do your dishwasher duties as soon as you can.", manager) | ||
| {:ok, "The current dishwasher manager `#{fullname}` was :wave:"} | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be hardcoded in here?