2020-05-14 12:21:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
########
|
|
|
|
#
|
|
|
|
# files: mycommands.sh.clean
|
|
|
|
# copy to mycommands.sh and add all your commands and functions here ...
|
|
|
|
#
|
2020-05-15 16:52:12 +00:00
|
|
|
#### $$VERSION$$ v0.94-0-gaaa71c8
|
2020-05-14 12:21:15 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
##########
|
|
|
|
# edit the following lines to fit your bot usage
|
|
|
|
|
2020-05-14 20:12:44 +00:00
|
|
|
export bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
|
2020-05-14 12:21:15 +00:00
|
|
|
'
|
|
|
|
|
2020-05-14 20:12:44 +00:00
|
|
|
export bashbot_help='*Available commands*:
|
2020-05-14 12:21:15 +00:00
|
|
|
'
|
2020-05-14 20:12:44 +00:00
|
|
|
export res=""
|
2020-05-14 12:21:15 +00:00
|
|
|
|
|
|
|
# Set INLINE to 1 in order to receive inline queries.
|
|
|
|
# To enable this option in your bot ypu must also send the /setinline command to @BotFather.
|
|
|
|
export INLINE="0"
|
|
|
|
|
|
|
|
# NOTE: this is a regex, not shell globbing! you must use a valid egex,
|
|
|
|
# '.' matches any charater and '.*' matches all remaining charatcers!
|
|
|
|
# additionally you must escape special charaters with '\', e.g. '\. \? \[ \*" to match them literally
|
|
|
|
# do NOT set to .* as this allow sending files from all locations!
|
2020-05-14 20:12:44 +00:00
|
|
|
export FILE_REGEX="${BASHBOT_ETC}/.*"
|
2020-05-14 12:21:15 +00:00
|
|
|
|
2020-05-14 13:02:17 +00:00
|
|
|
# set to "yes" and give your bot admin privilegs to remove service messaes from groups
|
|
|
|
export SILENCER="no"
|
|
|
|
|
2020-05-14 12:21:15 +00:00
|
|
|
########
|
|
|
|
# special network setups may require to provide additional ARGS to curl
|
|
|
|
#
|
|
|
|
# example: run bashbot over TOR or SOCKS proxy
|
|
|
|
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR
|
|
|
|
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS
|
|
|
|
|
2020-05-14 13:02:17 +00:00
|
|
|
if [ "$1" = "startbot" ];then
|
|
|
|
# run once after startup when the first message is recieved
|
|
|
|
my_startup(){
|
|
|
|
:
|
|
|
|
}
|
|
|
|
touch .mystartup
|
|
|
|
else
|
|
|
|
# here we call the function above when the mesage arrives
|
|
|
|
# things to do only at soure, eg. after startup
|
|
|
|
[ -f .mystartup ] && rm -f .mystartup && _exec_if_function my_startup
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# your own bashbot commands
|
2020-05-14 12:21:15 +00:00
|
|
|
# NOTE: command can have @botname attached, you must add * in case tests...
|
|
|
|
mycommands() {
|
|
|
|
|
2020-05-14 13:02:17 +00:00
|
|
|
##############
|
|
|
|
# a service Message was recieved
|
|
|
|
# add your own stuff here
|
2020-05-14 18:49:13 +00:00
|
|
|
if [ -n "${SERVICE}" ]; then
|
2020-05-14 13:02:17 +00:00
|
|
|
|
|
|
|
# example: delete every service message
|
|
|
|
if [ "${SILENCER}" = "yes" ]; then
|
|
|
|
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-05-14 12:21:15 +00:00
|
|
|
case "${MESSAGE}" in
|
|
|
|
##################
|
|
|
|
# example command, replace them by your own
|
|
|
|
'/echo'*) # example echo command
|
|
|
|
send_normal_message "${CHAT[ID]}" "$MESSAGE"
|
|
|
|
;;
|
|
|
|
|
|
|
|
##########
|
|
|
|
# command overwrite examples
|
|
|
|
# return 0 -> run default command afterwards
|
|
|
|
# return 1 -> skip possible default commands
|
|
|
|
'/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
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
myinlines() {
|
|
|
|
#######################
|
|
|
|
# this fuinction is called only if you has set INLINE=1 !!
|
|
|
|
# shellcheck disable=SC2128
|
|
|
|
iQUERY="${iQUERY,,}"
|
|
|
|
|
|
|
|
|
|
|
|
case "${iQUERY}" in
|
|
|
|
##################
|
|
|
|
# example inline command, replace it by your own
|
|
|
|
"image "*) # search images with yahoo
|
|
|
|
local search="${iQUERY#* }"
|
|
|
|
answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# place your processing functions here
|
|
|
|
|
|
|
|
# example inline processing function, not really useful
|
|
|
|
# $1 search parameter
|
|
|
|
my_image_search(){
|
|
|
|
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=")"
|
|
|
|
while read -r image; do
|
|
|
|
[ "$count" -gt "20" ] && break
|
|
|
|
image="${image#* src=\'}"; image="${image%%&pid=*}"
|
|
|
|
[[ "${image}" = *"src="* ]] && continue
|
|
|
|
echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep=","
|
|
|
|
count=$(( count + 1 ))
|
|
|
|
done <<<"${result}"
|
|
|
|
}
|
|
|
|
|
|
|
|
fi
|