Advertisement
Guest User

function bot BrIsBr

a guest
Jul 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.64 KB | None | 0 0
  1. function run_rank()
  2. {
  3.         unset numero
  4.         numero="${message_from_id[$id]}"
  5.         grupo=$(echo ${message_chat_id[$id]}|sed 's/-//')
  6.                 cat_=$(cat /etc/ShellBot/Usuarios/${grupo}/ranking |grep "$numero"| cut -d'|' -f2)
  7.                 if [[ $cat_ = "" ]]; then
  8.                         echo "$numero|0" >> /etc/ShellBot/Usuarios/${grupo}/ranking
  9.                 else
  10.                         result=$(echo $((1+$cat_)))
  11.                         sed -i "s/$numero|$cat_/$numero|$result/g"  /etc/ShellBot/Usuarios/${grupo}/ranking
  12.                 fi
  13.  
  14. }
  15. function ranking()
  16. {
  17.         local msg
  18.         chamada=(${message_text[$id]})
  19.         verifica_nivel "@${message_from_username[$id]}"
  20.                 if [[ ${chamada[0]} = "/zerar" ]]; then
  21.                         case $nivel in
  22.                                 creator) rm /etc/ShellBot/Usuarios/${grupo}/ranking
  23.                                 msg+="<b>Ranking restaurado!</b>"
  24.                                 ;;
  25.                     member|false|true) msg+="<b>Desculpe, esse comando só pode ser utilizado pelo criador do grupo!</b>"
  26.                                 ;;
  27.                         esac
  28.                 elif [[ ${chamada[0]} = "/ranking" ]]; then
  29.                         case $nivel in
  30.                         true|false|creator)
  31.                         local msg
  32.                 grupo=$(echo ${message_chat_id[$id]}|sed 's/-//')
  33.                 echo "$(cat Usuarios/$grupo/ranking|awk -F'|' '{print $1" - "$2}'| sort -t'-' -nrk2)" > /etc/ShellBot/Usuarios/${grupo}/semi_ranking
  34.                 a=($(cat /etc/ShellBot/Usuarios/${grupo}/semi_ranking|cut -d'-' -f1))
  35.                 for((i=0; i<${#a[@]}; i++)); do
  36.                         nome=$(cat Usuarios/$grupo/${a[$i]}|cut -d'|' -f3)
  37.                         sed -i "s|${a[$i]}|<a href=\"tg://user?id=${a[$i]}\">${nome}</a>|g" /etc/ShellBot/Usuarios/${grupo}/semi_ranking
  38.                 done
  39.                 cd=$(cat /etc/ShellBot/Usuarios/${grupo}/semi_ranking)
  40.                 msg+="<b>RANKING</b>\n$(cat /etc/ShellBot/Usuarios/${grupo}/semi_ranking|sed 's/^/\\n/')\n\nPowered by @BrIsBr_BoT"
  41.                 #ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "$(echo -e $msg)" --parse_mode html
  42.                         ;;
  43.                 *) msg+="<b>Desculpe você não é administrador!</b>"
  44.                                 ;;
  45.                         esac
  46.                 fi
  47.                 ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "$(echo -e $msg)" --parse_mode html
  48. }
  49.  
  50. # o run_rank fica sendo chamado a todo momento
  51. # o ranking so e chamado quando invocado /ranking ou /zerar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement