Browse Source

add time functions

Steven Jacobs 3 years ago
parent
commit
c8c7a0a86b
3 changed files with 60 additions and 42 deletions
  1. 23 9
      lib/incidentctl/slack.ex
  2. 1 0
      mix.exs
  3. 36 33
      mix.lock

+ 23 - 9
lib/incidentctl/slack.ex

@@ -8,12 +8,7 @@ defmodule Incidentctl.Slack do
 
   def handle_event(message = %{type: "message"}, slack, state) do
     if message_for_me?(message.text, slack.me.id) do
-      random_number = Integer.to_string(:rand.uniform(999_999))
-      channel_name = "inc-#{random_number}-190418"
-
-      %{"channel" => %{"id" => channel_id}} = create_channel(channel_name)
-
-      send_message("<##{channel_id}> created.", message.channel, slack)
+      create_channel("bar", message, slack)
     end
 
     {:ok, state}
@@ -57,8 +52,27 @@ defmodule Incidentctl.Slack do
     |> length > 0
   end
 
-  def create_channel(name) do
-    name
-    |> Slack.Web.Channels.create()
+  def get_command(message_text, id) do
+    message_text
+    |> String.split("\n")
+    |> Enum.filter(&String.match?(&1, ~r/^(<@#{id}>)/))
+    |> String.split
+  end
+
+
+  def create_channel(name, message, slack) do
+    import Timex
+
+    date_slug = DateTime.utc_now()
+      |> Timex.Timezone.convert("America/New_York")
+      |> Timex.format!("{YY}{0M}{0D}")
+
+    channel_name = "inc-#{name}-#{date_slug}"
+
+    %{"channel" => %{"id" => channel_id}} = Slack.Web.Channels.create(channel_name)
+
+    send_message("<##{channel_id}> created.", message.channel, slack)
+
+    channel_id
   end
 end

+ 1 - 0
mix.exs

@@ -43,6 +43,7 @@ defmodule Incidentctl.MixProject do
       {:gettext, "~> 0.11"},
       {:jason, "~> 1.0"},
       {:plug_cowboy, "~> 2.0"},
+      {:timex, "~> 3.5"},
       {:slack, github: "BlakeWilliams/Elixir-Slack", ref: "4812cf8"}
       # {:slack, "~> 0.18.0"}
     ]

File diff suppressed because it is too large
+ 36 - 33
mix.lock