diff --git a/lib/formatter.ex b/lib/formatter.ex index 9a67d68..2698400 100644 --- a/lib/formatter.ex +++ b/lib/formatter.ex @@ -117,14 +117,35 @@ defmodule Discordirc.Formatter do end end - def from_discord(user, msg) do - usr = "#{user.username}\##{user.discriminator}" + def format_member_nick(msg) do + user = msg.author + {:ok, member} = DiscordAPI.get_guild_member(msg.guild_id, user.id()) - messages = - msg + if is_binary(member.nick) do + member.nick + else + "#{user.username}\##{user.discriminator}" + end + end + + def from_discord(msg) do + content = msg.content + attachments = msg.attachments + usr = format_member_nick(msg) + + cpart = + content |> String.split("\n") |> Enum.map(&fixdiscordidstrings(&1)) + apart = + attachments + |> Enum.map(& &1.url) + + messages = + (cpart ++ apart) + |> Enum.filter(&(&1 != "")) + # discord may give... many lines. split and format. case Enum.count(messages) do 0 -> diff --git a/lib/irc_bot.ex b/lib/irc_bot.ex index d3b59c9..34bac12 100644 --- a/lib/irc_bot.ex +++ b/lib/irc_bot.ex @@ -67,7 +67,7 @@ defmodule Discordirc.IRC do def handle_info({:discordmsg, msg}, state) do channel = ChannelMap.irc(msg.channel_id) - response = Formatter.from_discord(msg.author, msg.content) + response = Formatter.from_discord(msg) case channel do {:ok, _, chan} ->