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)