aboutsummaryrefslogtreecommitdiff
path: root/units/ib_name.zsh
blob: 9e8f3927c506fddbd82f61e20523121a887c6632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

if [[ -n "${1}" ]]
then
    return 0
fi

reply_text="$(jq -r '.message.reply_to_message.text' <<< "${update}")"

if [[ "${reply_text}" == "null" ]]
then
    reply_text="$(jq -r '.message.reply_to_message.caption' <<< "${update}")"
fi

if [[ "${reply_text}" == "null" ]]
then
    if [[ -n "${ib_parent}" ]]
    then
        output_text="You must specify Image Board and parent post ID, or use this command in reply to a message"
    else
        output_text="You must specify Image Board and post ID or MD5 hash, or use this command in reply to a message"
    fi

    return 0
fi

ib_reply_name="$(sed '1!d' <<< "${reply_text}")"

for ib_board in {a..z} 0
do
    . "${units}/ib_config.zsh"

    if [[ "${ib_reply_name}" == "${ib_name}" ]]
    then
        break
    fi
done

if [[ "${ib_board}" == "0" ]]
then
    output_text="Could not find Image Board in replied message"
    return 0
fi

ib_post_id="$(sed '2!d' <<< "${reply_text}" | cut -d ' ' -f 2)"

if [[ -z "${ib_post_id}" ]]
then
    output_text="Could not find post ID in replied message"
    return 0
fi

set -- ${ib_board} ${ib_post_id}