From 9ce8f9a8990362818659b8f5f3f07ed73b22deb3 Mon Sep 17 00:00:00 2001 From: techgaun Date: Tue, 16 Aug 2016 23:05:55 -0500 Subject: [PATCH] standup stuffs closes #1 --- config/config.exs | 4 +++- lib/ex_mustang/responders/standup.ex | 13 ++++++++++++- lib/ex_mustang/robot.ex | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index 8bab1de..81ce33d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,7 +4,9 @@ use Mix.Config config :ex_mustang, ExMustang.Responders.Standup, time_of_day: "30 10 * * 1-5", - slack_channel: System.get_env("STANDUP_CHANNEL") || "general" + slack_channel: System.get_env("STANDUP_CHANNEL") || "general", + suffix: ["folks", "hackers", "peeps", "avengers"], + msg: "Standup time" config :ex_mustang, ExMustang.Responders.Github, repos: ["techgaun/ex_mustang"], diff --git a/lib/ex_mustang/responders/standup.ex b/lib/ex_mustang/responders/standup.ex index 13547bd..dc5745f 100644 --- a/lib/ex_mustang/responders/standup.ex +++ b/lib/ex_mustang/responders/standup.ex @@ -3,7 +3,18 @@ defmodule ExMustang.Responders.Standup do Module that sends message when its Standup time """ + @doc """ + Function to call for sending standup notice + """ def run do - + msg = %Hedwig.Message{ + type: "message", + room: "#{config[:slack_channel]}", + text: "#{config[:msg]}, #{Hedwig.Responder.random(config[:suffix])}!", + } + pid = Hedwig.whereis("mustang") + Hedwig.Robot.send(pid, msg) end + + defp config, do: Application.get_env(:ex_mustang, ExMustang.Responders.Standup) end diff --git a/lib/ex_mustang/robot.ex b/lib/ex_mustang/robot.ex index 4cc72a0..49d7e73 100644 --- a/lib/ex_mustang/robot.ex +++ b/lib/ex_mustang/robot.ex @@ -1,3 +1,9 @@ defmodule ExMustang.Robot do use Hedwig.Robot, otp_app: :ex_mustang + + def after_connect(state) do + Hedwig.Registry.register(state.name) + + {:ok, state} + end end