2016-04-17 20:00:37 +02:00
|
|
|
#!/bin/bash
|
2019-04-23 21:52:57 +02:00
|
|
|
# file: commands.sh
|
2020-05-14 13:27:53 +02:00
|
|
|
|
|
|
|
# _____ _______ _ _ _
|
|
|
|
# (____ \ _ (_______) | (_)_ | |
|
|
|
|
# _ \ \ ___ ____ ___ | |_ _____ _ | |_| |_ | |
|
|
|
|
# | | | / _ \ | _ \ / _ \| _) | ___) / || | | _)|_|
|
|
|
|
# | |__/ / |_| | | | | | |_| | |__ | |____( (_| | | |__ _
|
|
|
|
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
|
|
|
|
#
|
2020-05-14 14:21:15 +02:00
|
|
|
# this file *MUST* not be edited! palce your config and commands in
|
|
|
|
# the file "mycommnds.sh". a clean version is provided as "mycommands.clean"
|
2020-05-14 13:27:53 +02:00
|
|
|
#
|
2016-04-17 20:00:37 +02:00
|
|
|
|
2016-04-19 05:49:35 -04: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 16:51:33 +01:00
|
|
|
#
|
2020-06-12 11:11:17 +02:00
|
|
|
#### $$VERSION$$ v0.96-0-g3871ca9
|
2019-04-01 18:24:05 +02:00
|
|
|
#
|
2016-04-19 05:49:35 -04:00
|
|
|
|
2019-03-27 15:03:02 +01:00
|
|
|
# adjust your language setting here, e.g.when run from other user or cron.
|
|
|
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
2019-03-30 15:11:33 +01: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 15:03:02 +01:00
|
|
|
|
2020-05-14 13:27:53 +02:00
|
|
|
#
|
|
|
|
# this file *MUST* not edited!
|
2020-05-14 14:21:15 +02:00
|
|
|
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
|
2019-05-02 15:14:18 +02:00
|
|
|
bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
|
2019-04-11 13:53:01 +02:00
|
|
|
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
|
2020-06-11 09:23:03 +02:00
|
|
|
It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
|
2019-04-11 13:53:01 +02:00
|
|
|
'
|
|
|
|
|
2020-05-14 13:27:53 +02:00
|
|
|
#
|
|
|
|
# this file *MUST* not edited!
|
2020-05-14 14:21:15 +02:00
|
|
|
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
|
2020-06-11 08:33:59 +02:00
|
|
|
bashbot_help='Place your own commands and messages in mycommands.sh
|
|
|
|
|
|
|
|
*Available commands*:
|
2019-04-11 13:53:01 +02:00
|
|
|
*• /start*: _Start bot and get this message_.
|
2019-04-27 13:36:32 +02:00
|
|
|
*• /help*: _Get this message_.
|
2019-04-11 13:53:01 +02:00
|
|
|
*• /info*: _Get shorter info message about this bot_.
|
|
|
|
*• /question*: _Start interactive chat_.
|
|
|
|
*• /cancel*: _Cancel any currently running interactive chats_.
|
|
|
|
*• /kickme*: _You will be autokicked from the chat_.
|
|
|
|
*• /leavechat*: _The bot will leave the group with this command _.
|
|
|
|
Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz).
|
|
|
|
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
|
|
|
'
|
|
|
|
|
2019-05-12 17:51:52 +02:00
|
|
|
# load modues on startup and always on on debug
|
2020-05-20 16:35:22 +02:00
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
# load all readable modules
|
|
|
|
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
|
|
|
if [[ "${1}" == *"debug"* ]] || ! _is_function "$(basename "${modules}")"; then
|
2019-05-12 17:51:52 +02:00
|
|
|
# shellcheck source=./modules/aliases.sh
|
|
|
|
[ -r "${modules}" ] && source "${modules}" "${1}"
|
2020-05-20 16:35:22 +02:00
|
|
|
fi
|
|
|
|
done
|
2019-05-08 14:54:01 +02:00
|
|
|
fi
|
2019-04-24 13:34:44 +02:00
|
|
|
|
2020-05-14 13:27:53 +02:00
|
|
|
#
|
|
|
|
# this file *MUST* not edited!
|
2020-05-14 14:21:15 +02:00
|
|
|
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there
|
2019-05-12 17:51:52 +02:00
|
|
|
# defaults to no inline and nonsense home dir
|
|
|
|
export INLINE="0"
|
2020-05-20 16:35:22 +02:00
|
|
|
export FILE_REGEX="${BASHBOT_ETC}/.*"
|
2019-05-12 17:51:52 +02:00
|
|
|
|
|
|
|
|
2019-05-02 15:14:18 +02:00
|
|
|
# load mycommands
|
|
|
|
# shellcheck source=./commands.sh
|
|
|
|
[ -r "${BASHBOT_ETC:-.}/mycommands.sh" ] && source "${BASHBOT_ETC:-.}/mycommands.sh" "${1}"
|
2019-04-23 21:52:57 +02:00
|
|
|
|
2019-04-12 14:04:57 +02:00
|
|
|
|
2020-05-20 16:35:22 +02:00
|
|
|
if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
2019-05-12 17:51:52 +02:00
|
|
|
# detect inline commands....
|
|
|
|
# no default commands, all processing is done in myinlines()
|
2020-05-20 16:35:22 +02:00
|
|
|
if [ "$INLINE" != "0" ] && [ -n "${iQUERY[ID]}" ]; then
|
2019-05-28 21:28:58 +02:00
|
|
|
# forward iinline query to optional dispatcher
|
|
|
|
_exec_if_function myinlines
|
2019-05-12 17:51:52 +02:00
|
|
|
|
|
|
|
# regular (gobal) commands ...
|
|
|
|
# your commands are in mycommands()
|
2019-05-02 15:14:18 +02:00
|
|
|
else
|
2019-05-12 17:51:52 +02:00
|
|
|
|
2019-05-25 13:31:36 +02:00
|
|
|
###################
|
2019-05-26 21:25:01 +02:00
|
|
|
# user defined commands must placed in mycommands
|
|
|
|
_exec_if_function mycommands
|
2019-05-25 13:31:36 +02:00
|
|
|
|
|
|
|
# run commands if true (0) is returned or if mycommands dose not exist
|
|
|
|
# shellcheck disable=SC2181
|
2019-06-02 12:15:59 +02:00
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
case "${MESSAGE}" in
|
2019-03-27 15:03:02 +01:00
|
|
|
################################################
|
2020-05-14 13:27:53 +02:00
|
|
|
# this file *MUST* not edited!
|
2020-05-14 14:21:15 +02:00
|
|
|
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values and add your commands there
|
2020-05-14 13:27:53 +02:00
|
|
|
#
|
2019-04-27 13:36:32 +02:00
|
|
|
# GLOBAL commands start here, edit messages only
|
2019-06-02 12:15:59 +02:00
|
|
|
'/info'*)
|
2019-11-27 18:47:44 +01:00
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_info}"
|
2016-04-17 20:00:37 +02:00
|
|
|
;;
|
2019-06-02 12:15:59 +02:00
|
|
|
'/start'*)
|
2016-06-05 05:42:20 -05:00
|
|
|
send_action "${CHAT[ID]}" "typing"
|
2019-06-02 12:15:59 +02:00
|
|
|
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
2020-05-16 08:49:36 +02:00
|
|
|
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "start" ; then
|
2019-06-02 12:15:59 +02:00
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
2019-04-12 13:14:33 +02:00
|
|
|
else
|
2019-06-02 12:15:59 +02:00
|
|
|
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
|
2019-04-12 14:04:57 +02:00
|
|
|
fi
|
2016-04-17 20:00:37 +02:00
|
|
|
;;
|
2016-06-05 05:42:20 -05:00
|
|
|
|
2019-06-02 12:15:59 +02:00
|
|
|
'/help'*)
|
|
|
|
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
2019-04-27 13:36:32 +02:00
|
|
|
;;
|
2019-06-02 12:15:59 +02:00
|
|
|
'/leavechat'*) # bot leave chat if user is admin in chat
|
2020-05-16 08:49:36 +02:00
|
|
|
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "leave" ; then
|
2019-06-02 12:15:59 +02:00
|
|
|
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
2020-05-16 08:49:36 +02:00
|
|
|
leave_chat "${CHAT[ID]}"
|
2019-04-11 20:33:39 +02:00
|
|
|
fi
|
2016-06-05 05:42:20 -05:00
|
|
|
;;
|
|
|
|
|
2019-06-02 12:15:59 +02:00
|
|
|
'/kickme'*)
|
|
|
|
kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
|
|
|
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
2016-06-05 06:07:31 -05:00
|
|
|
;;
|
2016-06-05 05:42:20 -05:00
|
|
|
|
2020-06-07 13:30:59 +02:00
|
|
|
'/'*) # discard all unkown commands
|
|
|
|
: ;;
|
|
|
|
*) # forward message to interactive chats
|
2019-05-26 21:25:01 +02:00
|
|
|
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
2016-04-17 20:00:37 +02:00
|
|
|
;;
|
2019-05-25 13:31:36 +02:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
2016-04-19 05:49:35 -04:00
|
|
|
fi
|