summaryrefslogblamecommitdiff
path: root/lib/nola_plugins/txt_plugin/markov_py_markovify.ex
blob: b610ea8ee8880f494ff7d448dd5e48e5417b4b1c (plain) (tree)
1
                                                 


















                                       
                                                                       







                                                      

                                                                                







                                                                                     
defmodule Nola.IRC.TxtPlugin.MarkovPyMarkovify do

  def start_link() do
    {:ok, nil}
  end

  def reload(_data, _markov) do
    :ok
  end

  def sentence(_) do
    {:ok, run()}
  end

  def complete_sentence(sentence, _) do
    {:ok, run([sentence])}
  end

  defp run(args \\ []) do
    {binary, script} = script()
    args = [script, Path.expand(Nola.IRC.TxtPlugin.directory()) | args]
    IO.puts "Args #{inspect args}"
    case MuonTrap.cmd(binary, args) do
      {response, 0} -> response
      {response, code} -> "error #{code}: #{response}"
    end
  end

  defp script() do
    default_script = to_string(:code.priv_dir(:nola)) <> "/irc/txt/markovify.py"
    env = Application.get_env(:nola, Nola.IRC.TxtPlugin, [])
    |> Keyword.get(:py_markovify, [])

    {Keyword.get(env, :python, "python3"), Keyword.get(env, :script, default_script)}
  end



end