summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/txt_plugin/markov_py_markovify.ex
blob: a3838cd2771d0da802cb23a72a302e148a2a66fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule LSG.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(LSG.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(:lsg)) <> "/irc/txt/markovify.py"
    env = Application.get_env(:lsg, LSG.IRC.TxtPlugin, [])
    |> Keyword.get(:py_markovify, [])

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



end