#!/bin/bash
clear
#--------@Resurrection SSH-----------#
source ShellBot.sh
touch lista
[[ -z $1 ]] && {
    clear && echo "INFORME O TOKEN DO BOT" && return 0
}
[[ ! -e RESET ]] && touch RESET
api_bot=$1
ShellBot.init --token "$api_bot" --monitor --flush
ShellBot.username

# - Funcao menu
menu() {
    local msg
        ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
        --text "🤖" \
        msg="________________________________\n"
        msg+="<b>|🧑‍💻 OLA SEJA BEM VINDO(a) 🧑‍💻|</b>\n"
        msg+="—————————————————––\n|😁Gere seu teste agora mesmo!|\n| ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ    ㅤ |\n| Esse teste será de apenas 1 h   |\n| ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ     |\n| Caso goste compre o acesso    |\n| premium que dura o mês todo. |\n| por apenas 💸15,00😉 ㅤㅤㅤ    |\n—————————————————––\n\nAproveite. 😉 ass @leandrodts"
        ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
        --text "$(echo -e $msg)" \
        --reply_markup "$keyboard1" \
        --parse_mode html
        return 0
}

# - funcao criar ssh
criarteste() {
    [[ $(grep -wc ${callback_query_from_id} lista) != '0' ]] && {
      ShellBot.sendMessage --chat_id ${callback_query_message_chat_id} \
        --text "😁️ VOCÊ JA CRIOU SEU TESTE HOJE 😁️"
      return 0
    }
    usuario=$(echo teste$(( RANDOM% + 99 )))
    senha=$((RANDOM% + 999999))
    limite='2'
    tempo='2'
    tuserdate=$(date '+%C%y/%m/%d' -d " +1 days")
    useradd -M -N -s /bin/false $usuario -e $tuserdate > /dev/null 2>&1
    (echo "$senha";echo "$senha") | passwd $usuario > /dev/null 2>&1
    echo "$senha" > /etc/SSHPlus/senha/$usuario
    echo "$usuario $limite" >> /root/usuarios.db
    echo "#!/bin/bash
pkill -f "$usuario"
userdel --force $usuario
grep -v ^$usuario[[:space:]] /root/usuarios.db > /tmp/ph ; cat /tmp/ph > /root/usuarios.db
rm /etc/SSHPlus/senha/$usuario > /dev/null 2>&1
rm -rf /etc/SSHPlus/userteste/$usuario.sh" > /etc/SSHPlus/userteste/$usuario.sh
    chmod +x /etc/SSHPlus/userteste/$usuario.sh
    at -f /etc/SSHPlus/userteste/$usuario.sh now + $tempo hour > /dev/null 2>&1
    echo ${callback_query_from_id} > lista
    # - ENVIA O SSH
    ShellBot.sendMessage --chat_id ${callback_query_message_chat_id} \
    --text "$(echo -e "✅ <b>Criado com sucesso</b> ✅\n\n🌐SERVIDOR: BRASIL [01]\n👤USUARIO: <code>$usuario</code>\n🔑SENHA: <code>$senha</code>\<n\n⏳ Expira em: $tempo Hora")" \
    --parse_mode html
    return 0
}

#enviar app
enviarapp() {
    ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} \
        --text "⬇️️ ENVIANDO APLICATIVO, AGUARDE..."
    ShellBot.sendDocument --chat_id ${callback_query_message_chat_id} \
        --document "@/root/MT4G V1.0.2.apk" \
    return 0


    }

#informacoes usuario
infouser () {
	ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
	--text "$(echo -e "Nome:  ${message_from_first_name[$(ShellBot.ListUpdates)]}\nUser: @${message_from_username[$(ShellBot.ListUpdates)]:-null}")\nID: ${message_from_id[$(ShellBot.ListUpdates)]} " \
	--parse_mode html
	return 0
}

unset botao1
botao1=''
ShellBot.InlineKeyboardButton --button 'botao1' --line 1 --text '♻️ GERAR TESTE ♻️' --callback_data 'gerarssh'
ShellBot.InlineKeyboardButton --button 'botao1' --line 3 --text '🔰 BAIXAR APLICATIVO 🔰' --callback_data 'appenviar'
ShellBot.InlineKeyboardButton --button 'botao1' --line 5 --text '🔰 COMPRAR LOGIN "PIX"🔰️️'  --callback_data '3' --url ' https://iti.itau/receber/pix/?saleId=24e79232-7b82-40b9-9986-d54c9c157225 '
ShellBot.InlineKeyboardButton --button 'botao1' --line 6 --text '📃 ENVIAR COMPROVANTE PAGAMENTO 📃' --callback_data '3' --url 'https://wa.me/5527996192080'
ShellBot.InlineKeyboardButton --button 'botao1' --line 7 --text '🧑‍💻SUPORTE WHATSAPP🧑‍💻️️'  --callback_data '3' --url 'https://wa.me/5527996192080'
ShellBot.InlineKeyboardButton --button 'botao1' --line 8 --text '👩‍💻 TELEGRAM 🧑‍💻️️'  --callback_data '3' --url 'https://t.me/resurrectionssh'
ShellBot.regHandleFunction --function criarteste --callback_data gerarssh
ShellBot.regHandleFunction --function enviarapp --callback_data appenviar
unset keyboard1
keyboard1="$(ShellBot.InlineKeyboardMarkup -b 'botao1')"
while :; do
   [[ "$(date +%d)" != "$(cat RESET)" ]] && {
   	echo $(date +%d) > RESET
   	echo ' ' > lista
   }
  ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 24
  for id in $(ShellBot.ListUpdates); do
    (
      ShellBot.watchHandle --callback_data ${callback_query_data[$id]}
      comando=(${message_text[$id]})
      [[ "${comando[0]}" = "/menu"  || "${comando[0]}" = "/start" ]] && menu
      [[ "${comando[0]}" = "/id"  ]] && infouser
    ) &
  done
done