diff options
Diffstat (limited to 'lib/lsg_irc/txt_plugin/markov_py_markovify.ex')
-rw-r--r-- | lib/lsg_irc/txt_plugin/markov_py_markovify.ex | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/lsg_irc/txt_plugin/markov_py_markovify.ex b/lib/lsg_irc/txt_plugin/markov_py_markovify.ex new file mode 100644 index 0000000..a3838cd --- /dev/null +++ b/lib/lsg_irc/txt_plugin/markov_py_markovify.ex @@ -0,0 +1,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 |