Add shorter output to dice, to prevent flooding. - annna - Annna the nice friendly bot.
HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
---
DIR commit ad85bee8ce64c56bac98badf9b70dd8b37fa1cbd
DIR parent ee1b69d6dd4d8a0e757f47167dd7d0b51494058d
HTML Author: Annna Robert-Houdin <annna@bitreich.org>
Date: Sat, 20 Dec 2025 21:46:43 +0100
Add shorter output to dice, to prevent flooding.
Diffstat:
M annna-message-common | 4 ++--
M dice | 15 +++++++++++++--
2 files changed, 15 insertions(+), 4 deletions(-)
---
DIR diff --git a/annna-message-common b/annna-message-common
@@ -1000,7 +1000,7 @@ $'\001'"ACTION pokes ${IRC_USER}"$'\001') annna-say "$(echo -e '\001')ACTION pok
qroll="$(($(/home/20h/scm/quantum-rng/quantum-rng) + 1))"
annna-say "${IRC_CMD_USER}, ${qroll} [1d2(scores:[${qroll}])]";;
"${IRC_USER}, please roll "*" for me"*)
- q="${text#* roll }"
+ q="${IRC_PRIVMSG_TEXT#* roll }"
q="${q%for*}"
# https://en.wikipedia.org/wiki/Dice_notation
@@ -1009,7 +1009,7 @@ $'\001'"ACTION pokes ${IRC_USER}"$'\001') annna-say "$(echo -e '\001')ACTION pok
[ "${q}" = "a die " ] && q="d6"
[ "${q}" = "dice " ] && q="d6"
- dicescore="$(dice "${q}")"
+ dicescore="$(dice -vs "${q}")"
annna-say "${IRC_CMD_USER}, ${dicescore}";;
"${IRC_USER}, please tell me your favourite flower"*) annna-say "My favourite flower is the beer flower.";;
"${IRC_USER}, please tell me your favourite color"*) annna-say "My favourite color is yellow.";;
DIR diff --git a/dice b/dice
@@ -12,8 +12,11 @@ def usage(app):
sys.exit(1)
def main(args):
+ doverbose = False
+ doshorten = False
+
try:
- opts, largs = getopt.getopt(args[1:], "h")
+ opts, largs = getopt.getopt(args[1:], "hvs")
except getopt.GetoptError as err:
print(str(err))
usage(args[0])
@@ -21,6 +24,10 @@ def main(args):
for o, a in opts:
if o == "-h":
usage(args[0])
+ elif o == "-s":
+ doshorten = True
+ elif o == "-v":
+ doverbose = True
else:
assert False, "unhandled option"
@@ -35,7 +42,11 @@ def main(args):
except:
print("Invalid pattern.")
else:
- print("%s [%s]" % (score, score.format(verbose=True)))
+ if doshorten == True:
+ print("%s [%s]" \
+ % (score, "%s..." % (str(score.format(verbose=doverbose))[:32])))
+ else:
+ print("%s [%s]" % (score, score.format(verbose=doverbose)))
return 0