Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F77350
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
View Options
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
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jul 7, 2:52 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
49823
Default Alt Text
(3 KB)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment