2016-04-17 18:00:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Edit your commands in this file.
|
|
|
|
|
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-04-01 17:13:13 +00:00
|
|
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
2019-04-01 16:24:05 +00:00
|
|
|
#
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
# shellcheck disable=SC2034
|
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
|
|
|
|
2016-04-18 10:05:31 +00:00
|
|
|
if [ "$1" = "source" ];then
|
2016-05-13 15:45:56 +00:00
|
|
|
# Place the token in the token file
|
2019-03-30 14:11:33 +00:00
|
|
|
TOKEN="$(cat token)"
|
2016-04-19 09:49:35 +00:00
|
|
|
# Set INLINE to 1 in order to receive inline queries.
|
2016-04-18 10:05:31 +00:00
|
|
|
# To enable this option in your bot, send the /setinline command to @BotFather.
|
2019-03-30 14:11:33 +00:00
|
|
|
INLINE="0"
|
2016-04-18 10:05:31 +00:00
|
|
|
# Set to .* to allow sending files from all locations
|
|
|
|
FILE_REGEX='/home/user/allowed/.*'
|
|
|
|
else
|
2019-03-30 14:11:33 +00:00
|
|
|
if ! tmux ls | grep -v send | grep -q "$copname"; then
|
|
|
|
[ ! -z "${URLS[*]}" ] && {
|
2019-04-01 16:24:05 +00:00
|
|
|
curl -s "${URLS[*]}" -o "$NAME"
|
2016-06-05 10:42:20 +00:00
|
|
|
send_file "${CHAT[ID]}" "$NAME" "$CAPTION"
|
2019-03-28 19:59:52 +00:00
|
|
|
rm -f "$NAME"
|
2016-04-18 10:05:31 +00:00
|
|
|
}
|
2019-04-01 16:24:05 +00:00
|
|
|
[ ! -z "${LOCATION[*]}" ] && send_location "${CHAT[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}"
|
2016-04-19 09:49:35 +00:00
|
|
|
|
|
|
|
# Inline
|
2016-04-18 10:05:31 +00:00
|
|
|
if [ $INLINE == 1 ]; then
|
2016-04-17 18:00:37 +00:00
|
|
|
# inline query data
|
2019-03-30 14:11:33 +00:00
|
|
|
iUSER[FIRST_NAME]="$(echo "$res" | sed 's/^.*\(first_name.*\)/\1/g' | cut -d '"' -f3 | tail -1)"
|
|
|
|
iUSER[LAST_NAME]="$(echo "$res" | sed 's/^.*\(last_name.*\)/\1/g' | cut -d '"' -f3)"
|
|
|
|
iUSER[USERNAME]="$(echo "$res" | sed 's/^.*\(username.*\)/\1/g' | cut -d '"' -f3 | tail -1)"
|
|
|
|
iQUERY_ID="$(echo "$res" | sed 's/^.*\(inline_query.*\)/\1/g' | cut -d '"' -f5 | tail -1)"
|
|
|
|
iQUERY_MSG="$(echo "$res" | sed 's/^.*\(inline_query.*\)/\1/g' | cut -d '"' -f5 | tail -6 | head -1)"
|
2016-04-19 09:49:35 +00:00
|
|
|
|
2016-04-17 18:00:37 +00:00
|
|
|
# Inline examples
|
2019-03-30 14:11:33 +00:00
|
|
|
if [[ "$iQUERY_MSG" == "photo" ]]; then
|
2016-04-17 18:00:37 +00:00
|
|
|
answer_inline_query "$iQUERY_ID" "photo" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg" "http://blog.techhysahil.com/wp-content/uploads/2016/01/Bash_Scripting.jpeg"
|
|
|
|
fi
|
2016-04-19 09:49:35 +00:00
|
|
|
|
2019-03-30 14:11:33 +00:00
|
|
|
if [[ "$iQUERY_MSG" == "sticker" ]]; then
|
2016-04-17 18:00:37 +00:00
|
|
|
answer_inline_query "$iQUERY_ID" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
|
|
|
|
fi
|
2016-04-19 09:49:35 +00:00
|
|
|
|
2019-03-30 14:11:33 +00:00
|
|
|
if [[ "$iQUERY_MSG" == "gif" ]]; then
|
2016-04-17 18:00:37 +00:00
|
|
|
answer_inline_query "$iQUERY_ID" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
|
|
|
|
fi
|
2019-03-30 14:11:33 +00:00
|
|
|
if [[ "$iQUERY_MSG" == "web" ]]; then
|
2016-06-05 10:42:20 +00:00
|
|
|
answer_inline_query "$iQUERY_ID" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
|
2016-04-17 18:00:37 +00:00
|
|
|
fi
|
2016-10-24 22:13:52 +00:00
|
|
|
fi &
|
2016-04-18 10:05:31 +00:00
|
|
|
fi
|
2019-02-28 19:26:26 +00:00
|
|
|
case "$MESSAGE" in
|
2016-04-17 18:00:37 +00:00
|
|
|
'/question')
|
2019-03-18 14:32:17 +00:00
|
|
|
checkproc
|
2019-04-01 16:24:05 +00:00
|
|
|
if [ "$res" -gt 0 ] ; then
|
2019-03-18 14:32:17 +00:00
|
|
|
startproc "./question"
|
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
'/run-notify')
|
|
|
|
myback="notify"; checkback "$myback"
|
2019-04-01 16:24:05 +00:00
|
|
|
if [ "$res" -gt 0 ] ; then
|
2019-03-18 14:32:17 +00:00
|
|
|
background "./notify 60" "$myback" # notify every 60 seconds
|
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "Background command $myback already running ..."
|
|
|
|
fi
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2019-03-18 14:32:17 +00:00
|
|
|
'/stop-notify')
|
|
|
|
myback="notify"; checkback "$myback"
|
2019-04-01 16:24:05 +00:00
|
|
|
if [ "$res" -eq 0 ] ; then
|
2019-03-18 14:32:17 +00:00
|
|
|
killback "$myback"
|
|
|
|
send_normal_message "${CHAT[ID]}" "Background command $myback canceled."
|
|
|
|
else
|
|
|
|
send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2019-03-27 14:03:02 +00:00
|
|
|
################################################
|
|
|
|
# DEFAULT commands start here, edit messages only
|
2016-04-17 18:00:37 +00:00
|
|
|
'/info')
|
2016-06-05 10:42:20 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "This is bashbot, the *Telegram* bot written entirely in *bash*."
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
|
|
|
'/start')
|
2016-06-05 10:42:20 +00:00
|
|
|
send_action "${CHAT[ID]}" "typing"
|
2016-06-05 11:07:31 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "This is bashbot, the Telegram bot written entirely in bash.
|
2016-04-19 09:49:35 +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.
|
2016-06-05 10:42:20 +00:00
|
|
|
*Available commands*:
|
|
|
|
*• /start*: _Start bot and get this message_.
|
|
|
|
*• /info*: _Get shorter info message about this bot_.
|
|
|
|
*• /question*: _Start interactive chat_.
|
|
|
|
*• /cancel*: _Cancel any currently running interactive chats_.
|
2016-06-05 11:07:31 +00:00
|
|
|
*• /kickme*: _You will be autokicked from the chat_.
|
|
|
|
*• /leavechat*: _The bot will leave the group with this command _.
|
2016-04-19 09:49:35 +00:00
|
|
|
Written by Drew (@topkecleon) and Daniil Gentili (@danogentili).
|
2016-06-05 10:42:20 +00:00
|
|
|
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
2016-04-17 18:00:37 +00:00
|
|
|
"
|
|
|
|
;;
|
2016-06-05 10:42:20 +00:00
|
|
|
|
|
|
|
'/leavechat')
|
2016-06-09 13:40:39 +00:00
|
|
|
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
2016-06-05 10:42:20 +00:00
|
|
|
leave_chat "${CHAT[ID]}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
'/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
|
|
|
|
2016-04-17 18:00:37 +00:00
|
|
|
'/cancel')
|
2019-03-18 14:32:17 +00:00
|
|
|
checkprog
|
2019-04-01 16:24:05 +00:00
|
|
|
if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
|
|
|
*)
|
2019-04-01 16:24:05 +00:00
|
|
|
if tmux ls | grep -v send | grep -q "$copname";then inproc; else send_message "${CHAT[ID]}" "$MESSAGE" "safe";fi
|
2016-04-17 18:00:37 +00:00
|
|
|
;;
|
2016-04-18 10:05:31 +00:00
|
|
|
esac
|
2016-04-19 09:49:35 +00:00
|
|
|
fi
|