forgot to mix format
parent
4f6cc19c40
commit
0421ec9264
|
@ -8,6 +8,7 @@ defmodule Discordirc.DiscordInfo do
|
|||
case Api.get_guild_member(guild_id, id) do
|
||||
{:ok, x = %{nick: nil}} ->
|
||||
"#{x.user.username}##{x.user.discriminator}"
|
||||
|
||||
{:ok, %{nick: n}} ->
|
||||
n
|
||||
end
|
||||
|
@ -22,12 +23,13 @@ defmodule Discordirc.DiscordInfo do
|
|||
{: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
|
||||
|
|
|
@ -30,13 +30,17 @@ 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_nick_by_id(guild, i)}
|
||||
|
||||
"@&" ->
|
||||
{match, "@" <> DiscordInfo.get_role_name_by_id(guild, i)}
|
||||
end
|
||||
|
@ -46,6 +50,7 @@ defmodule Discordirc.Formatter do
|
|||
{fst, snd} = head
|
||||
do_replace(String.replace(str, fst, snd, global: true), tail)
|
||||
end
|
||||
|
||||
def do_replace(str, []) do
|
||||
str
|
||||
end
|
||||
|
@ -56,11 +61,10 @@ defmodule Discordirc.Formatter do
|
|||
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,8 +55,10 @@ defmodule Discordirc.WebhookService do
|
|||
|
||||
30_007 when retry >= 1 ->
|
||||
raise "too many webhooks"
|
||||
|
||||
40_001 ->
|
||||
raise "no permissions"
|
||||
|
||||
50_035 ->
|
||||
raise "invalid form body"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue