diff --git a/lib/tir_inna_noc/imageboard.ex b/lib/tir_inna_noc/imageboard.ex index 3cfe26c..9a5c3f4 100644 --- a/lib/tir_inna_noc/imageboard.ex +++ b/lib/tir_inna_noc/imageboard.ex @@ -9,7 +9,7 @@ defmodule TirInnaNoc.Imageboard do if GenServer.call(:ratelimiter, :activate) == :goahead do get(uri) else - Process.sleep(1000) + Process.sleep(1_000) wget(uri) end end diff --git a/lib/tir_inna_noc/meldh.ex b/lib/tir_inna_noc/meldh.ex index c6d7edd..f715dd1 100644 --- a/lib/tir_inna_noc/meldh.ex +++ b/lib/tir_inna_noc/meldh.ex @@ -13,32 +13,43 @@ defmodule TirInnaNoc.Meldh do @impl true def handle_info(:update, state) do + IO.puts("upd8ing "<>state.board) {:ok, res} = TirInnaNoc.Imageboard.threads(state.board) res.body |> Enum.each(fn page -> Enum.each(page["threads"], fn thread -> - DynamicSupervisor.start_child( - String.to_atom(state.board<>"Supervisor"), - { - TirInnaNoc.Perenelle, - %TirInnaNoc.Imageboard.Thread{ - board: state.board, - no: thread["no"], - last_update: thread["last_modified"], - reply_number: thread["replies"], - on_page: page["page"] + if state.threads[thread["no"]] == nil do + DynamicSupervisor.start_child( + String.to_atom(state.board<>"Supervisor"), + { + TirInnaNoc.Perenelle, + %TirInnaNoc.Imageboard.Thread{ + board: state.board, + no: thread["no"], + last_update: thread["last_modified"], + reply_number: thread["replies"], + on_page: page["page"] + } } - } - ) + ) + else + send(String.to_atom(state.board<>to_string(thread["no"])<>"Perenelle"), {:update, page["page"], thread["replies"], false}) + end end) end) {:noreply, state} end + def go_forever(proc) do + send(proc, :update) + Process.sleep(60_000) + go_forever(proc) + end + @impl true def init(state) do IO.puts("started meldh to archive board "<>state.board) - send(self(), :update) + Task.start_link(fn -> go_forever(String.to_atom(state.board<>"Meldh")) end) {:ok, state} end end diff --git a/lib/tir_inna_noc/perenelle.ex b/lib/tir_inna_noc/perenelle.ex index 7816096..744a1af 100644 --- a/lib/tir_inna_noc/perenelle.ex +++ b/lib/tir_inna_noc/perenelle.ex @@ -37,6 +37,8 @@ defmodule TirInnaNoc.Perenelle do send(self(), {:addpost, post, sage_status}) end) end + else + IO.puts("NOT UPDATING CUZ THERES NO UPDATE!!") end state = %TirInnaNoc.Imageboard.Thread{state | on_page: new_page, reply_number: new_replynum} send(self(), :save)