discord message attachments.
parent
37feac6295
commit
65dad89f5e
|
@ -117,14 +117,35 @@ defmodule Discordirc.Formatter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_discord(user, msg) do
|
def format_member_nick(msg) do
|
||||||
usr = "#{user.username}\##{user.discriminator}"
|
user = msg.author
|
||||||
|
{:ok, member} = DiscordAPI.get_guild_member(msg.guild_id, user.id())
|
||||||
|
|
||||||
messages =
|
if is_binary(member.nick) do
|
||||||
msg
|
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")
|
|> String.split("\n")
|
||||||
|> Enum.map(&fixdiscordidstrings(&1))
|
|> Enum.map(&fixdiscordidstrings(&1))
|
||||||
|
|
||||||
|
apart =
|
||||||
|
attachments
|
||||||
|
|> Enum.map(& &1.url)
|
||||||
|
|
||||||
|
messages =
|
||||||
|
(cpart ++ apart)
|
||||||
|
|> Enum.filter(&(&1 != ""))
|
||||||
|
|
||||||
# discord may give... many lines. split and format.
|
# discord may give... many lines. split and format.
|
||||||
case Enum.count(messages) do
|
case Enum.count(messages) do
|
||||||
0 ->
|
0 ->
|
||||||
|
|
|
@ -67,7 +67,7 @@ defmodule Discordirc.IRC do
|
||||||
|
|
||||||
def handle_info({:discordmsg, msg}, state) do
|
def handle_info({:discordmsg, msg}, state) do
|
||||||
channel = ChannelMap.irc(msg.channel_id)
|
channel = ChannelMap.irc(msg.channel_id)
|
||||||
response = Formatter.from_discord(msg.author, msg.content)
|
response = Formatter.from_discord(msg)
|
||||||
|
|
||||||
case channel do
|
case channel do
|
||||||
{:ok, _, chan} ->
|
{:ok, _, chan} ->
|
||||||
|
|
Loading…
Reference in New Issue