diff --git a/README.md b/README.md index 7a4233c..cac795d 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Clone the repository: 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. ### Receive data @@ -115,7 +115,7 @@ This function also allows a third parameter that disables additional function pa ``` 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" ``` @@ -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*. 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 bot’s 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. To send messsages or links through an *inline query*: diff --git a/bashbot.sh b/bashbot.sh old mode 100755 new mode 100644 index 701318f..15c1c09 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,13 +12,9 @@ # 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. -TOKEN='tokenhere' -TOKEN='197476763:AAGj-kg10J97h7t57DawEJYs_ljxKFuKaJ0' +source commands.sh source 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" MSG_URL=$URL'/sendMessage' @@ -196,7 +192,7 @@ send_file() { [ "$2" = "" ] && return local chat_id=$1 local file=$2 - echo "$file" | grep -qE '/home/allowed/.*' || return + echo "$file" | grep -qE $FILE_REGEX || return local ext="${file##*.}" case $ext in "mp3") diff --git a/commands.sh b/commands.sh old mode 100755 new mode 100644 index b52e957..03c0a88 --- a/commands.sh +++ b/commands.sh @@ -1,16 +1,25 @@ #!/bin/bash # Edit your commands in this file. -if ! tmux ls | grep -v send | grep -q $copname; then - [ ! -z ${URLS[*]} ] && { +if [ "$1" = "source" ];then + # 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 - send_file "${USER[ID]}" "$NAME" "$CAPTION" - rm "$NAME" - } - [ ! -z ${LOCATION[*]} ] && send_location "${USER[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" + send_file "${USER[ID]}" "$NAME" "$CAPTION" + rm "$NAME" + } + [ ! -z ${LOCATION[*]} ] && send_location "${USER[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}" - # Inline - if [ $INLINE == 1 ]; then + # Inline + if [ $INLINE == 1 ]; then # inline query data 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) @@ -34,8 +43,8 @@ if ! tmux ls | grep -v send | grep -q $copname; then answer_inline_query "$iQUERY_ID" "article" "Telegram" "https://telegram.org/" fi fi -fi -case $MESSAGE in + fi + case $MESSAGE in '/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 ;; -esac \ No newline at end of file + esac +fi \ No newline at end of file