Fix small bug with linkbot where Regex.scan() would return a list of lists, instead of a list of strings

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-06-14 18:10:10 -04:00
parent 4b269675d5
commit 7f6a5e8a90

View File

@@ -3,7 +3,6 @@ defmodule Omnibot.Contrib.Linkbot do
require Logger
@default_config timeout: 30_000
@hostname_blacklist ~r/(^localhost$|\.local$|\.localdomain$|\.home$|^[^.]+$|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$)/i
def blacklisted?(url) do
@@ -23,6 +22,7 @@ defmodule Omnibot.Contrib.Linkbot do
def get_title(url) do
if should_get?(url) do
Logger.info("Fetching #{url}")
resp = get!(url)
%{"title" => title} = Regex.named_captures(@title_regex, resp.body)
title
@@ -46,6 +46,7 @@ defmodule Omnibot.Contrib.Linkbot do
@impl true
def on_channel_msg(irc, channel, _nick, line) do
Regex.scan(@url_regex, line)
|> Enum.flat_map(& &1)
|> Enum.map(fn url -> Client.get_title(url) end)
|> Enum.each(fn title -> Irc.send_to(irc, channel, title) end)
end