Compare commits

...

3 Commits

Author SHA1 Message Date
Rachel Fae Fox 6d99d07514 implements links to stickers. fix's #5, works on #6 2022-11-10 10:33:56 -05:00
Rachel Fae Fox dd072964ae mix format run 2022-11-10 10:33:36 -05:00
Rachel Fae Fox ca07be9b86 fixes "invalid form body" from webhook
discord doesn't let "discord" exist in webhooks anymore. end all.
I may have to add a special rule to have the bot post a message
instead of a webhook service if someone has "discord" in their
nick.
2022-11-10 10:31:02 -05:00
3 changed files with 13 additions and 6 deletions

View File

@ -5,6 +5,8 @@ defmodule Discordirc.Formatter do
alias Nostrum.Api, as: DiscordAPI alias Nostrum.Api, as: DiscordAPI
alias Discordirc.DiscordInfo alias Discordirc.DiscordInfo
@discordcdn "https://cdn.discordapp.com/"
def from_irc(nick, msg, ctcp \\ false) do def from_irc(nick, msg, ctcp \\ false) do
# strip or replace IRC formatting. # strip or replace IRC formatting.
fmsg = fmsg =
@ -67,9 +69,9 @@ defmodule Discordirc.Formatter do
|> do_replace(matches) |> do_replace(matches)
end end
def from_discord(msg) do def from_discord(
%{attachments: attachments, author: user, guild_id: guild} = msg %{attachments: attachments, author: user, guild_id: guild, sticker_items: stickers} = msg
) do
usr = usr =
case DiscordAPI.get_guild_member(guild, user.id) do case DiscordAPI.get_guild_member(guild, user.id) do
{:ok, %{nick: nick}} when is_binary(nick) -> nick {:ok, %{nick: nick}} when is_binary(nick) -> nick
@ -85,8 +87,12 @@ defmodule Discordirc.Formatter do
attachments attachments
|> Enum.map(& &1.url) |> Enum.map(& &1.url)
spart =
stickers
|> Enum.map(fn s -> "#{@discordcdn}stickers/#{s.id}.png" end)
messages = messages =
(cpart ++ apart) (cpart ++ apart ++ spart)
|> Enum.filter(&(&1 != "")) |> Enum.filter(&(&1 != ""))
# discord may give... many lines. split and format. # discord may give... many lines. split and format.

View File

@ -8,6 +8,7 @@ defmodule Discordirc.ByteSplit do
@doc """ @doc """
split a string into a number `bytes`, optionally subtracting a number of `hold` bytes for prefix/suffix split a string into a number `bytes`, optionally subtracting a number of `hold` bytes for prefix/suffix
""" """
def byte_split(str, bytes, hold \\ 0) do def byte_split(str, bytes, hold \\ 0) do
case byte_size(str) do case byte_size(str) do
n when is_integer(n) and n > bytes -> n when is_integer(n) and n > bytes ->

View File

@ -31,8 +31,8 @@ defmodule Discordirc.WebhookService do
case DiscordAPI.create_webhook( case DiscordAPI.create_webhook(
channel_id, channel_id,
%{name: "discordirc hook", avatar: avatar}, %{name: "irc relay hook", avatar: avatar},
"discordirc proxy hook" "irc relay hook"
) do ) do
{:ok, hook} -> {:ok, hook} ->
case state.hooks do case state.hooks do