more aliases, use aliases in commands.sh

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-24 13:34:44 +02:00
parent 097a841961
commit 262bb9e805
37 changed files with 112 additions and 60 deletions

View File

@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -168,5 +168,5 @@ That's it!
If you feel that there's something missing or if you found a bug, feel
free to submit a pull request!
latexmath:[\[VERSION\]] v0.70-dev2-17-g92ad9e4
latexmath:[\[VERSION\]] v0.70-dev2-18-g097a841
++++++++++++++++++++++++++++++++++++++++++++++

View File

@ -1,7 +1,7 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# shellcheck disable=SC2009
# shellcheck disable=SC2181

View File

@ -12,7 +12,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -666,7 +666,7 @@ if [ "$1" != "source" ]; then
echo "Sending the broadcast $* to $NUMCOUNT users."
[ "$NUMCOUNT" -gt "300" ] && sleep="sleep 0.5"
shift
while read -r f; do send_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}"
while read -r f; do send__markdown_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}"
;;
"start")
${CLEAR}

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
@ -20,19 +20,16 @@ unset IFS
# set -f # if you are paranoid use set -f to disable globbing
# to change the default info and help messages copy bashbot_info() and bahsbot_help()
# to mycommands.sh and edit the messages there.
if [ "$1" != "source" ]; then
bashbot_info() {
send_markdown_message "${1}" 'This is bashbot, the Telegram bot written entirely in bash.
# to change the default info message overwrite bashbot_info in mycommands.sh
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.
'
}
bashbot_help() {
send_markdown_message "${1}" '*Available commands*:
# to change the default help messages overwrite in mycommands.sh
bashbot_help='*Available commands*:
*• /start*: _Start bot and get this message_.
*• /info*: _Get shorter info message about this bot_.
*• /question*: _Start interactive chat_.
@ -42,11 +39,13 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a
Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwartz).
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
'
}
# load additional modules
[ -r "modules/aliases.sh" ] && source "modules/aliases.sh" # some handy aliases, e.g. _is_admin and _message
# ...
[ -r "modules/aliases.sh" ] && source "modules/aliases.sh"
[ -r "modules/background.sh" ] && source "modules/background.sh"
# ... more modules here ...
# mycommands is the last "module" to source in
# shellcheck source=./commands.sh
[ -r "mycommands.sh" ] && source "mycommands.sh"
@ -60,6 +59,7 @@ if [ "$1" = "source" ];then
FILE_REGEX='/home/user/allowed/.*'
else
if ! tmux ls | grep -v send | grep -q "$copname"; then
# interactive running?
[ ! -z "${URLS[*]}" ] && {
curl -s "${URLS[*]}" -o "$NAME"
send_file "${CHAT[ID]}" "$NAME" "$CAPTION"
@ -91,42 +91,42 @@ else
if [[ "$iQUERY_MSG" = "web" ]]; then
answer_inline_query "$iQUERY_ID" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
fi
fi &
fi & # note the & !
fi
case "$MESSAGE" in
################################################
# DEFAULT commands start here, edit messages only
'/info')
bashbot_info "${CHAT[ID]}"
_markdown_message "${bashbot_info}"
;;
'/start')
send_action "${CHAT[ID]}" "typing"
_is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
_is_botadmin && _markdown_message "You are *BOTADMIN*."
if _is_allowed "start" ; then
bot_help "${CHAT[ID]}"
_markdown_message "${bot_help}"
else
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
_message "You are not allowed to start Bot."
fi
;;
'/leavechat') # bot leave chat if user is admin in chat
if _is_admin ; then
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
leave_chat "${CHAT[ID]}"
_markdown_message "*LEAVING CHAT...*"
_leave
fi
;;
'/kickme')
kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
_kick_user "${USER[ID]}"
_unban_user "${USER[ID]}"
;;
'/cancel')
checkprog
if [ "$res" -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
;;
*) # forward other messages to optional dispatcher
_is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi
_is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running
_is_function mycommands && mycommands
;;
esac

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,3 +1,3 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
bashbot.rc

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -61,5 +61,5 @@ group. This step is up to you actually.
#### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
#### [Prev Advanced Usage](3_advanced.md)
#### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
#### [Prev Expert Use](4_expert.md)
#### [Next Best Practice](5_practice.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -133,19 +133,24 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \
##### kick_chat_member
If your Bot is Admin of a chat he can kick and ban a user.
*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
*alias* _kick_user "${USER[ID]}"
##### unban_chat_member
If your Bot is Admin of a chat he can unban a kicked user.
*usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
*alias* _unban "${USER[ID]}"
##### leave_chat
Bot will leave given chat.
*usage:* leave_chat "${CHAT[ID]}"
*alias* _leave
```bash
if _is_admin ; then
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
@ -229,6 +234,26 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to
----
##### kick_chat_member
*usage:* _kick_user "${USER[ID]}"
*alias for* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
##### unban_chat_member
*usage:* _unban "${USER[ID]}"
*alias for* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
##### leave_chat
*usage:* _leave
*alias for* leave_chat "${CHAT[ID]}"
----
#### _message
*usage:* _message "message"
@ -420,5 +445,5 @@ Send Input from Telegram to waiting Interactive Chat.
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -71,5 +71,5 @@ fi
#### [Prev Function Reference](6_function.md)
#### [Next Bashbot Environment](8_custom.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841

View File

@ -7,7 +7,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
SHELL=/bin/sh

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# source from commands.sh to use the aliases
# some handy aliases for use when processing messages:
@ -21,7 +21,16 @@ _is_creator() {
_is_allowed() {
user_is_allowed "${USER[ID]}" "$1" "${CHAT[ID]}"
}
# same for easy sending messages of messages
_leave() {
leave_chat "${CHAT[ID]}"
}
_kick_user() {
kick_chat_member "${CHAT[ID]}" "${1}"
}
_unban_user() {
unban_chat_member "${CHAT[ID]}" "${1}"
}
# easy sending of messages of messages
_message() {
send_normal_message "${CHAT[ID]}" "$1"
}

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# source from commands.sh if you want ro use interactive or background jobs

10
modules/inline.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# file: modules/inline.sh
# do not edit, this file will be overwritten on update
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.70-dev2-18-g097a841
# source from commands.sh to use the inline functions

View File

@ -2,11 +2,19 @@
# files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
# uncomment the following lines to overwrite info and hel messages
# bashbot_info='This is bashbot, the Telegram bot written entirely in bash.`
#'
# bashbot_help='*Available commands*:
#'
# your additional bahsbot commands
mycommands() {

View File

@ -2,7 +2,7 @@
#
# ADD a new test skeleton to test dir, but does not activate test
#
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
../dev/hooks/pre-commit.sh

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
../dev/hooks/pre-push.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-17-g92ad9e4
#### $$VERSION$$ v0.70-dev2-18-g097a841
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh