From fd7908d432c17dc85d54366256a3c70225d4773b Mon Sep 17 00:00:00 2001 From: "Rachel Fae Fox (foxiepaws)" Date: Fri, 4 Sep 2020 06:04:38 -0400 Subject: [PATCH] avoid redoing webhooks --- lib/discordhandler.ex | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/discordhandler.ex b/lib/discordhandler.ex index 5bedacb..d0aaff8 100644 --- a/lib/discordhandler.ex +++ b/lib/discordhandler.ex @@ -7,10 +7,28 @@ defmodule Discordirc.DiscordHandler do Consumer.start_link(__MODULE__) end + + def is_me_or_my_webhook(msg) do + {:ok, me} = api.get_current_user() + + is_me = msg.author.username == me.username and msg.author.discriminator == me.discriminator + is_webhook = msg.webhook_id != nil + + is_my_webhook = + if is_webhook do + {:ok, wh} = api.get_webhook(msg.webhook_id) + wh.user.id == nostrum.snowflake.dump(me.id) + else + false + end + + is_me or is_my_webhook + end + def handle_event({:MESSAGE_CREATE, msg, _ws_state}) do {:ok, me} = Api.get_current_user() - unless msg.author.username == me.username and msg.author.discriminator == me.discriminator do + unless is_me_or_my_webhook(msg) do case ChannelMap.irc(msg.channel_id) do {:ok, net, _} -> pid = String.to_atom(net)