2016-04-17 18:00:37 +00:00
|
|
|
#!/bin/bash
|
2019-04-23 19:52:57 +00:00
|
|
|
# file: commands.sh
|
2020-05-14 11:27:53 +00:00
|
|
|
|
|
|
|
# _____ _______ _ _ _
|
|
|
|
# (____ \ _ (_______) | (_)_ | |
|
|
|
|
# _ \ \ ___ ____ ___ | |_ _____ _ | |_| |_ | |
|
|
|
|
# | | | / _ \ | _ \ / _ \| _) | ___) / || | | _)|_|
|
|
|
|
# | |__/ / |_| | | | | | |_| | |__ | |____( (_| | | |__ _
|
|
|
|
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
|
|
|
|
#
|
2020-06-23 14:35:50 +00:00
|
|
|
# this file *MUST* not be edited! place your config and commands in
|
2020-09-06 16:50:12 +00:00
|
|
|
# the file "mycommands.sh". a clean version is provided as "mycommands.sh.clean"
|
2020-05-14 11:27:53 +00:00
|
|
|
#
|
2016-04-17 18:00:37 +00:00
|
|
|
|
2016-04-19 09:49:35 +00:00
|
|
|
# This file is public domain in the USA and all free countries.
|
|
|
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
2019-03-28 15:51:33 +00:00
|
|
|
#
|
2021-01-26 13:34:25 +00:00
|
|
|
#### $$VERSION$$ v1.35-dev-14-g08a0524
|
2019-04-01 16:24:05 +00:00
|
|
|
#
|
2016-04-19 09:49:35 +00:00
|
|
|
|
2021-01-04 15:37:54 +00:00
|
|
|
# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed
|
2019-03-30 14:11:33 +00:00
|
|
|
export 'LC_ALL=C.UTF-8'
|
|
|
|
export 'LANG=C.UTF-8'
|
|
|
|
export 'LANGUAGE=C.UTF-8'
|
|
|
|
|
|
|
|
unset IFS
|
|
|
|
# set -f # if you are paranoid use set -f to disable globbing
|
2019-03-27 14:03:02 +00:00
|
|
|
|
2020-08-01 09:37:32 +00:00
|
|
|
#-----------------------------
|
2020-05-14 11:27:53 +00:00
|
|
|
# this file *MUST* not edited!
|
2020-09-06 16:50:12 +00:00
|
|
|
# copy "mycommands.sh.dist" to "mycommands.sh" and change the strings there
|
2019-05-02 13:14:18 +00:00
|
|
|
bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
|
2019-04-11 11:53:01 +00:00
|
|
|
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
|
2020-06-11 07:23:03 +00:00
|
|
|
It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
|
2019-04-11 11:53:01 +00:00
|
|
|
'
|
|
|
|
|
2020-08-01 09:37:32 +00:00
|
|
|
#-----------------------------
|
2020-05-14 11:27:53 +00:00
|
|
|
# this file *MUST* not edited!
|
2020-09-06 16:50:12 +00:00
|
|
|
# copy "mycommands.sh.dist" to "mycommands.sh" and change the strings there
|
2020-12-14 14:43:50 +00:00
|
|
|
bashbot_help='
|
2020-06-11 06:33:59 +00:00
|
|
|
*Available commands*:
|
2019-04-11 11:53:01 +00:00
|
|
|
*• /start*: _Start bot and get this message_.
|
2019-04-27 11:36:32 +00:00
|
|
|
*• /help*: _Get this message_.
|
2019-04-11 11:53:01 +00:00
|
|
|
*• /info*: _Get shorter info message about this bot_.
|
2020-12-14 14:43:50 +00:00
|
|
|
*• /question*: _Start interactive chat (mycommands.dist)_.
|
|
|
|
*• /cancel*: _Cancel any currently running interactive chat_.
|
|
|
|
*• /kickme*: _You will be autokicked from the group_.
|
2019-04-11 11:53:01 +00:00
|
|
|
*• /leavechat*: _The bot will leave the group with this command _.
|
2020-12-14 14:43:50 +00:00
|
|
|
Written by Drew (@topkecleon) and KayM (@gnadelwartz).
|
2019-04-11 11:53:01 +00:00
|
|
|
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
|
|
|
'
|
|
|
|
|
2020-08-01 09:37:32 +00:00
|
|
|
# load modules on startup and always on on debug
|
2021-01-05 15:17:34 +00:00
|
|
|
if [ -n "$1" ]; then
|
2020-05-20 14:35:22 +00:00
|
|
|
# load all readable modules
|
|
|
|
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
2021-01-05 15:17:34 +00:00
|
|
|
if [[ "$1" == *"debug"* ]] || ! _is_function "$(basename "${modules}")"; then
|
2019-05-12 15:51:52 +00:00
|
|
|
# shellcheck source=./modules/aliases.sh
|
2021-01-05 15:17:34 +00:00
|
|
|
[ -r "${modules}" ] && source "${modules}" "$1"
|
2020-05-20 14:35:22 +00:00
|
|
|
fi
|
|
|
|
done
|
2019-05-08 12:54:01 +00:00
|
|
|
fi
|
2019-04-24 11:34:44 +00:00
|
|
|
|
2020-08-01 09:37:32 +00:00
|
|
|
#----------------------------
|
2020-05-14 11:27:53 +00:00
|
|
|
# this file *MUST* not edited!
|
2020-09-06 16:50:12 +00:00
|
|
|
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values there
|
2020-12-14 19:35:45 +00:00
|
|
|
# defaults to no inline, all commands and nonsense home dir
|
2019-05-12 15:51:52 +00:00
|
|
|
export INLINE="0"
|
2021-01-25 13:52:47 +00:00
|
|
|
export CALLBACK="0"
|
2020-12-14 19:35:45 +00:00
|
|
|
export MEONLY="0"
|
2020-05-20 14:35:22 +00:00
|
|
|
export FILE_REGEX="${BASHBOT_ETC}/.*"
|
2019-05-12 15:51:52 +00:00
|
|
|
|
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
# load mycommands
|
|
|
|
# shellcheck source=./commands.sh
|
2021-01-05 15:17:34 +00:00
|
|
|
[ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" "$1"
|
2019-04-23 19:52:57 +00:00
|
|
|
|
2019-04-12 12:04:57 +00:00
|
|
|
|
2021-01-05 15:17:34 +00:00
|
|
|
if [ -z "$1" ] || [[ "$1" == *"debug"* ]];then
|
2021-01-25 13:52:47 +00:00
|
|
|
#################
|
|
|
|
# detect inline and callback query
|
2021-01-25 15:49:15 +00:00
|
|
|
if [ -n "${iQUERY[ID]}" ]; then
|
|
|
|
# forward inline query to optional dispatcher
|
2021-01-26 13:34:25 +00:00
|
|
|
[ "${INLINE:-0}" != "0" ] && _exec_if_function myinlines
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2021-01-25 15:49:15 +00:00
|
|
|
elif [ -n "${iBUTTON[ID]}" ]; then
|
|
|
|
# forward inline query to optional dispatcher
|
2021-01-26 13:34:25 +00:00
|
|
|
[ "${CALLBACK:-0}" != "0" ] && _exec_if_function mycallbacks
|
2021-01-25 13:52:47 +00:00
|
|
|
|
|
|
|
#################
|
|
|
|
# regular command
|
2019-05-02 13:14:18 +00:00
|
|
|
else
|
2020-12-14 19:35:45 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
# if is bashbot is group admin it get commands sent to other bots
|
|
|
|
# set MEONLY=1 to ignore commands for other bots
|
|
|
|
if [[ "${MEONLY}" != "0" && "${MESSAGE}" == "/"* && "${MESSAGE%% *}" == *"@"* ]]; then
|
|
|
|
# here we have a command with @xyz_bot added, check if it's our bot
|
|
|
|
MYCHECK="${MESSAGE%% *}"
|
|
|
|
[ "${MYCHECK}" != "${MYCHECK%%@${ME}}" ] && return
|
|
|
|
fi
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2019-05-25 11:31:36 +00:00
|
|
|
###################
|
2019-05-26 19:25:01 +00:00
|
|
|
# user defined commands must placed in mycommands
|
2020-11-29 14:34:00 +00:00
|
|
|
! _is_function mycommands || mycommands
|
2019-05-25 11:31:36 +00:00
|
|
|
|
|
|
|
# run commands if true (0) is returned or if mycommands dose not exist
|
|
|
|
# shellcheck disable=SC2181
|
2019-06-02 10:15:59 +00:00
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
case "${MESSAGE}" in
|
2019-03-27 14:03:02 +00:00
|
|
|
################################################
|
2020-05-14 11:27:53 +00:00
|
|
|
# this file *MUST* not edited!
|
2020-09-06 16:50:12 +00:00
|
|
|
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values and add your commands there
|
2020-05-14 11:27:53 +00:00
|
|
|
#
|
2019-04-27 11:36:32 +00:00
|
|
|
# GLOBAL commands start here, edit messages only
|
2019-06-02 10:15:59 +00:00
|
|
|
'/info'*)
|
2019-11-27 17:47:44 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_info}"
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2019-06-02 10:15:59 +00:00
|
|
|
'/start'*)
|
2016-06-05 10:42:20 +00:00
|
|
|
send_action "${CHAT[ID]}" "typing"
|
2020-12-28 14:11:28 +00:00
|
|
|
MYCOMMANDS="*Note*: MISSING mycommands.sh: copy _mycommands.dist_ or _mycommands.clean_."
|
2020-12-14 14:43:50 +00:00
|
|
|
[ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && MYCOMMANDS="Place your commands and messages in _mycommands.sh_"
|
|
|
|
user_is_botadmin "${USER[ID]}" &&\
|
|
|
|
send_markdownv2_message "${CHAT[ID]}" "You are *BOTADMIN*.\n${MYCOMMANDS}"
|
2020-05-16 06:49:36 +00:00
|
|
|
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "start" ; then
|
2019-06-02 10:15:59 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
2019-04-12 11:14:33 +00:00
|
|
|
else
|
2019-06-02 10:15:59 +00:00
|
|
|
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
|
2019-04-12 12:04:57 +00:00
|
|
|
fi
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2016-06-05 10:42:20 +00:00
|
|
|
|
2019-06-02 10:15:59 +00:00
|
|
|
'/help'*)
|
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
2019-04-27 11:36:32 +00:00
|
|
|
;;
|
2021-01-20 18:50:19 +00:00
|
|
|
'/leavechat'*) # bot leave chat if user is admin in chat
|
2020-05-16 06:49:36 +00:00
|
|
|
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "leave" ; then
|
2019-06-02 10:15:59 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
2020-05-16 06:49:36 +00:00
|
|
|
leave_chat "${CHAT[ID]}"
|
2019-04-11 18:33:39 +00:00
|
|
|
fi
|
2016-06-05 10:42:20 +00:00
|
|
|
;;
|
|
|
|
|
2019-06-02 10:15:59 +00:00
|
|
|
'/kickme'*)
|
|
|
|
kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
|
|
|
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
2016-06-05 11:07:31 +00:00
|
|
|
;;
|
2016-06-05 10:42:20 +00:00
|
|
|
|
2020-06-23 14:35:50 +00:00
|
|
|
'/'*) # discard all unknown commands
|
2020-06-07 11:30:59 +00:00
|
|
|
: ;;
|
|
|
|
*) # forward message to interactive chats
|
2019-05-26 19:25:01 +00:00
|
|
|
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2019-05-25 11:31:36 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
2016-04-19 09:49:35 +00:00
|
|
|
fi
|