Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
Binary file added elixir.zip
Binary file not shown.
37 changes: 17 additions & 20 deletions lib/fruitbot/nostrum_consumer.ex
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 14 additions & 2 deletions lib/fruitbot/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
]

Expand Down