Put events in their own folder
This commit is contained in:
parent
779f99a5f3
commit
77ebcf9d7b
6 changed files with 61 additions and 13 deletions
14
lib/events/AddReaction.ex
Normal file
14
lib/events/AddReaction.ex
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule HahaYes.Events.AddReactionsConsumer do
|
||||||
|
@moduledoc """
|
||||||
|
Triggered when reactions are added to a message.
|
||||||
|
|
||||||
|
Used to handle starboard.
|
||||||
|
|
||||||
|
TODO: Implement starboard
|
||||||
|
"""
|
||||||
|
use Nostrum.Consumer
|
||||||
|
|
||||||
|
def handle_event({:MESSAGE_REACTION_ADD, _reacts, _ws_state}) do
|
||||||
|
IO.puts("Someone added reaction.")
|
||||||
|
end
|
||||||
|
end
|
14
lib/events/RemoveReaction.ex
Normal file
14
lib/events/RemoveReaction.ex
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule HahaYes.Events.RemoveReactionsConsumer do
|
||||||
|
@moduledoc """
|
||||||
|
Triggered when reactions are added to a message.
|
||||||
|
|
||||||
|
Used to handle starboard.
|
||||||
|
|
||||||
|
TODO: Implement starboard
|
||||||
|
"""
|
||||||
|
use Nostrum.Consumer
|
||||||
|
|
||||||
|
def handle_event({:MESSAGE_REACTION_REMOVE, _reacts, _ws_state}) do
|
||||||
|
IO.puts("Someone removed reaction.")
|
||||||
|
end
|
||||||
|
end
|
19
lib/events/messages.ex
Normal file
19
lib/events/messages.ex
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
defmodule HahaYes.Events.MessagesConsumer do
|
||||||
|
@moduledoc """
|
||||||
|
Parse messages to execute commands
|
||||||
|
"""
|
||||||
|
|
||||||
|
use Nostrum.Consumer
|
||||||
|
|
||||||
|
def handle_event({:MESSAGE_CREATE, msg, _ws_state}) when msg.author.bot != true do
|
||||||
|
if String.starts_with?(msg.content, "h3h3 ") do
|
||||||
|
msg.content
|
||||||
|
|> String.replace("h3h3 ", "")
|
||||||
|
|> String.split(" ")
|
||||||
|
|> Enum.at(0)
|
||||||
|
|> String.downcase()
|
||||||
|
|> String.capitalize()
|
||||||
|
|> then(& apply(String.to_atom("#{HahaYes.Commands}.#{&1}"), :execute, [msg]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
10
lib/events/ready.ex
Normal file
10
lib/events/ready.ex
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
defmodule HahaYes.Events.ReadyConsumer do
|
||||||
|
use Nostrum.Consumer
|
||||||
|
|
||||||
|
def handle_event({:READY, event, _ws_state}) do
|
||||||
|
IO.puts("""
|
||||||
|
#{event.user.username} (#{event.user.id}) is ready!
|
||||||
|
I am in #{length(event.guilds)} servers!
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,12 +0,0 @@
|
||||||
defmodule HahaConsumer do
|
|
||||||
use Nostrum.Consumer
|
|
||||||
|
|
||||||
def handle_event({:MESSAGE_CREATE, msg, _ws_state}) when msg.author.bot != true do
|
|
||||||
if String.starts_with?(msg.content, "h3h3 ") do
|
|
||||||
msg.content
|
|
||||||
|> String.replace("h3h3 ", "")
|
|
||||||
|> String.split(" ")
|
|
||||||
|> then(& apply(HahaCommands, String.to_atom(Enum.at(&1, 0)), [msg]))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -8,7 +8,10 @@ defmodule HahaYes.Application do
|
||||||
@impl true
|
@impl true
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
children = [
|
children = [
|
||||||
HahaConsumer
|
HahaYes.Events.MessagesConsumer,
|
||||||
|
HahaYes.Events.ReadyConsumer,
|
||||||
|
HahaYes.Events.AddReactionsConsumer,
|
||||||
|
HahaYes.Events.RemoveReactionsConsumer
|
||||||
# Starts a worker by calling: HahaYes.Worker.start_link(arg)
|
# Starts a worker by calling: HahaYes.Worker.start_link(arg)
|
||||||
# {HahaYes.Worker, arg}
|
# {HahaYes.Worker, arg}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue