Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shellscriptx/5a2dfbe9a7ccb3be070495c5e0d0e2cc to your computer and use it in GitHub Desktop.
Save shellscriptx/5a2dfbe9a7ccb3be070495c5e0d0e2cc 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

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
	(
		# Remove a nomenclatura do bot e o caractere '@' inclusive, avaliando apenas o comando.
    		# 
    		# Exemplo:
    		#      parse: /comando1@bot1 arg1 arg2
    		#      comando: /comando1
		case ${message_text[$id]%%@*} in
			/comando1)	# comando@bot
          		# Obtem somente os argumentos do comando.
          		# Exemplo:
          		#     parse: /comando1@bot1 arg1 arg2
          		#     args: "arg1 arg2"
			args=${message_text[$id]##* }
			;;
		esac
    	)  &  # 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