discord message attachments.

master
Rachel Fae Fox (foxiepaws) 2020-07-17 03:24:44 -04:00
parent 37feac6295
commit 65dad89f5e
2 changed files with 26 additions and 5 deletions

View File

@ -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 ->

View File

@ -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} ->