mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
115 lines
3.3 KiB
Bash
115 lines
3.3 KiB
Bash
#!/bin/bash
|
|
#######################################################
|
|
#
|
|
# File: mycommands.sh.clean
|
|
#
|
|
# copy to mycommands.sh and add all your commands and functions here ...
|
|
#
|
|
# Usage: will be executed when a bot command is received
|
|
#
|
|
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
|
# Author: KayM (gnadelwartz), kay@rrr.de
|
|
#
|
|
#### $$VERSION$$ v1.30-0-g3266427
|
|
#######################################################
|
|
# shellcheck disable=SC1117
|
|
|
|
####################
|
|
# Config has moved to bashbot.conf
|
|
# shellcheck source=./commands.sh
|
|
[ -r "${BASHBOT_ETC:-.}/mycommands.conf" ] && source "${BASHBOT_ETC:-.}/mycommands.conf" "$1"
|
|
|
|
|
|
##################
|
|
# lets's go
|
|
if [ "$1" = "startbot" ];then
|
|
###################
|
|
# this section is processed on startup
|
|
|
|
# run once after startup when the first message is received
|
|
my_startup(){
|
|
:
|
|
}
|
|
touch .mystartup
|
|
else
|
|
# call my_startup on first message after startup
|
|
# things to do only once
|
|
[ -f .mystartup ] && rm -f .mystartup && _exec_if_function my_startup
|
|
|
|
#############################
|
|
# your own bashbot commands
|
|
# NOTE: command can have @botname attached, you must add * to case tests...
|
|
mycommands() {
|
|
|
|
##############
|
|
# a service Message was received
|
|
# add your own stuff here
|
|
if [ -n "${SERVICE}" ]; then
|
|
# example: delete every service message
|
|
if [ "${SILENCER}" = "yes" ]; then
|
|
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
|
|
fi
|
|
fi
|
|
|
|
# remove keyboard if you use keyboards
|
|
[ -n "${REMOVEKEYBOARD}" ] && remove_keyboard "${CHAT[ID]}" &
|
|
[[ -n "${REMOVEKEYBOARD_PRIVATE}" && "${CHAT[ID]}" == "${USER[ID]}" ]] && remove_keyboard "${CHAT[ID]}" &
|
|
|
|
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_markdownv2_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
|
|
printf "%s\n" "${sep}"; inline_query_compose "${RANDOM}" "photo" "${image}"; sep=","
|
|
count=$(( count + 1 ))
|
|
done <<<"${result}"
|
|
}
|
|
|
|
fi
|