diff --git a/.gitignore b/.gitignore index 77a3132..c5d957e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ aier_bot-*.tar /tmp/ .DS_Store .local -run.sh \ No newline at end of file +dev.sh +start.sh +run.sh +nohup.out diff --git a/docs/dev_readme.md b/docs/dev_readme.md new file mode 100644 index 0000000..ec2bf80 --- /dev/null +++ b/docs/dev_readme.md @@ -0,0 +1,21 @@ +# Dev Readme + +## Dev + +```sh +./dev +``` + +## Prod + +```sh +./start +``` + +Stop + +```bash +ps aux | grep mix + +kill -9 +``` diff --git a/lib/aier_bot/bot.ex b/lib/aier_bot/bot.ex index cb7280d..beaa8f3 100644 --- a/lib/aier_bot/bot.ex +++ b/lib/aier_bot/bot.ex @@ -10,14 +10,13 @@ defmodule AierBot.Bot do command("start") command("help", description: "Print the bot's help") - command("image", description: "Generate image from text") middleware(ExGram.Middleware.IgnoreUsername) def bot(), do: @bot def handle({:command, :start, _msg}, context) do - answer(context, "Hi!") + answer(context, "Hi! I'm a bot that can download images and videos, just give me a link.") end def handle({:command, :help, _msg}, context) do diff --git a/lib/aier_bot/file_helper.ex b/lib/aier_bot/file_helper.ex index 92774df..bd2d795 100644 --- a/lib/aier_bot/file_helper.ex +++ b/lib/aier_bot/file_helper.ex @@ -1,8 +1,14 @@ defmodule AierBot.FileHelper do use Tesla - # youtube video download url: "https://olly.imput.net/api/stream?id=WpsLJCeQ24MBD_xM_3uwu&exp=1721625834931&sig=4UvjCvFD57jU7yrLdwmzRmfsPgPb8KhFIE1DwmnOj14&sec=C1Hty_eEXvswFhzdrDfDZ4cmkSUDgex1aV6mzDSK0dc&iv=ozku3rLJzeV_rVRSzWVlFw" - def download("https://olly.imput.net/api/stream" <> _ = url) do + def download(url) do + cond do + String.contains?(url, "/api/stream") -> download_streaming(url) + true -> download_file(url) + end + end + + defp download_streaming(url) do IO.inspect(url, label: "Download URL") case get(url) do @@ -20,7 +26,7 @@ defmodule AierBot.FileHelper do end end - def download(url) do + defp download_file(url) do IO.inspect(url, label: "Download URL") case get(url) do