diff --git a/config/config.exs b/config/config.exs index 3ee0b57..9bbf02b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,13 +1,13 @@ import Config -config :nostrum, - # The token of your bot as a string - token: System.get_env("DISCORD_TOKEN"), - gateway_intents: [ - :guilds, - :message_content, - :guild_messages - ] +# Nostrum configuration is now handled via bot_options in supervisor +# config :nostrum, +# token: System.get_env("DISCORD_TOKEN"), +# gateway_intents: [ +# :guilds, +# :message_content, +# :guild_messages +# ] config :fruitbot, bots: [ diff --git a/elixir.zip b/elixir.zip new file mode 100644 index 0000000..b10e101 Binary files /dev/null and b/elixir.zip differ diff --git a/lib/fruitbot/nostrum_consumer.ex b/lib/fruitbot/nostrum_consumer.ex index e8aa4ae..96eed06 100644 --- a/lib/fruitbot/nostrum_consumer.ex +++ b/lib/fruitbot/nostrum_consumer.ex @@ -1,35 +1,32 @@ defmodule Fruitbot.NostrumConsumer do @just_a_website_channel_id 918577903258730506 - use Nostrum.Consumer - - # alias Nostrum.Api - - def start_link do - Consumer.start_link(__MODULE__) - end + @behaviour Nostrum.Consumer def handle_event({:MESSAGE_CREATE, msg, ws_state}) do IO.inspect(ws_state) IO.inspect msg IO.puts "new message in channel: #{msg.channel_id}" if msg.channel_id == @just_a_website_channel_id do - # case Fruitbot.Commands.handle_message(msg.content) do - # {:ok, message} -> - # Api.create_message(msg.channel_id, message) - # - # {:error, :bad_command} -> - # # noop - # IO.puts("not a command") - # IO.puts("is it #{msg.author.username} bot: #{msg.author.bot}") - # - if msg.author.bot != true do IO.puts("NOT a bot") send_discord_message(msg) - end + + # Handle commands if message starts with ! + if String.starts_with?(msg.content, "!") do + case Fruitbot.CommandHandler.handle_command(msg.content) do + {:ok, message} -> + Nostrum.Api.Message.create(msg.channel_id, message) - # :ignore - # end + {:error, :bad_command} -> + # noop + IO.puts("not a command") + :ignore + + _ -> + :ignore + end + end + end end end diff --git a/lib/fruitbot/supervisor.ex b/lib/fruitbot/supervisor.ex index d092064..3f8a54f 100644 --- a/lib/fruitbot/supervisor.ex +++ b/lib/fruitbot/supervisor.ex @@ -17,12 +17,24 @@ defmodule Fruitbot.Supervisor do @impl true def init(:ok) do - [bot_config] = Application.fetch_env!(:fruitbot, :bots) + [_bot_config] = Application.fetch_env!(:fruitbot, :bots) + + # Bot options for new Nostrum API + bot_options = %{ + name: :fruitbot, + consumer: Fruitbot.NostrumConsumer, + intents: [ + :guilds, + :message_content, + :guild_messages + ], + wrapped_token: fn -> System.get_env("DISCORD_TOKEN") end + } children = [ Plug.Cowboy.child_spec(scheme: :http, plug: Fruitbot.Router, options: [port: get_port()]), {Fruitbot.Worker, uri: System.get_env("CHAT_URL")}, - {Fruitbot.NostrumConsumer, name: Fruitbot.NostrumConsumer}, + {Nostrum.Bot, bot_options}, # {TMI.Supervisor, bot_config} ]