avoid redoing webhooks

master
Rachel Fae Fox (foxiepaws) 2020-09-04 06:04:38 -04:00
parent a29fe329c2
commit fd7908d432
1 changed files with 19 additions and 1 deletions

View File

@ -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)