Compare commits
No commits in common. "77ebcf9d7b452cf2dccb5b10db5c0d7c9a554c6e" and "0896eb9ffb21480f46cebbe1eeb5b5065cee72c9" have entirely different histories.
77ebcf9d7b
...
0896eb9ffb
10 changed files with 30 additions and 96 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,6 +7,6 @@
|
|||
erl_crash.dump
|
||||
*.ez
|
||||
*.beam
|
||||
/config/config.exs
|
||||
/config/
|
||||
.elixir_ls/
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import Config
|
||||
|
||||
config :nostrum,
|
||||
token: "bot token goes here",
|
||||
gateway_intents: [
|
||||
:guilds,
|
||||
:guild_members,
|
||||
:guild_messages,
|
||||
:message_content,
|
||||
:guild_message_reactions
|
||||
]
|
|
@ -1,21 +0,0 @@
|
|||
defmodule HahaYes.Commands.Ping do
|
||||
@moduledoc """
|
||||
Contain all the function for each commands
|
||||
"""
|
||||
|
||||
alias Nostrum.Api
|
||||
|
||||
@doc """
|
||||
Reply with a simple "Pong!"
|
||||
|
||||
## Example
|
||||
|
||||
User: h3h3 ping
|
||||
|
||||
Bot: Pong!
|
||||
"""
|
||||
|
||||
def execute(msg) do
|
||||
Api.create_message(msg.channel_id, "Pong!")
|
||||
end
|
||||
end
|
|
@ -1,10 +1,24 @@
|
|||
defmodule HahaYes.Commands.Download do
|
||||
defmodule HahaCommands do
|
||||
@moduledoc """
|
||||
Contain all the function for each commands
|
||||
"""
|
||||
|
||||
alias Nostrum.Api
|
||||
|
||||
@doc """
|
||||
Reply with a simple "Pong!"
|
||||
|
||||
## Example
|
||||
|
||||
User: h3h3 ping
|
||||
|
||||
Bot: Pong!
|
||||
"""
|
||||
|
||||
def ping(msg) do
|
||||
Api.create_message(msg.channel_id, "Pong!")
|
||||
end
|
||||
|
||||
@doc """
|
||||
Download the video sent by the user at 480p max.
|
||||
|
||||
|
@ -22,7 +36,7 @@ defmodule HahaYes.Commands.Download do
|
|||
|
||||
Bot: <video file>
|
||||
"""
|
||||
def execute(msg) do
|
||||
def download(msg) do
|
||||
arg = String.replace(msg.content, "h3h3 download ", "")
|
||||
opt = ["-f", "bestvideo[height<=?480]+bestaudio/best", arg, "-o", "#{System.tmp_dir}/test.mp4", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
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
|
|
@ -1,14 +0,0 @@
|
|||
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
|
|
@ -1,19 +0,0 @@
|
|||
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
|
|
@ -1,10 +0,0 @@
|
|||
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
|
12
lib/haha_yes.ex
Normal file
12
lib/haha_yes.ex
Normal file
|
@ -0,0 +1,12 @@
|
|||
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,10 +8,7 @@ defmodule HahaYes.Application do
|
|||
@impl true
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
HahaYes.Events.MessagesConsumer,
|
||||
HahaYes.Events.ReadyConsumer,
|
||||
HahaYes.Events.AddReactionsConsumer,
|
||||
HahaYes.Events.RemoveReactionsConsumer
|
||||
HahaConsumer
|
||||
# Starts a worker by calling: HahaYes.Worker.start_link(arg)
|
||||
# {HahaYes.Worker, arg}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue