diff options
Diffstat (limited to '')
-rw-r--r-- | lib/plugins/link/html.ex | 13 | ||||
-rw-r--r-- | lib/plugins/preums.ex | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/plugins/link/html.ex b/lib/plugins/link/html.ex index 1173526..7df1bfc 100644 --- a/lib/plugins/link/html.ex +++ b/lib/plugins/link/html.ex @@ -30,9 +30,10 @@ defmodule Nola.Plugins.Link.HTML do defp generate_text_from_opengraph(url, html, opengraph) do itemprops = collect_itemprops(html) prefix = collect_prefix_and_site_name(url, opengraph, itemprops) - description = collect_description(opengraph, itemprops, 400) + title = Map.get(opengraph, "title") + description = collect_description(opengraph, itemprops, title, 400) - [clean_text("#{prefix}#{Map.get(opengraph, "title")}")] ++ description + [clean_text("#{prefix}#{title}")] ++ description end defp collect_title(html) do @@ -114,11 +115,15 @@ defmodule Nola.Plugins.Link.HTML do if section, do: ": #{section}", else: "" end - defp collect_description(opengraph, itemprops, max_length) do + defp collect_description(opengraph, itemprops, title, max_length) do date = get_formatted_date(opengraph, itemprops) description = transform_description(Map.get(opengraph, "description"), max_length) - Nola.Irc.Message.splitlong(clean_text("#{date}#{description}")) + cond do + title == description -> date + String.jaro_distance(title, description) > 0.8 -> date + true -> Nola.Irc.Message.splitlong(clean_text("#{date}#{description}")) + end end defp get_formatted_date(opengraph, itemprops) do diff --git a/lib/plugins/preums.ex b/lib/plugins/preums.ex index 5891ab3..cee3dcc 100644 --- a/lib/plugins/preums.ex +++ b/lib/plugins/preums.ex @@ -36,6 +36,7 @@ defmodule Nola.Plugins.Preums do # - ? require Logger + alias Timex.Format.DateTime.Formatters # dets {{chan, day = {yyyy, mm, dd}}, nick, now, perfect?, text} @@ -157,7 +158,7 @@ defmodule Nola.Plugins.Preums do if item do {_, account_id, date, _perfect, text} = item - h = "#{date.hour}:#{date.minute}:#{date.second}" + {:ok, h} = Formatters.Default.lformat(date, "{h24}:{m}:{s}", "fr") account = Nola.Account.get(account_id) user = Nola.UserTrack.find_by_account(m.network, account) nick = if(user, do: user.nick, else: account.name) |