<commit_before>defmodule SlackBot do
  use WebsocketClient

  def rtm_start do
    token = Application.get_env(:slack_bot, :token)
    opts = add_proxy_opt([])
    res = HTTPoison.get!("https://slack.com/api/rtm.start?token=#{token}", [], opts)

    %{"url" => url} = Poison.decode!(res.body)

    WebsocketClient.start_link(__MODULE__, url)
  end


  defp add_proxy_opt(acc) do
    https_proxy = System.get_env("https_proxy")
    case  https_proxy |> URI.parse do
      %URI{host: proxy_host} when not is_nil(proxy_host) ->
        [{:proxy, https_proxy} | acc]
      _ ->
        acc
    end
  end

  # callback function

  def init(_args) do
    plugins = Enum.map(Application.get_env(:slack_bot, :plugins), fn(%{path: path, mod: mod}) ->
      Code.append_path(path)
      {:module, mod}= Code.ensure_loaded(mod)

      {:ok, pid} = apply(mod, :start, [self])
      {mod, pid}
    end)

    {:ok, %{plugins: plugins}}
  end

  def handle_text(text, %{plugins: plugins} = state) do
    Enum.each(plugins, fn({mod, pid}) ->
      apply(mod, :handle_text, [pid, text])
    end)
    {:ok, state}
  end

end<commit_msg>improve log message<commit_after>defmodule SlackBot do
  use WebsocketClient

  require Logger

  def rtm_start do
    token = Application.get_env(:slack_bot, :token)
    opts = add_proxy_opt([])
    res = HTTPoison.get!("https://slack.com/api/rtm.start?token=#{token}", [], opts)

    %{"url" => url} = Poison.decode!(res.body)

    WebsocketClient.start_link(__MODULE__, url)
  end

  def send_message(pid, msg) do
    
  end

  # callback function

  def init(_args) do
    plugins = Enum.map(Application.get_env(:slack_bot, :plugins), fn %{path: path, mod: mod} ->
      try do
        Code.append_path(path)
        {:module, mod}= Code.ensure_loaded(mod)

        {:ok, pid} = apply(mod, :start, [self])
        {mod, pid}
      rescue
        error ->
          Logger.warn "plugin loading failed: #{mod}, #{error}"
          nil
      end
    end) |> Enum.filter(fn x -> not is_nil(x) end)

    {:ok, %{plugins: plugins}}
  end

  def handle_text(text, %{plugins: plugins} = state) do
    Enum.each(plugins, fn({mod, pid}) ->
      try do
        apply(mod, :handle_text, [pid, text])
      rescue
        error ->
          Logger.warn "#{mod}.handle_text failed: #{error}"
      end
    end)
    {:ok, state}
  end

  # private

  defp add_proxy_opt(acc) do
    https_proxy = System.get_env("https_proxy")
    case  https_proxy |> URI.parse do
      %URI{host: proxy_host} when not is_nil(proxy_host) ->
        Logger.info "use proxy: #{https_proxy}"
        [{:proxy, https_proxy} | acc]
      _ ->
        acc
    end
  end

end
{'fraction_non_alphanumeric': 0.14591951861602107, 'fraction_numerical': 0.0, 'mean_word_length': 2.7150837988826817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1019071', 'n_tokens_mistral': 954, 'n_tokens_neox': 930, 'n_words': 216}