captionbot-clients/bash/commands.sh
2016-04-18 22:23:21 +02:00

69 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Edit your commands in this file.
if [ "$1" = "source" ];then
# Edit the token in here
# Set INLINE to 1 in order to receive inline queries.
# To enable this option in your bot, send the /setinline command to @BotFather.
INLINE=0
# Set to .* to allow sending files from all locations
FILE_REGEX='/home/user/allowed/.*'
else
if ! tmux ls | grep -v send | grep -q $copname; then
[ ! -z ${URLS[*]} ] && {
send_action ${USER[ID]} typing
result=$(./captionbot.sh ${URLS[*]} script)
res=$(curl -s "$MSG_URL" -d "chat_id=${USER[ID]}" -d "text=$result" -d "reply_to_message_id=$MESSAGE_ID")
return
}
# Inline
if [ $INLINE == 1 ]; then
# inline query data
iUSER[FIRST_NAME]=$(echo "$res" | sed 's/^.*\(first_name.*\)/\1/g' | cut -d '"' -f3 | tail -1)
iUSER[LAST_NAME]=$(echo "$res" | sed 's/^.*\(last_name.*\)/\1/g' | cut -d '"' -f3)
iUSER[USERNAME]=$(echo "$res" | sed 's/^.*\(username.*\)/\1/g' | cut -d '"' -f3 | tail -1)
iQUERY_ID=$(echo "$res" | sed 's/^.*\(inline_query.*\)/\1/g' | cut -d '"' -f5 | tail -1)
iQUERY_MSG=$(echo "$res" | sed 's/^.*\(inline_query.*\)/\1/g' | cut -d '"' -f5 | tail -6 | head -1)
# Inline examples
if [[ $iQUERY_MSG == photo ]]; then
answer_inline_query "$iQUERY_ID" "photo" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg"
fi
if [[ $iQUERY_MSG == sticker ]]; then
answer_inline_query "$iQUERY_ID" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
fi
if [[ $iQUERY_MSG == gif ]]; then
answer_inline_query "$iQUERY_ID" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
fi
if [[ $iQUERY_MSG == web ]]; then
answer_inline_query "$iQUERY_ID" "article" "Telegram" "https://telegram.org/"
fi
fi
fi
case $MESSAGE in
'/start')
send_message "${USER[ID]}" "This is a bot client for captionbot.ai written in bash.
This bot will try to recognize the content of any image you give him using Microsoft's captionbot.ai website api.
Available commands:
/start: Start bot and image recognition process.
/info: Get shorter info message about this bot.
/cancel: Cancel any currently running interactive chats.
Captionbot client written by Daniil Gentili @danogentili.
Contribute to the project: https://github.com/danog/captionbot-clients
Bot written by @topkecleon, Juan Potato (@awkward_potato), Lorenzo Santina (BigNerd95) and Daniil Gentili (@danogentili)
Contribute to the project: https://github.com/topkecleon/telegram-bot-bash
To start, send me a photo.
"
;;
*)
if tmux ls | grep -v send | grep -q $copname;then inproc; else result=$(./captionbot.sh "$MESSAGE" script) && res=$(curl -s "$MSG_URL" -d "chat_id=${USER[ID]}" -d "text=$result" -d "reply_to_message_id=$MESSAGE_ID"); fi
;;
esac
fi