Skip to content

Instantly share code, notes, and snippets.

@shellscriptx
Created February 11, 2019 20:36
Show Gist options
  • Select an option

  • Save shellscriptx/6ca91607972481fc1d57df8040a504cb to your computer and use it in GitHub Desktop.

Select an option

Save shellscriptx/6ca91607972481fc1d57df8040a504cb to your computer and use it in GitHub Desktop.
#!/bin/bash
# Importando API
source ShellBot.sh
# Token do bot
bot_token='<TOKEN_AQUI>'
# Inicializando o bot
ShellBot.init --token "$bot_token" --monitor --flush
add_user(){
local servers ports service1 service2 service3
# Valores válidos.
#(Obs: Os valores precisam estar delimitados por '|' PIPE)
servers='192.168.1.10|192.168.1.20|192.168.1.30'
ports='22|23|8080|7070'
service1='opensips|opensips2|opensisps3'
service2='mysql|sql|firebird'
service3='sb|sb2|sb3'
# Verifica os argumentos do comando.
[[ $2 == +([a-zA-Z0-9_]) ]] &&
[[ $3 == @($servers) ]] &&
[[ $4 == @($ports) ]] &&
[[ $5 == @($service1) ]] &&
[[ $6 == @($service2) ]] &&
[[ $7 == @($service3) ]] || {
# Erro
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
--text '*O comando possui argumentos inválidos !!\n\nSintaxe:*\n\n`/cadastro <cliente> <ip> <portassh> <serviço1> <serviço2> <serviço3>`' \
--parse_mode markdown
return 1
}
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
--text '*Comando executado com sucesso !!*' \
--parse_mode markdown
# XXX COMANDOS AQUI XXX
}
# Regra
ShellBot.setMessageRules --name 'cadastrar_cliente' \
--num_args 7 \
--command '/cadastro' \
--action 'add_user'
while :
do
# Obtem as atualizações
ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30
# Lista o índice das atualizações
for id in $(ShellBot.ListUpdates)
do
# Inicio thread
(
ShellBot.manageRules --update_id $id
:
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
done
done
#FIM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment