From b2fc4052fc7ebd197ef086a9f82aafb5fae2b740 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 20:44:58 +0100 Subject: [PATCH] mycommands.sh: add send_dice example --- commands.sh | 8 +++++--- doc/6_reference.md | 4 ++-- mycommands.sh | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/commands.sh b/commands.sh index 20e5beb..f6d45a0 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-9-g62b6b61 # # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed @@ -42,10 +42,12 @@ bashbot_help=' *• /start*: _Start bot and get this message_. *• /help*: _Get this message_. *• /info*: _Get shorter info message about this bot_. -*• /question*: _Start interactive chat (mycommands.dist)_. -*• /cancel*: _Cancel any currently running interactive chat_. *• /kickme*: _You will be autokicked from the group_. *• /leavechat*: _The bot will leave the group with this command _. +Additional commands from mycommands.dist ... +*• /game*: _throw a die_. +*• /question*: _Start interactive chat_. +*• /cancel*: _Cancel any currently running interactive chat_. Written by Drew (@topkecleon) and KayM (@gnadelwartz). Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ' diff --git a/doc/6_reference.md b/doc/6_reference.md index fbb7b55..3b68eef 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -190,7 +190,7 @@ Dice can have values 1-6 for '🎲' and '🎯', values 1-5 for '🏀' and '⚽', ```bash # send die and output points send_dice "${CHAT[ID]}" ":game_die:" -[ "$BOTSENT[ok]" = "true ] && send_markdownv2_message "*Congratulation* you got *${BOTSENT[RESULT]} Points*." +[ "${BOTSENT[OK]}" = "true" ] && send_markdownv2_message "${CHAT[ID]}" "*Congratulation* you got *${BOTSENT[RESULT]} Point(s)*." ``` ---- @@ -1641,5 +1641,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.45-dev-8-g069570e +#### $$VERSION$$ v1.45-dev-9-g62b6b61 diff --git a/mycommands.sh b/mycommands.sh index c8fcd2c..0b87ffd 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-9-g62b6b61 ####################################################### # shellcheck disable=SC1117 @@ -123,7 +123,20 @@ else case "${MESSAGE}" in ################## - # example commands, replace thm by your own + # example commands, replace them by your own + '/game'*) # send random dice 1-5 + send_dice "${CHAT[ID]}" "$(shuf -i "1-5" -n 1)" + if [ "${BOTSENT[OK]}" = "true" ]; then + local gameresult="*Congratulation* you got *${BOTSENT[RESULT]} Points*." + sleep 5 + case "${BOTSENT[RESULT]}" in + 1) gameresult="*Sorry* only *one Point* ...";; + 2) gameresult="*Hey*, 2 Points are *more then one!*";; + 64) gameresult="*JACKPOT! ${BOTSENT[RESULT]} Points!*" + esac + send_markdownv2_message "${CHAT[ID]}" "${gameresult}" + fi + ;; '/unpin'*) # unpin all messages if (bot)admin or allowed for user user_is_allowed "${USER[ID]}" "unpin" "${CHAT[ID]}" &&\ unpinall_chat_messages "${CHAT[ID]}"