Skip to content

Commit

Permalink
update something
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaddeusJiang committed Jul 22, 2024
1 parent ecef83f commit 0f8a9a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/dev-log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## FIXME: download youtube big video

![error log: download youtube big video](./error_log_download_youtube_big_video.png)

![log: stream date](./error_log_streaming_data.png)

## FIXME: bug: 无法发送 20 分钟的长视频

![bug log: 无法发送 20 分钟的长视频](./bug_log_发送20分钟长视频.png)
Expand Down
Binary file added docs/error_log_download_youtube_big_video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/error_log_streaming_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 32 additions & 7 deletions lib/aier_bot/bot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule AierBot.Bot do
{:ok, download_url} ->
{:ok, file_name, file_content} = FileDownloader.download(download_url)

{:ok, _} = bot_send_file(chat.id, file_name, file_content)
{:ok, _} = bot_send_file(chat.id, file_name, file_content, url)

{:error, error} ->
ExGram.send_message(chat.id, "Failed to download file. Reason: #{inspect(error)}")
Expand All @@ -56,26 +56,51 @@ defmodule AierBot.Bot do
Enum.map(matches, fn [url] -> url end)
end

defp bot_send_file(chat_id, file_name, file_content) do
# TODO: 额外参数可以使用 options 来传递
defp bot_send_file(chat_id, file_name, file_content, _original_url) do
IO.inspect(file_name)

cond do
String.ends_with?(file_name, ".png") ->
ExGram.send_photo(chat_id, {:file_content, file_content, file_name})
ExGram.send_photo(
chat_id,
{:file_content, file_content, file_name}
# TODO: original_url 作为 caption 收益不高,AI generated searchable caption 会更好
# original_text
# AI generated searchable caption
# and some other metadata
# caption: "Image from URL: #{original_url}"
)

String.ends_with?(file_name, ".jpg") ->
ExGram.send_photo(chat_id, {:file_content, file_content, file_name})
ExGram.send_photo(
chat_id,
{:file_content, file_content, file_name}
# caption: "Image from URL: #{original_url}"
)

String.ends_with?(file_name, ".jpeg") ->
ExGram.send_photo(chat_id, {:file_content, file_content, file_name})
ExGram.send_photo(
chat_id,
{:file_content, file_content, file_name}
# caption: "Image from URL: #{original_url}"
)

String.ends_with?(file_name, ".mp4") ->
# {:file_content, iodata() | Enum.t(), String.t()}
# MEMO: 注意:参数是 {:file_content, file_content, file_name} ,3 个元素的 tuple
ExGram.send_video(chat_id, {:file_content, file_content, file_name})
ExGram.send_video(
chat_id,
{:file_content, file_content, file_name}
# caption: "Image from URL: #{original_url}"
)

true ->
ExGram.send_document(chat_id, {:file_content, file_content, file_name})
ExGram.send_document(
chat_id,
{:file_content, file_content, file_name}
# caption: "Image from URL: #{original_url}"
)
end
end

Expand Down

0 comments on commit 0f8a9a3

Please sign in to comment.