forked from shellscriptx/shellbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcomeBot.sh
More file actions
executable file
·60 lines (49 loc) · 1.5 KB
/
Copy pathWelcomeBot.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# script: WelcomeBot.sh
#
# Para melhor compreensão foram utilizados parâmetros longos nas funções; Podendo
# ser substituidos pelos parâmetros curtos respectivos.
# Importando API
source ShellBot.sh
# Token do bot
bot_token='<TOKEN_AQUI>'
# Inicializando o bot
ShellBot.init --token "$bot_token"
ShellBot.username
# boas vindas
msg_bem_vindo()
{
local msg
# Texto da mensagem
msg="🆔 [@${message_new_chat_member_username[$id]:-null}]\n"
msg+="🗣 Olá *${message_new_chat_member_first_name[$id]}*"'!!\n\n'
msg+="Seja bem-vindo(a) ao *${message_chat_title[$id]}*.\n\n"
msg+='`Se precisar de ajuda ou informações sobre meus comandos, é só me chamar no privado.`'"[@$(ShellBot.username)]"
# Envia a mensagem de boas vindas.
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \
--text "$(echo -e $msg)" \
--parse_mode markdown
return 0
}
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
(
# Chama a função 'msg_bem_vindo' se o valor de 'message_new_chat_member_id' não for nulo.
[[ ${message_new_chat_member_id[$id]} ]] && msg_bem_vindo
# Verifica se a mensagem enviada pelo usuário é um comando válido.
case ${message_text[$id]} in
*)
:
# <BOT COMANDOS> ...
;;
esac
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
done
done
#FIM