sticker_items is nil, not [], when empty...

master
Rachel Fae Fox 2022-11-10 11:07:54 -05:00
parent 6d99d07514
commit 83ae20c041
1 changed files with 34 additions and 0 deletions

View File

@ -69,6 +69,40 @@ defmodule Discordirc.Formatter do
|> do_replace(matches)
end
def from_discord(
%{attachments: attachments, author: user, guild_id: guild, sticker_items: nil} = msg
) do
usr =
case DiscordAPI.get_guild_member(guild, user.id) do
{:ok, %{nick: nick}} when is_binary(nick) -> nick
_ -> "#{user.username}\##{user.discriminator}"
end
cpart =
msg
|> fixdiscordidstrings
|> String.split("\n")
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 ->
{usr, "#{messages[0]}"}
_ ->
{usr,
messages
|> Enum.map(fn m -> "#{m}" end)}
end
end
def from_discord(
%{attachments: attachments, author: user, guild_id: guild, sticker_items: stickers} = msg
) do