summaryrefslogtreecommitdiff
path: root/lib/nola_plugins/txt_plugin/markov_py_markovify.ex
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 00:21:54 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:41 +0100
commit2d83df8b32bff7f0028923bb5b64dc0b55f20d03 (patch)
tree1207e67b5b15f540963db05e7be89f3ca950e724 /lib/nola_plugins/txt_plugin/markov_py_markovify.ex
parentNola rename, the end. pt 6. Refs T77. (diff)
Nola rename: The Big Move, Refs T77
Diffstat (limited to 'lib/nola_plugins/txt_plugin/markov_py_markovify.ex')
-rw-r--r--lib/nola_plugins/txt_plugin/markov_py_markovify.ex39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/nola_plugins/txt_plugin/markov_py_markovify.ex b/lib/nola_plugins/txt_plugin/markov_py_markovify.ex
new file mode 100644
index 0000000..b610ea8
--- /dev/null
+++ b/lib/nola_plugins/txt_plugin/markov_py_markovify.ex
@@ -0,0 +1,39 @@
+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