blob: a3838cd2771d0da802cb23a72a302e148a2a66fe (
plain) (
tree)
|
|
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
|