Skip to content

Instantly share code, notes, and snippets.

@shellscriptx
Created February 14, 2019 16:50
Show Gist options
  • Select an option

  • Save shellscriptx/808ca2cac3eeace0259ffba8f0bfaafc to your computer and use it in GitHub Desktop.

Select an option

Save shellscriptx/808ca2cac3eeace0259ffba8f0bfaafc 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
comando=""
# Criando 3 botões e define os seus valores.
ShellBot.InlineKeyboardButton --button 'comando' --line 1 --text 'ping' --callback_data 'ping'
hosts=''
ShellBot.InlineKeyboardButton --button 'hosts' --line 1 --text 'google.com' --callback_data 'google.com'
ShellBot.InlineKeyboardButton --button 'hosts' --line 2 --text 'youtube.com' --callback_data 'youtube.com'
# Teclados.
keyboard="$(ShellBot.InlineKeyboardMarkup -b 'comando')"
keyboard2="$(ShellBot.InlineKeyboardMarkup -b 'hosts')"
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
(
# Verifica o botão clicado.
case ${callback_query_data[$id]} in
ping)
ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} --text 'Escolha o host' --reply_markup "$keyboard2"
ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} --text "${callback_query_data[$id]}"
;;
'google.com'|'youtube.com')
output=$(ping -c4 ${callback_query_data[$id]})
ShellBot.sendMessage --chat_id ${callback_query_message_chat_id[$id]} --text "$output"
ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} --text "${callback_query_data[$id]}"
;;
esac
case ${message_text[$id]%% *} in
/menu)
# Envia o teclado principal.
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text "Escolha o comando" --reply_markup "$keyboard"
esac
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment