2016-04-17 18:00:37 +00:00
|
|
|
#!/bin/bash
|
2019-04-23 19:52:57 +00:00
|
|
|
# file: commands.sh
|
|
|
|
# do not edit this file, instead place all your commands in mycommands.sh
|
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
|
|
|
#
|
2019-05-26 14:50:19 +00:00
|
|
|
#### $$VERSION$$ v0.90-dev2-0-gec85636
|
2019-04-01 16:24:05 +00:00
|
|
|
#
|
2016-04-19 09:49:35 +00:00
|
|
|
|
2019-03-27 14:03:02 +00: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 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
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
# to change the default info message overwrite bashbot_info in mycommands.sh
|
|
|
|
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.
|
|
|
|
It currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
|
|
|
|
'
|
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
# to change the default help messages overwrite in mycommands.sh
|
|
|
|
bashbot_help='*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_.
|
|
|
|
*• /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 15:51:52 +00:00
|
|
|
# load modues on startup and always on on debug
|
|
|
|
if [ "${1}" = "source" ] || [[ "${1}" = *"debug"* ]] ; then
|
|
|
|
# load all readable modules
|
|
|
|
for modules in ${MODULEDIR:-.}/*.sh ; do
|
|
|
|
# shellcheck source=./modules/aliases.sh
|
|
|
|
[ -r "${modules}" ] && source "${modules}" "${1}"
|
|
|
|
done
|
2019-05-08 12:54:01 +00:00
|
|
|
fi
|
2019-04-24 11:34:44 +00:00
|
|
|
|
2019-05-12 15:51:52 +00:00
|
|
|
# defaults to no inline and nonsense home dir
|
|
|
|
export INLINE="0"
|
|
|
|
export FILE_REGEX='/home/user/allowed/.*'
|
|
|
|
|
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
# load mycommands
|
|
|
|
# shellcheck source=./commands.sh
|
|
|
|
[ -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
|
|
|
|
2019-05-02 13:14:18 +00:00
|
|
|
if [ "${1}" != "source" ];then
|
2019-05-12 15:51:52 +00:00
|
|
|
# detect inline commands....
|
|
|
|
# no default commands, all processing is done in myinlines()
|
2019-05-02 13:14:18 +00:00
|
|
|
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
|
|
|
if _is_function process_inline; then
|
2019-05-09 21:34:45 +00:00
|
|
|
# forward iinline query to optional dispatcher
|
|
|
|
_is_function myinlines && myinlines
|
2016-04-18 10:05:31 +00:00
|
|
|
fi
|
2019-05-12 15:51:52 +00:00
|
|
|
|
|
|
|
# regular (gobal) commands ...
|
|
|
|
# your commands are in mycommands()
|
2019-05-02 13:14:18 +00:00
|
|
|
else
|
2019-05-12 15:51:52 +00:00
|
|
|
|
2019-05-25 11:31:36 +00:00
|
|
|
###################
|
|
|
|
# user defined commands must plaed in mycommands
|
|
|
|
! _is_function mycommands || mycommands # return true if not exist!
|
|
|
|
|
|
|
|
# run commands if true (0) is returned or if mycommands dose not exist
|
|
|
|
# shellcheck disable=SC2181
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
case "${MESSAGE}" in
|
2019-03-27 14:03:02 +00:00
|
|
|
################################################
|
2019-04-27 11:36:32 +00:00
|
|
|
# GLOBAL commands start here, edit messages only
|
|
|
|
'/info'*)
|
2019-04-24 11:34:44 +00:00
|
|
|
_markdown_message "${bashbot_info}"
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2019-04-27 11:36:32 +00:00
|
|
|
'/start'*)
|
2016-06-05 10:42:20 +00:00
|
|
|
send_action "${CHAT[ID]}" "typing"
|
2019-04-24 11:34:44 +00:00
|
|
|
_is_botadmin && _markdown_message "You are *BOTADMIN*."
|
2019-05-02 09:10:55 +00:00
|
|
|
if _is_botadmin || _is_allowed "start" ; then
|
|
|
|
_markdown_message "${bashbot_help}"
|
2019-04-12 11:14:33 +00:00
|
|
|
else
|
2019-04-24 11:34:44 +00:00
|
|
|
_message "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-04-27 11:36:32 +00:00
|
|
|
'/help'*)
|
2019-05-02 09:10:55 +00:00
|
|
|
_markdown_message "${bashbot_help}"
|
2019-04-27 11:36:32 +00:00
|
|
|
;;
|
|
|
|
'/leavechat'*) # bot leave chat if user is admin in chat
|
2019-04-15 12:17:18 +00:00
|
|
|
if _is_admin ; then
|
2019-04-24 11:34:44 +00:00
|
|
|
_markdown_message "*LEAVING CHAT...*"
|
|
|
|
_leave
|
2019-04-11 18:33:39 +00:00
|
|
|
fi
|
2016-06-05 10:42:20 +00:00
|
|
|
;;
|
|
|
|
|
2019-04-27 11:36:32 +00:00
|
|
|
'/kickme'*)
|
2019-04-24 11:34:44 +00:00
|
|
|
_kick_user "${USER[ID]}"
|
|
|
|
_unban_user "${USER[ID]}"
|
2016-06-05 11:07:31 +00:00
|
|
|
;;
|
2016-06-05 10:42:20 +00:00
|
|
|
|
2019-04-27 11:36:32 +00:00
|
|
|
'/cancel'*)
|
2019-05-01 17:21:57 +00:00
|
|
|
checkproc
|
2019-04-24 11:34:44 +00:00
|
|
|
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2019-05-02 13:14:18 +00:00
|
|
|
*) # forward messages to optional dispatcher
|
2019-05-20 08:50:51 +00:00
|
|
|
_is_function send_interactive && 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
|