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

View File

@ -8,6 +8,7 @@ defmodule Discordirc.ByteSplit do
@doc """
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
case byte_size(str) do
n when is_integer(n) and n > bytes ->

View File

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