From a5975d93c4a1a94264bc122a2fda6f8771f431e2 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 May 2020 14:21:15 +0200 Subject: [PATCH] =?UTF-8?q?provide=20a=20clean=20mycomm=C3=A1nds.sh=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands.sh | 14 +++---- mycommands.sh | 12 ++++-- mycommands.sh.clean | 98 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 mycommands.sh.clean diff --git a/commands.sh b/commands.sh index 7bc7268..63a3f07 100644 --- a/commands.sh +++ b/commands.sh @@ -8,14 +8,14 @@ # | |__/ / |_| | | | | | |_| | |__ | |____( (_| | | |__ _ # |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_| # -# 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 *MUST* not be edited! palce your config and commands in +# the file "mycommnds.sh". a clean version is provided 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 +#### $$VERSION$$ v0.94-dev3-2-gbf8a911 # # adjust your language setting here, e.g.when run from other user or cron. @@ -29,7 +29,7 @@ unset IFS # # this file *MUST* not edited! -# copy "mycommands,sh,dist" to "mycommnds,sh" and change the strings there +# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there bashbot_info='This is bashbot, the Telegram bot written entirely in bash. 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. @@ -37,7 +37,7 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a # # this file *MUST* not edited! -# copy "mycommands,sh,dist" to "mycommnds,sh" and change the strings there +# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there bashbot_help='*Available commands*: *• /start*: _Start bot and get this message_. *• /help*: _Get this message_. @@ -61,7 +61,7 @@ fi # # this file *MUST* not edited! -# copy "mycommands,sh,dist" to "mycommnds,sh" and change the values there +# 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/.*' @@ -93,7 +93,7 @@ if [ "${1}" = "" ] || [[ "${1}" == *"debug"* ]];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 + # copy "mycommands.sh.dist" to "mycommnds.sh" and change the values and add your commands there # # GLOBAL commands start here, edit messages only '/info'*) diff --git a/mycommands.sh b/mycommands.sh index 539a1dd..5299c74 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -1,8 +1,14 @@ #!/bin/bash -# files: mycommands.sh.dist -# copy to mycommands.sh and add all your commands and functions here ... +######### # -#### $$VERSION$$ v0.94-dev3-0-geef955a +# files: mycommands.sh.dist +# +# this is an out of the box test and example file to show what you can do in mycommands.ah +# +# #### if you start to develop you own bot, use the clean version of this file: +# #### mycommands.clean +# +#### $$VERSION$$ v0.94-dev3-2-gbf8a911 # # uncomment the following lines to overwrite info and help messages diff --git a/mycommands.sh.clean b/mycommands.sh.clean new file mode 100644 index 0000000..b219e64 --- /dev/null +++ b/mycommands.sh.clean @@ -0,0 +1,98 @@ +#!/bin/bash +######## +# +# files: mycommands.sh.clean +# copy to mycommands.sh and add all your commands and functions here ... +# +#### $$VERSION$$ v0.94-dev3-2-gbf8a911 +# + +########## +# edit the following lines to fit your bot usage + +bashbot_info='This is bashbot, the Telegram bot written entirely in bash. +' + +bashbot_help='*Available commands*: +' +res="" + +# Set INLINE to 1 in order to receive inline queries. +# To enable this option in your bot ypu must also send the /setinline command to @BotFather. +export INLINE="0" + +# NOTE: this is a regex, not shell globbing! you must use a valid egex, +# '.' matches any charater and '.*' matches all remaining charatcers! +# additionally you must escape special charaters with '\', e.g. '\. \? \[ \*" to match them literally +# do NOT set to .* as this allow sending files from all locations! +export FILE_REGEX='^/home/user/allowed/.*' + +######## +# special network setups may require to provide additional ARGS to curl +# +# example: run bashbot over TOR or SOCKS proxy +# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR +# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS + +if [ "$1" != "source" ];then + # your additional bahsbot commands + # NOTE: command can have @botname attached, you must add * in case tests... + mycommands() { + + case "${MESSAGE}" in + ################## + # example command, replace them by your own + '/echo'*) # example echo command + send_normal_message "${CHAT[ID]}" "$MESSAGE" + ;; + + ########## + # command overwrite examples + # return 0 -> run default command afterwards + # return 1 -> skip possible default commands + '/info'*) # output date in front of regular info + send_normal_message "${CHAT[ID]}" "$(date)" + return 0 + ;; + '/kickme'*) # this will replace the /kickme command + send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*" + return 1 + ;; + esac + } + + myinlines() { + ####################### + # this fuinction is called only if you has set INLINE=1 !! + # shellcheck disable=SC2128 + iQUERY="${iQUERY,,}" + + + case "${iQUERY}" in + ################## + # example inline command, replace it by your own + "image "*) # search images with yahoo + local search="${iQUERY#* }" + answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")" + ;; + esac + } + + ##################### + # place your processing functions here + + # example inline processing function, not really useful + # $1 search parameter + my_image_search(){ + local image result sep="" count="1" + result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/