telegram-bot-bash/commands.sh

134 lines
4.7 KiB
Bash
Raw Normal View History

#!/bin/bash
# file: commands.sh
# _____ _______ _ _ _
# (____ \ _ (_______) | (_)_ | |
# _ \ \ ___ ____ ___ | |_ _____ _ | |_| |_ | |
# | | | / _ \ | _ \ / _ \| _) | ___) / || | | _)|_|
# | |__/ / |_| | | | | | |_| | |__ | |____( (_| | | |__ _
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
#
# this file *MUST* not edited! palce your config and commands in
# the provided mycommnds.sh. a clean version is avalible as mycommands.clean
#
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.94-dev3-1-g8a119f8
2019-04-01 16:24:05 +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
#
# this file *MUST* not edited!
# copy "mycommands,sh,dist" to "mycommnds,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.
It currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
'
#
# this file *MUST* not edited!
# copy "mycommands,sh,dist" to "mycommnds,sh" and change the strings there
2019-05-02 13:14:18 +00:00
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)
'
# load modues on startup and always on on debug
if [ "${1}" = "startbot" ] || [[ "${1}" = *"debug"* ]] ; then
# load all readable modules
2019-12-07 12:25:50 +00:00
for modules in "${MODULEDIR:-.}"/*.sh ; do
# shellcheck source=./modules/aliases.sh
[ -r "${modules}" ] && source "${modules}" "${1}"
done
fi
#
# this file *MUST* not edited!
# copy "mycommands,sh,dist" to "mycommnds,sh" and change the values there
# 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-12 12:04:57 +00:00
if [ "${1}" = "" ] || [[ "${1}" == *"debug"* ]];then
# 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
# forward iinline query to optional dispatcher
_exec_if_function myinlines
# regular (gobal) commands ...
# your commands are in mycommands()
2019-05-02 13:14:18 +00:00
else
2019-05-25 11:31:36 +00:00
###################
2019-05-26 19:25:01 +00:00
# user defined commands must placed in mycommands
_exec_if_function 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
if [ "$?" = "0" ]; then
case "${MESSAGE}" in
################################################
# this file *MUST* not edited!
# copy "mycommands,sh,dist" to "mycommnds,sh" and change the values and add your commands there
#
2019-04-27 11:36:32 +00:00
# GLOBAL commands start here, edit messages only
'/info'*)
2019-11-27 17:47:44 +00:00
send_markdown_message "${CHAT[ID]}" "${bashbot_info}"
;;
'/start'*)
send_action "${CHAT[ID]}" "typing"
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
2019-05-02 09:10:55 +00:00
if _is_botadmin || _is_allowed "start" ; then
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
2019-04-12 11:14:33 +00:00
else
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
2019-04-12 12:04:57 +00:00
fi
;;
'/help'*)
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
2019-04-27 11:36:32 +00:00
;;
'/leavechat'*) # bot leave chat if user is admin in chat
if user_is_botadmin "${USER[ID]}" ; then
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
leave_chat "${CHAT[ID]}"
fi
;;
'/kickme'*)
kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
;;
2019-05-02 13:14:18 +00:00
*) # forward messages to optional dispatcher
2019-05-26 19:25:01 +00:00
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
;;
2019-05-25 11:31:36 +00:00
esac
fi
fi
fi