Skip to content

Commit 81f177a

Browse files
committed
Novo método "ShellBot.getMyCommands" para obter a lista atual dos comandos do bot.
1 parent c6c9ad8 commit 81f177a

16 files changed

Lines changed: 12190 additions & 0 deletions

-

Whitespace-only changes.

BotDownloadFile1.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
#
3+
# SCRIPT: BotDownloadFile1.sh
4+
#
5+
# DESCRIÇÃO: Efetua download dos arquivos enviados para o privado, grupo ou canal.
6+
# Em grupos/canais o bot precisa ser administrador para ter acesso a
7+
# todas mensagens enviadas.
8+
#
9+
# Para melhor compreensão foram utilizados parâmetros longos nas funções; Podendo
10+
# ser substituidos pelos parâmetros curtos respectivos.
11+
12+
# Importando API
13+
source ShellBot.sh
14+
15+
# Token do bot
16+
bot_token='371714654:AAF1Vujtoi81zjwFjpb-qdGJFspK0HuwUD0'
17+
18+
# Inicializando o bot
19+
ShellBot.init --token "$bot_token" --monitor --return map
20+
21+
function download_file()
22+
{
23+
local file_id
24+
25+
if [[ ${message_photo_file_id[$id]} ]]; then
26+
# Em alguns arquivos de imagem o telegram aplica uma escala de tamanho
27+
# gerando id's para diferentes resoluções da mesma iagem. São elas (baixa, média, alta).
28+
# Os id's são armazenados e separados pelo delimitador '|' (padrão).
29+
#
30+
# Exemplo:
31+
# baixa_id|media_id|alta_id
32+
33+
# Extrai o id da imagem com melhor resolução.
34+
file_id=${message_photo_file_id[$id]##*|}
35+
else
36+
# Outros objetos.
37+
# Extrai o id do objeto da mensagem.
38+
# document, audio, sticker, voice
39+
file_id=$(cat << _eof
40+
${message_document_file_id[$id]}
41+
${message_audio_file_id[$id]}
42+
${message_sticker_file_id[$id]}
43+
${message_voice_file_id[$id]}
44+
_eof
45+
)
46+
fi
47+
48+
# Verifica se 'file_id' contém um id válido.
49+
if [[ $file_id ]]; then
50+
# Obtém informações do arquivo, incluindo sua localização nos servidores do Telegram.
51+
ShellBot.getFile --file_id $file_id
52+
53+
# Baixa o arquivo do diretório remoto contido em '{return[file_path]}' após
54+
# a chamada do método 'ShellBot.getFile'.
55+
# Obs: Recurso disponível somente no modo de retorno 'map'.
56+
if ShellBot.downloadFile --file_path "${return[file_path]}" --dir "$HOME"; then
57+
ShellBot.sendMessage --chat_id "${message_chat_id[$id]}" \
58+
--reply_to_message_id "${message_message_id[$id]}" \
59+
--text "Arquivo baixado com sucesso!!\n\nSalvo em: ${return[file_path]}"
60+
fi
61+
fi
62+
63+
return 0
64+
}
65+
66+
while :
67+
do
68+
# Obtem as atualizações
69+
ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30
70+
71+
# Lista o índice das atualizações
72+
for id in $(ShellBot.ListUpdates)
73+
do
74+
# Inicio thread
75+
(
76+
# Executa a função 'download_file' se a requisição não for um objeto de texto.
77+
[[ ${message_text[$id]} ]] || download_file
78+
79+
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
80+
done
81+
done
82+
#FIM

InlineKeyboard.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
#
3+
4+
# Importando API
5+
source ShellBot.sh
6+
7+
# Token do bot
8+
bot_token='371714654:AAF1Vujtoi81zjwFjpb-qdGJFspK0HuwUD0'
9+
10+
# Inicializando o bot
11+
ShellBot.init --token "$bot_token" --monitor --return map --flush
12+
13+
readonly ICON_ARROW_DOWN='\U2B07'
14+
readonly ICON_OUTBOX='\U1F4E4'
15+
readonly ICON_CLIPBOARD='\U1F4CB'
16+
readonly ICON_HOUSE='\U1F3E0'
17+
readonly ICON_CLOCK='\U23F0'
18+
19+
function form_aviso()
20+
{
21+
local btn=
22+
23+
ShellBot.InlineKeyboardButton --button 'btn' --line 1 --text "$ICON_CLIPBOARD Aviso" --callback_data 'btn_aviso'
24+
ShellBot.InlineKeyboardButton --button 'btn' --line 2 --text "$ICON_HOUSE Cidade" --callback_data 'btn_cidade'
25+
ShellBot.InlineKeyboardButton --button 'btn' --line 3 --text "$ICON_CLOCK Previsão" --callback_data 'btn_previsao'
26+
ShellBot.InlineKeyboardButton --button 'btn' --line 4 --text "$ICON_OUTBOX Enviar" --callback_data 'btn_enviar'
27+
28+
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
29+
--text 'Selecione todas as opções do formulário.' \
30+
--parse_mode markdown \
31+
--reply_markup "$(ShellBot.InlineKeyboardMarkup --button 'btn')"
32+
33+
return 0
34+
}
35+
36+
function btn_aviso()
37+
{
38+
local avisos aviso btn
39+
40+
btn=
41+
avisos=('Ligar' 'Desligar')
42+
43+
echo "${callback_query_message_reply_markup_inline_keyboard_text[$id]}" > /tmp/${callback_query_id[$id]}
44+
45+
for aviso in "${avisos[@]}"; do
46+
ShellBot.InlineKeyboardButton --button 'btn' --line $((++c)) --text "$aviso" --callback_data 'form_aviso'
47+
done
48+
49+
ShellBot.sendPhoto --chat_id ${callback_query_message_chat_id[$id]} --photo '@ShellBot.png'
50+
51+
ShellBot.editMessageText --chat_id ${callback_query_chat_id[$id]} \
52+
--message_id ${callback_query_message_message_id[$id]} \
53+
--parse_mode markdown
54+
55+
56+
}
57+
58+
while :
59+
do
60+
# Obtem as atualizações
61+
ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30
62+
63+
# Lista o índice das atualizações
64+
for id in $(ShellBot.ListUpdates)
65+
do
66+
# Inicio thread
67+
(
68+
# Se a mensagem enviada é uma url.
69+
case ${message_text[$id]} in
70+
'/aviso') form_aviso; continue;;
71+
esac
72+
73+
# Envia notificação.
74+
${callback_query_id[$id]:+ShellBot.answerCallbackQuery --callback_query_id ${callback_query_id[$id]} --text 'Tudo certo jovem' --show_alert true}
75+
76+
case ${callback_query_data[$id]} in
77+
'btn_aviso') btn_aviso;;
78+
esac
79+
80+
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
81+
done
82+
done
83+
#FIM

InlineYoutube.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# XXX SOBRE XXX
4+
#
5+
# script: InlineYoutube.sh
6+
#
7+
# O script implementa um Bot Inline semelhante ao '@vid' que realiza
8+
# consultas de vídeos no site do youtube.
9+
#
10+
# Para melhor compreensão foram utilizados parâmetros longos nas funções; Podendo
11+
# ser substituidos pelos parâmetros curtos respectivos.
12+
#
13+
# XXX ATENÇÃO XXX
14+
#
15+
# É necessário habilitar o modo inline. Para ativar essa opção, envie o
16+
# comando /setinline para @BotFather e forneça o texto de espaço reservado
17+
# que o usuário verá no campo de entrada depois de digitar o nome do seu bot.
18+
19+
# Importando API
20+
source ShellBot.sh
21+
22+
# Token do bot
23+
bot_token='371714654:AAF1Vujtoi81zjwFjpb-qdGJFspK0HuwUD0'
24+
25+
# Inicializando o bot
26+
ShellBot.init --token "$bot_token" --monitor --return map
27+
28+
yt_video()
29+
{
30+
local vid title views
31+
local resp yt_video query vids i
32+
local re_vid re_vt re_vv
33+
34+
yt_video='https://www.youtube.com/watch?v=' # URI
35+
36+
# Regex
37+
re_vid='href="/watch\?v=([a-zA-Z0-9_-]+)"' # ID
38+
re_vt='title="([^"]+)' # Título
39+
re_vv='<li>([0-9.]+\s+(visualizações|views))</li>' # Visualizações
40+
41+
query=''
42+
43+
while read -r resp; do
44+
# Extrai as informações do video. (se presente)
45+
if [[ $resp =~ $re_vid ]] && vid=${BASH_REMATCH[1]} &&
46+
[[ $resp =~ $re_vt ]] && title=${BASH_REMATCH[1]} &&
47+
[[ $resp =~ $re_vv ]] && views=${BASH_REMATCH[1]}; then
48+
49+
# Salta para o próximo elemento caso já exista.
50+
[[ $vid == @($vids) ]] && continue
51+
52+
# Cria/anexa o objeto video a query de resultado.
53+
ShellBot.InlineQueryResult --input query \
54+
--type video \
55+
--mime_type 'video/mp4' \
56+
--id "$vid" \
57+
--video_url "${yt_video}${vid}" \
58+
--thumb_url "https://i.ytimg.com/vi/${vid}/hqdefault.jpg" \
59+
--title "${title}" \
60+
--description "${views}" \
61+
--input_message_content "$(ShellBot.InputMessageContent --message_text "${yt_video}${vid}")" # Envia o link caso o usuário clique no video da lista.
62+
63+
# 50 resultados por query. (limite máximo suportado pelo Telegram)
64+
[[ $((++i)) -eq 50 ]] && break
65+
66+
# Atualiza a lista com o objeto criado.
67+
vids+=${vids:+|}$vid
68+
fi
69+
# Envia uma requisição a uri de pesquisa do youtube com o video especificado na query de consulta.
70+
done < <(wget -qO- "https://www.youtube.com/results?search_query=${inline_query_query[$id]// /+}")
71+
72+
# Envia a query com os resultados da consulta.
73+
ShellBot.answerInlineQuery --inline_query_id ${inline_query_id[$id]} \
74+
--results "$query"
75+
76+
return $?
77+
}
78+
79+
while :
80+
do
81+
# Obtem as atualizações
82+
ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30
83+
84+
# Lista o índice das atualizações
85+
for id in $(ShellBot.ListUpdates)
86+
do
87+
# Inicio thread
88+
(
89+
# Executa a função caso uma consulta inline for iniciada.
90+
[[ $inline_query_id ]] && yt_video
91+
92+
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
93+
done
94+
done
95+
#FIM

0 commit comments

Comments
 (0)