From b433bba352166e6af357a80ecbf0c497f12ac326 Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Wed, 29 Sep 2021 14:16:03 +0200 Subject: [PATCH] + exported everything (?) to event objects --- tg.sh | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/tg.sh b/tg.sh index 1db6826..d72c07c 100755 --- a/tg.sh +++ b/tg.sh @@ -105,7 +105,7 @@ function tg_start() { _event_type="$(jq -r '(select(.message) | .message), (select(.edited_message) | .edited_message) | ( (select(.animation) | "animation"), (select(.audio) | "audio"), - (select(.document) | "document"), + (select(.animation == null) | select(.document) | "document"), (select(.photo) | "photo"), (select(.sticker) | "sticker"), (select(.video) | "video"), @@ -123,7 +123,7 @@ function tg_start() { (if .chat.type == "private" then .chat.username else .chat.title end), .chat.type, .date, - (select(.text) | .text, select(.caption) | .caption), + (select(.text) | .text), (select(.caption) | .caption), (if .reply_to_message then .reply_to_message | ( "true", @@ -192,8 +192,62 @@ function tg_start() { if [[ "$_msg_type" == edited_message ]]; then _on_edit elif [[ "$_event_type" == animation ]]; then + _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .animation | + [.file_name, + .mime_type, + .duration, + .width, + .height, + .thumb.file_id, + .thumb.file_unique_id, + .thumb.height, + .thumb.width, + .file_id, + .file_unique_id, + .file_size] | @sh' <<< "${_events[$i]}" + event[animation_file_name]="${_tmp[0]}" + event[animation_mime_type]="${_tmp[1]}" + event[animation_duration]="${_tmp[2]}" + event[animation_width]="${_tmp[3]}" + event[animation_height]="${_tmp[4]}" + event[animation_thumb_file_id]="${_tmp[5]}" + event[animation_thumb_file_unique_id]="${_tmp[6]}" + event[animation_thumb_height]="${_tmp[7]}" + event[animation_thumb_width]="${_tmp[8]}" + event[animation_file_id]="${_tmp[9]}" + event[animation_file_unique_id]="${_tmp[10]}" + event[animation_file_size]="${_tmp[11]}" + unset _tmp + _on_animation elif [[ "$_event_type" == audio ]]; then + _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .audio | + [.duration, + .file_name, + .mime_type, + .title, + .performer, + .thumb.file_id, + .thumb.file_unique_id, + .thumb.width, + .thumb.height, + .file_id, + .file_unique_id, + .file_size] | @sh' <<< "${_events[$i]}" + event[audio_duration]="${_tmp[0]}" + event[file_name]="${_tmp[1]}" + event[mime_type]="${_tmp[2]}" + event[title]="${_tmp[3]}" + event[performer]="${_tmp[4]}" + event[thumb_file_id]="${_tmp[5]}" + event[thumb_file_unique_id]="${_tmp[6]}" + event[thumb_width]="${_tmp[7]}" + event[thumb_height]="${_tmp[8]}" + event[file_id]="${_tmp[9]}" + event[file_unique_id]="${_tmp[10]}" + event[file_size]="${_tmp[11]}" + unset _tmp + _on_audio elif [[ "$_event_type" == document ]]; then _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .document | @@ -227,16 +281,78 @@ function tg_start() { _on_photo elif [[ "$_event_type" == sticker ]]; then + _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .sticker | + [.width, + .height, + .emoji, + .set_name, + .is_animated, + .file_id, + .file_unique_id, + .file_size] | @sh' <<< "${_events[$i]}" + event[sticker_width]="${_tmp[0]}" + event[sticker_height]="${_tmp[1]}" + event[sticker_emoji]="${_tmp[2]}" + event[sticker_set_name]="${_tmp[3]}" + event[sticker_is_animated]="${_tmp[4]}" + event[sticker_file_id]="${_tmp[5]}" + event[sticker_file_unique_id]="${_tmp[6]}" + event[sticker_file_size]="${_tmp[6]}" + unset _tmp + _on_sticker elif [[ "$_event_type" == video ]]; then + _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .video | + [.duration, + .width, + .height, + .file_name, + .mime_type, + .thumb.file_id, + .thumb.file_unique_id, + .thumb.width, + .thumb.height, + .file_id, + .file_unique_id, + .file_size] | @sh' <<< "${_events[$i]}" + event[video_duration]="${_tmp[0]}" + event[video_width]="${_tmp[1]}" + event[video_height]="${_tmp[2]}" + event[video_file_name]="${_tmp[3]}" + event[video_mime_type]="${_tmp[4]}" + event[video_thumb_file_id]="${_tmp[5]}" + event[video_thumb_file_unique_id]="${_tmp[6]}" + event[video_thumb_width]="${_tmp[7]}" + event[video_thumb_height]="${_tmp[8]}" + event[video_file_id]="${_tmp[9]}" + event[video_file_unique_id]="${_tmp[10]}" + event[video_file_size]="${_tmp[11]}" + unset _tmp + _on_video elif [[ "$_event_type" == video_note ]]; then - _on_video_note + # implement it yourself or use raw JSON + # I don't consider video_note to be a valid way of messaging + _on_video_note elif [[ "$_event_type" == voice ]]; then + _jq_to_array '(select(.message) | .message), (select(.edited_message) | .edited_message) | .voice | + [.duration, + .mime_type, + .file_id, + .file_unique_id, + .file_size] | @sh' <<< "${_events[$i]}" + event[voice_duration]="${_tmp[0]}" + event[voice_mime_type]="${_tmp[1]}" + event[voice_file_id]="${_tmp[2]}" + event[voice_file_unique_id]="${_tmp[3]}" + event[voice_file_size]="${_tmp[4]}" + unset _tmp + _on_voice else _on_msg fi + declare -p event unset event done [[ ${#_events[@]} -gt 0 ]] && _update_id=$(jq 'select(.update_id != null) | .update_id' <<< "${_events[-1]}")