forgot to mix format
parent
4f6cc19c40
commit
0421ec9264
|
@ -7,9 +7,10 @@ defmodule Discordirc.DiscordInfo do
|
|||
def get_nick_by_id(guild_id, id) do
|
||||
case Api.get_guild_member(guild_id, id) do
|
||||
{:ok, x = %{nick: nil}} ->
|
||||
"#{x.user.username}##{x.user.discriminator}"
|
||||
"#{x.user.username}##{x.user.discriminator}"
|
||||
|
||||
{:ok, %{nick: n}} ->
|
||||
n
|
||||
n
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -19,15 +20,16 @@ defmodule Discordirc.DiscordInfo do
|
|||
end
|
||||
|
||||
def get_channel_name_by_id(id) do
|
||||
{:ok, %{name: c}} = Api.get_channel(id)
|
||||
c
|
||||
{:ok, %{name: c}} = Api.get_channel(id)
|
||||
c
|
||||
end
|
||||
|
||||
def get_role_name_by_id(guild_id, id) do
|
||||
{:ok, roles} = Api.get_guild_roles(guild_id)
|
||||
|
||||
roles
|
||||
|> Enum.filter(fn (%{id: i}) -> i == id end)
|
||||
|> List.first
|
||||
|> Enum.filter(fn %{id: i} -> i == id end)
|
||||
|> List.first()
|
||||
|> Map.get(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ defmodule Discordirc.Formatter do
|
|||
"""
|
||||
alias Nostrum.Api, as: DiscordAPI
|
||||
alias Discordirc.DiscordInfo
|
||||
|
||||
|
||||
def from_irc(nick, msg, ctcp \\ false) do
|
||||
# strip or replace IRC formatting.
|
||||
fmsg =
|
||||
|
@ -30,37 +30,41 @@ defmodule Discordirc.Formatter do
|
|||
|
||||
def get_id_info([match, type, id], guild) do
|
||||
i = String.to_integer(id)
|
||||
|
||||
case type do
|
||||
"#" ->
|
||||
{match, "#" <> DiscordInfo.get_channel_name_by_id(i)}
|
||||
"@" ->
|
||||
{match, "@" <> DiscordInfo.get_nick_by_id(guild, i)}
|
||||
{match, "#" <> DiscordInfo.get_channel_name_by_id(i)}
|
||||
|
||||
"@" ->
|
||||
{match, "@" <> DiscordInfo.get_nick_by_id(guild, i)}
|
||||
|
||||
"@!" ->
|
||||
{match, "@" <> DiscordInfo.get_nick_by_id(guild, i)}
|
||||
{match, "@" <> DiscordInfo.get_nick_by_id(guild, i)}
|
||||
|
||||
"@&" ->
|
||||
{match, "@" <> DiscordInfo.get_role_name_by_id(guild, i)}
|
||||
{match, "@" <> DiscordInfo.get_role_name_by_id(guild, i)}
|
||||
end
|
||||
end
|
||||
|
||||
def do_replace(str, [head | tail]) do
|
||||
{fst,snd} = head
|
||||
do_replace(String.replace(str, fst, snd, global: true), tail)
|
||||
{fst, snd} = head
|
||||
do_replace(String.replace(str, fst, snd, global: true), tail)
|
||||
end
|
||||
|
||||
def do_replace(str, []) do
|
||||
str
|
||||
end
|
||||
|
||||
|
||||
def fixdiscordidstrings(%{:content => content, :guild_id => guild}) do
|
||||
pattern = ~r/\<(\@[!&]?|#)(\d+)\>/um
|
||||
|
||||
matches =
|
||||
Regex.scan(pattern, content)
|
||||
|> Enum.uniq()
|
||||
|> Enum.map(&(get_id_info(&1,guild)))
|
||||
|> Enum.map(&get_id_info(&1, guild))
|
||||
|
||||
content
|
||||
|> do_replace(matches)
|
||||
|
||||
end
|
||||
|
||||
def from_discord(msg) do
|
||||
|
|
|
@ -55,10 +55,12 @@ defmodule Discordirc.WebhookService do
|
|||
|
||||
30_007 when retry >= 1 ->
|
||||
raise "too many webhooks"
|
||||
|
||||
40_001 ->
|
||||
raise "no permissions"
|
||||
50_035 ->
|
||||
raise "invalid form body"
|
||||
|
||||
50_035 ->
|
||||
raise "invalid form body"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue