Compare commits

..

4 commits

6 changed files with 30 additions and 7 deletions

View file

@ -8,4 +8,5 @@ config :nostrum,
:guild_messages, :guild_messages,
:message_content, :message_content,
:guild_message_reactions :guild_message_reactions
] ],
prefix: "haha "

View file

@ -2,7 +2,7 @@ defmodule HahaYes.Commands.Download do
@moduledoc """ @moduledoc """
Download command Download command
""" """
import Nostrum.Struct.Embed
alias Nostrum.Api alias Nostrum.Api
@doc """ @doc """
@ -23,14 +23,34 @@ defmodule HahaYes.Commands.Download do
Bot: <video file> Bot: <video file>
""" """
def execute(msg, _ws_state, args) do def execute(msg, _ws_state, args) do
url = Enum.at(args, 0)
{:ok, loading} = Api.create_message(msg.channel_id, "Downloading...") {:ok, loading} = Api.create_message(msg.channel_id, "Downloading...")
opt = ["-f", "bestvideo[height<=?480]+bestaudio/best", args, "-o", "#{System.tmp_dir}/#{msg.id}.%(ext)si", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];
opt = ["-f", "bestvideo[height<=?480]+bestaudio/best", url, "-o", "#{System.tmp_dir}/#{msg.id}.%(ext)si", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];
System.cmd("yt-dlp", opt) System.cmd("yt-dlp", opt)
output = Enum.at(Path.wildcard("#{System.tmp_dir}/#{msg.id}.*"), 0)
{:ok, file} = File.stat(output)
file_size =
file.size / 1000000.0
|> Decimal.from_float()
|> Decimal.round(2)
|> Decimal.to_float()
Api.delete_message(loading.channel_id, loading.id) Api.delete_message(loading.channel_id, loading.id)
Api.delete_message(msg) Api.delete_message(msg)
Api.create_message(msg.channel_id, files: [Enum.at(Path.wildcard("#{System.tmp_dir}/#{msg.id}.*"), 0)])
if file_size >= 25 do
Api.create_message(msg.channel_id, "File size is too big! (#{file_size})")
else
embed =
%Nostrum.Struct.Embed{}
|> put_color(431_948)
|> put_author("Downloaded by #{msg.author.username} (#{file_size} MB)", url, "https://cdn.discordapp.com/avatars/#{msg.author.id}/#{msg.author.avatar}.webp")
|> put_footer("You can get the original video by clicking on the \"Downloaded by #{msg.author.username}\" message!")
Api.create_message(msg.channel_id, files: [output], embeds: [embed])
end
end end
end end

View file

@ -6,14 +6,15 @@ defmodule HahaYes.Events.MessagesConsumer do
use Nostrum.Consumer use Nostrum.Consumer
def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do def handle_event({:MESSAGE_CREATE, msg, ws_state}) when msg.author.bot != true do
if String.starts_with?(msg.content, "h3h3 ") do prefix = Application.get_env(:nostrum, :prefix)
if String.starts_with?(msg.content, prefix) do
msg.content msg.content
|> String.replace("h3h3 ", "") |> String.replace(prefix, "")
|> String.split(" ") |> String.split(" ")
|> Enum.at(0) |> Enum.at(0)
|> String.downcase() |> String.downcase()
|> String.capitalize() |> String.capitalize()
|> then(& apply(String.to_atom("#{HahaYes.Commands}.#{&1}"), :execute, [msg, ws_state, String.replace(msg.content, "h3h3 download ", "")])) |> then(& apply(String.to_atom("#{HahaYes.Commands}.#{&1}"), :execute, [msg, ws_state, String.split(String.replace(msg.content, "h3h3 download ", ""))]))
end end
end end
end end

View file

@ -11,6 +11,7 @@ defmodule HahaYes.Events.ReadyConsumer do
IO.puts(""" IO.puts("""
#{event.user.username} (#{event.user.id}) is ready! #{event.user.username} (#{event.user.id}) is ready!
I am in #{length(event.guilds)} servers! I am in #{length(event.guilds)} servers!
Prefix: #{Application.get_env(:nostrum, :prefix)}
""") """)
end end
end end