2019-04-23 19:52:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# files: mycommands.sh.dist
|
|
|
|
# copy to mycommands.sh and add all your commands and functions here ...
|
|
|
|
#
|
2019-05-25 11:31:36 +00:00
|
|
|
#### $$VERSION$$ v0.80-23-g25c9b62
|
2019-04-23 19:52:57 +00:00
|
|
|
#
|
2019-04-24 11:34:44 +00:00
|
|
|
|
2019-04-24 11:40:59 +00:00
|
|
|
# uncomment the following lines to overwrite info and help messages
|
|
|
|
# bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
|
2019-04-24 11:34:44 +00:00
|
|
|
#'
|
|
|
|
# bashbot_help='*Available commands*:
|
|
|
|
#'
|
2019-05-12 15:51:52 +00:00
|
|
|
res=""
|
2019-04-24 11:34:44 +00:00
|
|
|
|
2019-05-16 14:42:38 +00:00
|
|
|
# Set INLINE to 1 in order to receive inline queries.
|
|
|
|
# To enable this option in your bot, send the /setinline command to @BotFather.
|
|
|
|
export INLINE="0"
|
|
|
|
# Set to .* to allow sending files from all locations
|
|
|
|
export FILE_REGEX='/home/user/allowed/.*'
|
2019-05-23 17:40:15 +00:00
|
|
|
# example: run bashbot over TOR
|
|
|
|
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050"
|
2019-04-24 11:34:44 +00:00
|
|
|
|
2019-05-16 14:42:38 +00:00
|
|
|
if [ "$1" != "source" ];then
|
2019-05-02 10:33:10 +00:00
|
|
|
# your additional bahsbot commands
|
|
|
|
# NOTE: command can have @botname attached, you must add * in case tests...
|
|
|
|
mycommands() {
|
2019-04-23 19:52:57 +00:00
|
|
|
|
2019-05-14 11:16:58 +00:00
|
|
|
case "${MESSAGE}" in
|
2019-05-25 11:31:36 +00:00
|
|
|
##################
|
|
|
|
# example commands, replace thm by your own
|
2019-04-23 19:52:57 +00:00
|
|
|
'/echo'*) # example echo command
|
|
|
|
send_normal_message "${CHAT[ID]}" "$MESSAGE"
|
|
|
|
;;
|
2019-04-27 11:36:32 +00:00
|
|
|
'/question'*) # start interactive questions
|
2019-04-23 19:52:57 +00:00
|
|
|
checkproc
|
|
|
|
if [ "$res" -gt 0 ] ; then
|
2019-05-20 10:12:11 +00:00
|
|
|
startproc "examples/question.sh" || _message "Can't start question."
|
2019-04-23 19:52:57 +00:00
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2019-05-01 17:21:57 +00:00
|
|
|
'/run_notify'*) # start notify background job
|
2019-04-23 19:52:57 +00:00
|
|
|
myback="notify"; checkback "$myback"
|
|
|
|
if [ "$res" -gt 0 ] ; then
|
2019-05-20 10:12:11 +00:00
|
|
|
background "examples/notify.sh 60" "$myback" || _message "Can't start notify."
|
2019-04-23 19:52:57 +00:00
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "Background command $myback already running ..."
|
|
|
|
fi
|
|
|
|
;;
|
2019-05-01 17:21:57 +00:00
|
|
|
'/stop_notify'*) # kill notify background job
|
2019-04-23 19:52:57 +00:00
|
|
|
myback="notify"; checkback "$myback"
|
|
|
|
if [ "$res" -eq 0 ] ; then
|
|
|
|
killback "$myback"
|
|
|
|
send_normal_message "${CHAT[ID]}" "Background command $myback canceled."
|
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2019-05-25 11:31:36 +00:00
|
|
|
##########
|
|
|
|
# command overwrite examples
|
|
|
|
'info'*) # output date in front of regular info
|
|
|
|
send_normal_message "${CHAT[ID]}" "$(date)"
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'/kickme'*) # this will replace the /kickme command
|
|
|
|
send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*"
|
|
|
|
return 1
|
|
|
|
;;
|
2019-04-23 19:52:57 +00:00
|
|
|
esac
|
2019-05-02 10:33:10 +00:00
|
|
|
}
|
2019-04-23 19:52:57 +00:00
|
|
|
|
2019-05-09 21:34:45 +00:00
|
|
|
myinlines() {
|
|
|
|
#######################
|
2019-05-10 16:50:30 +00:00
|
|
|
# Inline query examples, do not use them in production (exept image search ;-)
|
2019-05-09 21:34:45 +00:00
|
|
|
# shellcheck disable=SC2128
|
2019-05-10 19:38:25 +00:00
|
|
|
iQUERY="${iQUERY,,}" # all lowercase
|
2019-05-09 21:34:45 +00:00
|
|
|
case "${iQUERY}" in
|
2019-05-10 16:50:30 +00:00
|
|
|
"image "*) # search images with yahoo
|
2019-05-09 21:34:45 +00:00
|
|
|
local search="${iQUERY#* }"
|
|
|
|
answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")"
|
|
|
|
;;
|
2019-05-10 16:50:30 +00:00
|
|
|
|
|
|
|
"0"*) # a single message with title
|
|
|
|
answer_inline_query "${iQUERY[ID]}" "message" "Title of the result" "Content of the message to be sent"
|
|
|
|
;;
|
|
|
|
"1"*) # a single photo
|
|
|
|
answer_inline_query "${iQUERY[ID]}" "photo" "https://avatars.githubusercontent.com/u/13046303" "https://avatars.githubusercontent.com/u/13046303"
|
|
|
|
;;
|
|
|
|
"2"*) # two photos
|
2019-05-09 21:34:45 +00:00
|
|
|
answer_inline_multi "${iQUERY[ID]}" "
|
2019-05-10 12:56:53 +00:00
|
|
|
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/13046303"),
|
|
|
|
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/4593242")
|
2019-05-09 21:34:45 +00:00
|
|
|
"
|
|
|
|
;;
|
2019-05-10 16:50:30 +00:00
|
|
|
"3"*) # three photos
|
|
|
|
answer_inline_multi "${iQUERY[ID]}" "
|
|
|
|
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/13046303"),
|
|
|
|
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/4593242")
|
|
|
|
$(inline_query_compose "$RANDOM" "photo" "https://avatars.githubusercontent.com/u/102707")
|
|
|
|
"
|
|
|
|
;;
|
2019-05-09 21:34:45 +00:00
|
|
|
|
2019-05-10 16:50:30 +00:00
|
|
|
"4") # four photo from array
|
2019-05-10 12:56:53 +00:00
|
|
|
local sep=""
|
|
|
|
local avatar=("https://avatars.githubusercontent.com/u/13046303" "https://avatars.githubusercontent.com/u/4593242" "https://avatars.githubusercontent.com/u/102707" "https://avatars.githubusercontent.com/u/6460407")
|
|
|
|
answer_inline_multi "${iQUERY[ID]}" "
|
|
|
|
$(for photo in ${avatar[*]} ; do
|
|
|
|
echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${photo}" "${photo}"; sep=","
|
|
|
|
done)
|
|
|
|
"
|
|
|
|
;;
|
|
|
|
|
2019-05-10 16:50:30 +00:00
|
|
|
"sticker") # example chaecd telegram sticker
|
2019-05-09 21:34:45 +00:00
|
|
|
answer_inline_query "${iQUERY[ID]}" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
|
|
|
|
;;
|
2019-05-10 16:50:30 +00:00
|
|
|
"gif") # exmaple chaehed gif
|
2019-05-09 21:34:45 +00:00
|
|
|
answer_inline_query "${iQUERY[ID]}" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
|
|
|
|
;;
|
|
|
|
esac
|
2019-05-16 14:42:38 +00:00
|
|
|
set +x
|
2019-05-09 21:34:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 10:33:10 +00:00
|
|
|
# place your processing functions here
|
2019-05-09 21:34:45 +00:00
|
|
|
|
|
|
|
# $1 search parameter
|
|
|
|
my_image_search(){
|
2019-05-10 13:58:19 +00:00
|
|
|
local image result sep="" count="1"
|
|
|
|
result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/</\n</g' | grep "<img src=")"
|
2019-05-09 21:34:45 +00:00
|
|
|
while read -r image; do
|
2019-05-11 10:07:06 +00:00
|
|
|
[ "$count" -gt "20" ] && break
|
2019-05-10 13:58:19 +00:00
|
|
|
image="${image#* src=\'}"; image="${image%%&pid=*}"
|
|
|
|
[[ "${image}" = *"src="* ]] && continue
|
2019-05-10 12:56:53 +00:00
|
|
|
echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep=","
|
2019-05-10 13:58:19 +00:00
|
|
|
count=$(( count + 1 ))
|
2019-05-09 21:34:45 +00:00
|
|
|
done <<<"${result}"
|
|
|
|
}
|
|
|
|
|
2019-05-02 10:33:10 +00:00
|
|
|
fi
|