Add brcon-score system for upcoming brcon2023. - 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 a17d8c98291940275e88fa872143baaddcf951ba DIR parent 49235cbd876bff8cb6a793373af83519b65c931c HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Sat, 5 Aug 2023 09:03:49 +0200 Add brcon-score system for upcoming brcon2023. Diffstat: M annna-message-common | 30 ++++++++++++++++++++++++++++++ A brcon-score | 75 +++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 0 deletions(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -9,6 +9,7 @@ hashtagfile="${modbase}/hashtags/hashtags.txt" idontcaredb="${modbase}/i-dont-care/i-dont-care.txt" printnhashtags=2 brmembers="__20h__ Evil_Bob chripo posativ quinq stateless solene josuah parazyd bin KatolaZ adc" +referees="__20h__" server="$1" ircuser="$(cat ${cfgbase}/${server}/ircuser)" @@ -258,6 +259,9 @@ case "${text}" in "${ircuser}, what the karma?") annna-say -s "${server}" -c "${channel}" "${user}, gophers://bitreich.org/1/irc/karma" ;; +"${ircuser}, what the brcon score?") + annna-say -s "${server}" -c "${channel}" "${user}, gophers://bitreich.org/1/con/$(date +%Y)/score" + ;; "${ircuser}, what the shame?") annna-say -s "${server}" -c "${channel}" "${user}, gophers://bitreich.org/1/irc/shame" ;; @@ -1316,6 +1320,9 @@ case "${text}" in *"arma is a bitch"*) annna-say -s "${server}" -c "${channel}" "${user}, I object! Karma is a nice girl!" ;; +"score "*) + # For referee scoring. + ;; *++|*--|*-=?|*+=?|*+=-?|*-=-?) karmatext="$(karma "${text}")" if [ -n "$karmatext" ]; @@ -1349,3 +1356,26 @@ case "${text}" in ;; esac +# Referee Level. +isreferee=0 +for referee in $referees; +do + [ "$user" = "$referee" ] && isreferee=1 +done +[ $isreferee -lt 1 ] && exit + +case "${text}" in +"score "*) + text="$(printf "%s\n" "${text}" | cut -d' ' -f2-)" + case "${text}" in + *++|*--|*-=?|*+=?|*+=-?|*-=-?) + scoretext="$(brcon-score "${text}")" + if [ -n "$scoretext" ]; + then + annna-say -s "${server}" -c "${channel}" "score: ${scoretext}" + fi + ;; + esac + ;; +esac + DIR diff --git a/brcon-score b/brcon-score @@ -0,0 +1,75 @@ +#!/bin/sh + +karmamodbase="$HOME/bin/modules/brcon-score" +karmadb="${karmamodbase}/score-$(date +%Y).txt" + +function setkarmaval { + if [ -n "$(grep -P "^${1}\t" "${karmadb}")" ]; + then + sed -i "s,^${1}\t.*,${1}\t${2}," "${karmadb}" + else + printf "%s\t%d\n" "${1}" "${2}" >> "${karmadb}" + fi +} + +function parsekarma { + karmatag="$(printf "%s\n" "${1}" | sed -e 's,^\([a-zA-Z_0-9]*\).*$,\1,')" + [ -z "${karmatag}" ] && karmatag="karma" + printf "%s\n" "${karmatag}" +} + +function getkarmaval { + karmatag="${1}" + karmaval="$(grep -P "^${karmatag}\t" "${karmadb}" | cut -f 2)" + [ -z "${karmaval}" ] && printf "0\n" + printf "%s\n" "${karmaval}" +} + +function modifykarma { + karmatag="$1" + karmaval=$(getkarmaval "${karmatag}") + newkarmaval="$(printf "%d%s\n" "${karmaval}" "$2" | bc)" + setkarmaval "${karmatag}" $newkarmaval + printf "%s = %d\n" "$karmatag" "$newkarmaval" +} + +function inckarma { + modifykarma "$1" " + $2" +} + +function deckarma { + modifykarma "$1" " - $2" +} + +function parsechangevalue { + printf "%s\n" "${1}" | sed -e 's,.*[+|-]=\([0-9\-]*\),\1,' +} + +karmastr="$1" +karmatag="$(parsekarma "${karmastr}")" +case "${karmastr}" in +*" "*) + ;; +*","*) + ;; +*+=*) + inckarma "${karmatag}" "$(parsechangevalue "${karmastr}")" + ;; +*++) + inckarma "${karmatag}" "1" + ;; +*-=*) + deckarma "${karmatag}" "$(parsechangevalue "${karmastr}")" + ;; +*--) + deckarma "${karmatag}" "1" + ;; +"${karmatag}") + karmaval="$(getkarmaval "${karmatag}")" + printf "%s = %d\n" "$karmatag" "$karmaval" + ;; +*) + sort -r -k 2 "${karmadb}" | column -t + ;; +esac +