functions in bash added and colors (#19)
* functions in bash added and colors * Update bashbot.sh * Update bashbot.sh * Update bashbot.sh * Update bashbot.sh * Update bashbot.sh
This commit is contained in:
parent
b2c5793032
commit
d169b7f96f
50
bashbot.sh
50
bashbot.sh
|
@ -16,12 +16,23 @@ if [ ! -f "JSON.sh/JSON.sh" ]; then
|
||||||
echo "JSON.sh has been downloaded. Proceeding."
|
echo "JSON.sh has been downloaded. Proceeding."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "token" ]; then
|
||||||
|
clear
|
||||||
|
echo -e '\e[0;31mTOKEN MISSING.\e[0m'
|
||||||
|
echo "PLEASE WRITE YOUR TOKEN HERE"
|
||||||
|
read token
|
||||||
|
echo "$token" >> token
|
||||||
|
fi
|
||||||
|
|
||||||
source commands.sh source
|
source commands.sh source
|
||||||
URL='https://api.telegram.org/bot'$TOKEN
|
URL='https://api.telegram.org/bot'$TOKEN
|
||||||
|
|
||||||
|
|
||||||
SCRIPT="$0"
|
SCRIPT="$0"
|
||||||
MSG_URL=$URL'/sendMessage'
|
MSG_URL=$URL'/sendMessage'
|
||||||
|
LEAVE_URL=$URL'/leaveChat'
|
||||||
|
KICK_URL=$URL'/kickChatMember'
|
||||||
|
UNBAN_URL=$URL'/unbanChatMember'
|
||||||
PHO_URL=$URL'/sendPhoto'
|
PHO_URL=$URL'/sendPhoto'
|
||||||
AUDIO_URL=$URL'/sendAudio'
|
AUDIO_URL=$URL'/sendAudio'
|
||||||
DOCUMENT_URL=$URL'/sendDocument'
|
DOCUMENT_URL=$URL'/sendDocument'
|
||||||
|
@ -99,13 +110,25 @@ send_text() {
|
||||||
}
|
}
|
||||||
|
|
||||||
send_markdown_message() {
|
send_markdown_message() {
|
||||||
res=$(curl -s "$MSG_URL" -d "chat_id=$1" -d "text=$2" -d "parse_mode=markdown")
|
res=$(curl -s "$MSG_URL" -d "chat_id=$1" -d "text=$2" -d "parse_mode=markdown" -d "disable_web_page_preview=true")
|
||||||
}
|
}
|
||||||
|
|
||||||
send_html_message() {
|
send_html_message() {
|
||||||
res=$(curl -s "$MSG_URL" -F "chat_id=$1" -F "text=$2" -F "parse_mode=html")
|
res=$(curl -s "$MSG_URL" -F "chat_id=$1" -F "text=$2" -F "parse_mode=html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kick_chat_member() {
|
||||||
|
res=$(curl -s "$KICK_URL" -F "chat_id=$1" -F "user_id=$2")
|
||||||
|
}
|
||||||
|
|
||||||
|
unban_chat_member() {
|
||||||
|
res=$(curl -s "$UNBAN_URL" -F "chat_id=$1" -F "user_id=$2")
|
||||||
|
}
|
||||||
|
|
||||||
|
leave_chat() {
|
||||||
|
res=$(curl -s "$LEAVE_URL" -F "chat_id=$1")
|
||||||
|
}
|
||||||
|
|
||||||
answer_inline_query() {
|
answer_inline_query() {
|
||||||
case $2 in
|
case $2 in
|
||||||
"article")
|
"article")
|
||||||
|
@ -263,7 +286,7 @@ startproc() {
|
||||||
killproc
|
killproc
|
||||||
mkfifo /tmp/$copname
|
mkfifo /tmp/$copname
|
||||||
TMUX= tmux new-session -d -s $copname "$* &>/tmp/$copname; echo imprettydarnsuredatdisisdaendofdacmd>/tmp/$copname"
|
TMUX= tmux new-session -d -s $copname "$* &>/tmp/$copname; echo imprettydarnsuredatdisisdaendofdacmd>/tmp/$copname"
|
||||||
TMUX= tmux new-session -d -s sendprocess_$copname "bash $SCRIPT outproc ${USER[ID]} $copname"
|
TMUX= tmux new-session -d -s sendprocess_$copname "bash $SCRIPT outproc ${CHAT[ID]} $copname"
|
||||||
}
|
}
|
||||||
|
|
||||||
killproc() {
|
killproc() {
|
||||||
|
@ -278,9 +301,12 @@ inproc() {
|
||||||
process_client() {
|
process_client() {
|
||||||
# Message
|
# Message
|
||||||
MESSAGE=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
MESSAGE=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
|
||||||
|
# Chat
|
||||||
|
CHAT[ID]=$(echo "$res" | egrep '\["result",0,"message","chat","id"\]' | cut -f 2)
|
||||||
|
|
||||||
# User
|
# User
|
||||||
USER[ID]=$(echo "$res" | egrep '\["result",0,"message","chat","id"\]' | cut -f 2)
|
USER[ID]=$(echo "$res" | egrep '\["result",0,"message","from","id"\]' | cut -f 2)
|
||||||
USER[FIRST_NAME]=$(echo "$res" | egrep '\["result",0,"message","chat","first_name"\]' | cut -f 2 | cut -d '"' -f 2)
|
USER[FIRST_NAME]=$(echo "$res" | egrep '\["result",0,"message","chat","first_name"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
USER[LAST_NAME]=$(echo "$res" | egrep '\["result",0,"message","chat","last_name"\]' | cut -f 2 | cut -d '"' -f 2)
|
USER[LAST_NAME]=$(echo "$res" | egrep '\["result",0,"message","chat","last_name"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
USER[USERNAME]=$(echo "$res" | egrep '\["result",0,"message","chat","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
USER[USERNAME]=$(echo "$res" | egrep '\["result",0,"message","chat","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
@ -313,11 +339,11 @@ process_client() {
|
||||||
NAME="$(echo ${URLS[*]} | sed 's/.*\///g')"
|
NAME="$(echo ${URLS[*]} | sed 's/.*\///g')"
|
||||||
|
|
||||||
# Tmux
|
# Tmux
|
||||||
copname="$ME"_"${USER[ID]}"
|
copname="$ME"_"${CHAT[ID]}"
|
||||||
|
|
||||||
source commands.sh
|
source commands.sh
|
||||||
|
|
||||||
tmpcount="COUNT${USER[ID]}"
|
tmpcount="COUNT${CHAT[ID]}"
|
||||||
cat count | grep -q "$tmpcount" || echo "$tmpcount">>count
|
cat count | grep -q "$tmpcount" || echo "$tmpcount">>count
|
||||||
# To get user count execute bash bashbot.sh count
|
# To get user count execute bash bashbot.sh count
|
||||||
}
|
}
|
||||||
|
@ -357,20 +383,28 @@ case "$1" in
|
||||||
for f in $(cat count);do send_message ${f//COUNT} "$*"; $sleep;done
|
for f in $(cat count);do send_message ${f//COUNT} "$*"; $sleep;done
|
||||||
;;
|
;;
|
||||||
"start")
|
"start")
|
||||||
|
clear
|
||||||
tmux kill-session -t $ME&>/dev/null
|
tmux kill-session -t $ME&>/dev/null
|
||||||
tmux new-session -d -s $ME "bash $SCRIPT startbot" && echo "Bot started successfully. Tmux session name is $ME" || echo "An error occurred while starting the bot."
|
tmux new-session -d -s $ME "bash $SCRIPT startbot" && echo -e '\e[0;32mBot started successfully.\e[0m'
|
||||||
|
echo "Tmux session name $ME" || echo -e '\e[0;31mAn error occurred while starting the bot. \e[0m'
|
||||||
|
send_markdown_message "${CHAT[ID]}" "*Bot started*"
|
||||||
;;
|
;;
|
||||||
"kill")
|
"kill")
|
||||||
|
clear
|
||||||
tmux kill-session -t $ME &>/dev/null
|
tmux kill-session -t $ME &>/dev/null
|
||||||
echo "Bot was killed successfully. "
|
send_markdown_message "${CHAT[ID]}" "*Bot stopped*"
|
||||||
|
echo -e '\e[0;32mOK. Bot stopped successfully.\e[0m'
|
||||||
;;
|
;;
|
||||||
"help")
|
"help")
|
||||||
|
clear
|
||||||
less README.md
|
less README.md
|
||||||
;;
|
;;
|
||||||
"attach")
|
"attach")
|
||||||
tmux attach -t $ME
|
tmux attach -t $ME
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Available arguments: outproc, count, broadcast, start, kill, help, attach"
|
echo -e '\e[0;31mBAD REQUEST\e[0m'
|
||||||
|
echo -e '\e[0;31mAvailable arguments: outproc, count, broadcast, start, kill, help, attach\e[0m'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue