Moved customizable settings into commands.sh

This commit is contained in:
Daniil Gentili 2016-04-18 12:05:31 +02:00
parent aebbff855c
commit dfd4bc6fa6
3 changed files with 26 additions and 20 deletions

View File

@ -70,7 +70,7 @@ Clone the repository:
git clone https://github.com/topkecleon/telegram-bot-bash git clone https://github.com/topkecleon/telegram-bot-bash
``` ```
Paste the token on line 15 (instead of tokenhere). Paste the token on line 6 of commands.sh (instead of tokenhere).
Then start editing the commands. Then start editing the commands.
### Receive data ### Receive data
@ -115,7 +115,7 @@ This function also allows a third parameter that disables additional function pa
``` ```
send_message "${USER[ID]}" "lol" "safe" send_message "${USER[ID]}" "lol" "safe"
``` ```
To send images, videos, voice files, photos ecc use the ```send_photo``` function (remember to change the safety Regex @ line 94 to allow sending files only from certain directories): To send images, videos, voice files, photos ecc use the ```send_photo``` function (remember to change the safety Regex @ line 11 of command.sh to allow sending files only from certain directories):
``` ```
send_file "${USER[ID]}" "/home/user/doge.jpg" "Lool" send_file "${USER[ID]}" "/home/user/doge.jpg" "Lool"
``` ```
@ -167,7 +167,7 @@ Please note that you can either send a location or a venue, not both. To send a
The following commands allows users to interact with your bot via *inline queries*. The following commands allows users to interact with your bot via *inline queries*.
In order to enable **inline mode**, send `/setinline` command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bots name. In order to enable **inline mode**, send `/setinline` command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bots name.
Also, edit line 21 from `bashbot.sh` putting a "1". Also, edit line 9 from `commands.sh` putting a "1".
Note that you can't modify the first two parameters of the function `answer_inline_query`, only the ones after them. Note that you can't modify the first two parameters of the function `answer_inline_query`, only the ones after them.
To send messsages or links through an *inline query*: To send messsages or links through an *inline query*:

8
bashbot.sh Executable file → Normal file
View File

@ -12,13 +12,9 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# If you're in Europe, and public domain does not exist, then haha. # If you're in Europe, and public domain does not exist, then haha.
TOKEN='tokenhere' source commands.sh source
TOKEN='197476763:AAGj-kg10J97h7t57DawEJYs_ljxKFuKaJ0'
URL='https://api.telegram.org/bot'$TOKEN URL='https://api.telegram.org/bot'$TOKEN
# Set INLINE to 1 in order to receive inline queries.
# To enable this option in your bot, send the /setinline command to @BotFather.
INLINE=0
SCRIPT="$0" SCRIPT="$0"
MSG_URL=$URL'/sendMessage' MSG_URL=$URL'/sendMessage'
@ -196,7 +192,7 @@ send_file() {
[ "$2" = "" ] && return [ "$2" = "" ] && return
local chat_id=$1 local chat_id=$1
local file=$2 local file=$2
echo "$file" | grep -qE '/home/allowed/.*' || return echo "$file" | grep -qE $FILE_REGEX || return
local ext="${file##*.}" local ext="${file##*.}"
case $ext in case $ext in
"mp3") "mp3")

32
commands.sh Executable file → Normal file
View File

@ -1,16 +1,25 @@
#!/bin/bash #!/bin/bash
# Edit your commands in this file. # Edit your commands in this file.
if ! tmux ls | grep -v send | grep -q $copname; then if [ "$1" = "source" ];then
[ ! -z ${URLS[*]} ] && { # Edit the token in here
TOKEN='tokenhere'
# Set INLINE to 1 in order to receive inline queries.
# To enable this option in your bot, send the /setinline command to @BotFather.
INLINE=0
# Set to .* to allow sending files from all locations
FILE_REGEX='/home/user/allowed/.*'
else
if ! tmux ls | grep -v send | grep -q $copname; then
[ ! -z ${URLS[*]} ] && {
curl -s ${URLS[*]} -o $NAME curl -s ${URLS[*]} -o $NAME
send_file "${USER[ID]}" "$NAME" "$CAPTION" send_file "${USER[ID]}" "$NAME" "$CAPTION"
rm "$NAME" rm "$NAME"
} }
[ ! -z ${LOCATION[*]} ] && send_location "${USER[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" [ ! -z ${LOCATION[*]} ] && send_location "${USER[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}"
# Inline # Inline
if [ $INLINE == 1 ]; then if [ $INLINE == 1 ]; then
# inline query data # inline query data
iUSER[FIRST_NAME]=$(echo "$res" | sed 's/^.*\(first_name.*\)/\1/g' | cut -d '"' -f3 | tail -1) 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[LAST_NAME]=$(echo "$res" | sed 's/^.*\(last_name.*\)/\1/g' | cut -d '"' -f3)
@ -34,8 +43,8 @@ if ! tmux ls | grep -v send | grep -q $copname; then
answer_inline_query "$iQUERY_ID" "article" "Telegram" "https://telegram.org/" answer_inline_query "$iQUERY_ID" "article" "Telegram" "https://telegram.org/"
fi fi
fi fi
fi fi
case $MESSAGE in case $MESSAGE in
'/question') '/question')
startproc "./question" startproc "./question"
;; ;;
@ -62,4 +71,5 @@ Contribute to the project: https://github.com/topkecleon/telegram-bot-bash
*) *)
if tmux ls | grep -v send | grep -q $copname;then inproc; else send_message "${USER[ID]}" "$MESSAGE" "safe";fi if tmux ls | grep -v send | grep -q $copname;then inproc; else send_message "${USER[ID]}" "$MESSAGE" "safe";fi
;; ;;
esac esac
fi