diff options
author | Jordan Bracco <href@random.sh> | 2022-12-20 12:26:05 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-20 19:29:42 +0100 |
commit | 122d17eb016ab52a705ef3cc9a6cf202b56f3fbf (patch) | |
tree | fe6dbc2ce62e0c80f20c49b2cf1b836ac103bab2 | |
parent | Rename IRC.{Connection,PuppetConnection} to Nola.Irc.{Connection,PuppetConnec... (diff) |
chore(plugins)!: remove deprecated outline plugin, refs T77.
-rw-r--r-- | lib/plugins/outline.ex | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/lib/plugins/outline.ex b/lib/plugins/outline.ex deleted file mode 100644 index ba8314d..0000000 --- a/lib/plugins/outline.ex +++ /dev/null @@ -1,108 +0,0 @@ -defmodule Nola.Plugins.Outline do - @moduledoc """ - # outline auto-link - - Envoie un lien vers Outline quand un lien est envoyé. - - * **!outline `<url>`** crée un lien outline pour `<url>`. - * **+outline `<host>`** active outline pour `<host>`. - * **-outline `<host>`** désactive outline pour `<host>`. - """ - def short_irc_doc, do: false - def irc_doc, do: @moduledoc - require Logger - - def start_link() do - GenServer.start_link(__MODULE__, [], name: __MODULE__) - end - - defstruct [:file, :hosts] - - def init([]) do - regopts = [plugin: __MODULE__] - {:ok, _} = Registry.register(Nola.PubSub, "trigger:outline", regopts) - {:ok, _} = Registry.register(Nola.PubSub, "messages", regopts) - file = Path.join(Nola.data_path, "/outline.txt") - hosts = case File.read(file) do - {:error, :enoent} -> - [] - {:ok, lines} -> - String.split(lines, "\n", trim: true) - end - {:ok, %__MODULE__{file: file, hosts: hosts}} - end - - def handle_info({:irc, :trigger, "outline", message = %Nola.Message{trigger: %Nola.Trigger{type: :plus, args: [host]}}}, state) do - state = %{state | hosts: [host | state.hosts]} - save(state) - message.replyfun.("ok") - {:noreply, state} - end - - def handle_info({:irc, :trigger, "outline", message = %Nola.Message{trigger: %Nola.Trigger{type: :minus, args: [host]}}}, state) do - state = %{state | hosts: List.delete(state.hosts, host)} - save(state) - message.replyfun.("ok") - {:noreply, state} - end - - def handle_info({:irc, :trigger, "outline", message = %Nola.Message{trigger: %Nola.Trigger{type: :bang, args: [url]}}}, state) do - line = "-> #{outline(url)}" - message.replyfun.(line) - end - - def handle_info({:irc, :text, message = %Nola.Message{text: text}}, state) do - String.split(text) - |> Enum.map(fn(word) -> - if String.starts_with?(word, "http://") || String.starts_with?(word, "https://") do - uri = URI.parse(word) - if uri.scheme && uri.host do - if Enum.any?(state.hosts, fn(host) -> String.ends_with?(uri.host, host) end) do - outline_url = outline(word) - line = "-> #{outline_url}" - message.replyfun.(line) - end - end - end - end) - {:noreply, state} - end - - def handle_info(msg, state) do - {:noreply, state} - end - - def save(state = %{file: file, hosts: hosts}) do - string = Enum.join(hosts, "\n") - File.write(file, string) - end - - def outline(url) do - unexpanded = "https://outline.com/#{url}" - headers = [ - {"User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0"}, - {"Accept", "*/*"}, - {"Accept-Language", "en-US,en;q=0.5"}, - {"Origin", "https://outline.com"}, - {"DNT", "1"}, - {"Referer", unexpanded}, - {"Pragma", "no-cache"}, - {"Cache-Control", "no-cache"} - ] - params = %{"source_url" => url} - case HTTPoison.get("https://api.outline.com/v3/parse_article", headers, params: params) do - {:ok, %HTTPoison.Response{status_code: 200, body: json}} -> - body = Poison.decode!(json) - if Map.get(body, "success") do - code = get_in(body, ["data", "short_code"]) - "https://outline.com/#{code}" - else - unexpanded - end - error -> - Logger.info("outline.com error: #{inspect error}") - unexpanded - end - end - -end |