Skip to content

Commit 8ab00ff

Browse files
author
Juliano Santos
committed
Novo método "ShellBot.sendPoll" para envio de enquete
1 parent f6b8acf commit 8ab00ff

1 file changed

Lines changed: 94 additions & 24 deletions

File tree

ShellBot.sh

Lines changed: 94 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4872,33 +4872,33 @@ _EOF
48724872
local can_change_info can_invite_users can_pin_messages
48734873

48744874
local param=$(getopt --name "$FUNCNAME" \
4875-
--options 'mdlowcip' \
4876-
--longoptions 'can_send_messages,
4877-
can_send_media_messages,
4878-
can_send_polls,
4879-
can_send_other_messages,
4880-
can_add_web_page_previews,
4881-
can_change_info,
4882-
can_invite_users,
4883-
can_pin_messages' \
4875+
--options 'm:d:l:o:w:c:i:p:' \
4876+
--longoptions 'can_send_messages:,
4877+
can_send_media_messages:,
4878+
can_send_polls:,
4879+
can_send_other_messages:,
4880+
can_add_web_page_previews:,
4881+
can_change_info:,
4882+
can_invite_users:,
4883+
can_pin_messages:' \
48844884
-- "$@")
48854885

48864886
eval set -- "$param"
48874887

48884888
while :
48894889
do
48904890
case $1 in
4891-
-m|--can_send_messages) can_send_messages=true;;
4892-
-d|--can_send_media_messages) can_send_media_messages=true;;
4893-
-l|--can_send_polls) can_send_polls=true;;
4894-
-o|--can_send_other_messages) can_send_other_messages=true;;
4895-
-w|--can_add_web_page_previews) can_add_web_page_previews=true;;
4896-
-c|--can_change_info) can_change_info=true;;
4897-
-i|--can_invite_users) can_invite_users=true;;
4898-
-p|--can_pin_messages) can_pin_messages=true;;
4899-
--) break;;
4891+
-m|--can_send_messages) can_send_messages=$2;;
4892+
-d|--can_send_media_messages) can_send_media_messages=$2;;
4893+
-l|--can_send_polls) can_send_polls=$2;;
4894+
-o|--can_send_other_messages) can_send_other_messages=$2;;
4895+
-w|--can_add_web_page_previews) can_add_web_page_previews=$2;;
4896+
-c|--can_change_info) can_change_info=$2;;
4897+
-i|--can_invite_users) can_invite_users=$2;;
4898+
-p|--can_pin_messages) can_pin_messages=$2;;
4899+
--) shift; break;;
49004900
esac
4901-
shift
4901+
shift 2
49024902
done
49034903

49044904
json=${can_send_messages:+\"can_send_messages\":$can_send_messages,}
@@ -4931,10 +4931,11 @@ _EOF
49314931
while :
49324932
do
49334933
case $1 in
4934-
-c|--chat_id) chat_id=$2; shift 2;;
4935-
-p|--permissions) permissions=$2; shift 2;;
4934+
-c|--chat_id) chat_id=$2;;
4935+
-p|--permissions) permissions=$2;;
49364936
--) shift; break;;
49374937
esac
4938+
shift 2
49384939
done
49394940

49404941
[[ $chat_id ]] || MessageError API "$_ERR_PARAM_REQUIRED_" "[-c, --chat_id]"
@@ -4968,11 +4969,12 @@ _EOF
49684969
while :
49694970
do
49704971
case $1 in
4971-
-c|--chat_id) chat_id=$2; shift 2;;
4972-
-u|--user_id) user_id=$2; shift 2;;
4973-
-t|--custom_title) custom_title=$2; shift 2;;
4972+
-c|--chat_id) chat_id=$2;;
4973+
-u|--user_id) user_id=$2;;
4974+
-t|--custom_title) custom_title=$2;;
49744975
--) shift; break;;
49754976
esac
4977+
shift 2
49764978
done
49774979

49784980
[[ $chat_id ]] || MessageError API "$_ERR_PARAM_REQUIRED_" "[-c, --chat_id]"
@@ -4991,6 +4993,73 @@ _EOF
49914993
return $?
49924994
}
49934995

4996+
ShellBot.sendPoll()
4997+
{
4998+
local chat_id question options is_anonymous reply_markup
4999+
local type allows_multiple_answers correct_option_id jq_obj
5000+
local is_closed disable_notification reply_to_message_id
5001+
5002+
local param=$(getopt --name "$FUNCNAME" \
5003+
--options 'c:q:o:a:k:t:m:i:l:n:r:' \
5004+
--longoptions 'chat_id:,
5005+
question:,
5006+
options:,
5007+
is_anonymous:,
5008+
reply_markup:,
5009+
type:,
5010+
allows_multiple_answers:,
5011+
correct_option_id:,
5012+
is_closed:,
5013+
disable_notification:,
5014+
reply_to_message_id:' \
5015+
-- "$@")
5016+
5017+
eval set -- "$param"
5018+
5019+
while :
5020+
do
5021+
case $1 in
5022+
-c|--chat_id) chat_id=$2;;
5023+
-q|--question) question=$2;;
5024+
-o|--options) options=$2;;
5025+
-a|--is_anonymous) is_anonymous=$2;;
5026+
-k|--reply_markup) reply_markup=$2;;
5027+
-t|--type) type=$2;;
5028+
-m|--allows_multiple_answers) allows_multiple_answers=$2;;
5029+
-i|--correct_option_id) correct_option_id=$2;;
5030+
-l|--is_closed) is_closed=$2;;
5031+
-n|--disable_notification) disable_notification=$2;;
5032+
-r|--reply_to_message_id) reply_to_message_id=$2;;
5033+
--) shift; break;;
5034+
esac
5035+
shift 2
5036+
done
5037+
5038+
[[ $chat_id ]] || MessageError API "$_ERR_PARAM_REQUIRED_" "[-c, --chat_id]"
5039+
[[ $question ]] || MessageError API "$_ERR_PARAM_REQUIRED_" "[-q, --question]"
5040+
[[ $options ]] || MessageError API "$_ERR_PARAM_REQUIRED_" "[-o, --options]"
5041+
5042+
jq_obj=$(curl $_CURL_OPT_ POST $_API_TELEGRAM_/${FUNCNAME#*.} \
5043+
${chat_id:+-d chat_id="$chat_id"} \
5044+
${question:+-d question="$question"} \
5045+
${options:+-d options="$options"} \
5046+
${is_anonymous:+-d is_anonymous="$is_anonymous"} \
5047+
${reply_markup:+-d reply_markup="$reply_markup"} \
5048+
${type:+-d type="$type"} \
5049+
${allows_multiple_answers:+-d allows_multiple_answers="$allows_multiple_answers"} \
5050+
${correct_option_id:+-d correct_option_id="$correct_option_id"} \
5051+
${is_closed:+-d is_closed="$is_closed"} \
5052+
${disable_notification:+-d disable_notification="$disable_notification"} \
5053+
${reply_to_message_id:+-d reply_to_message_id="$reply_to_message_id"})
5054+
5055+
# Retorno do método
5056+
MethodReturn $jq_obj || MessageError TG $jq_obj
5057+
5058+
# Status
5059+
return $?
5060+
5061+
}
5062+
49945063
ShellBot.setMessageRules()
49955064
{
49965065
local action command user_id username chat_id
@@ -5786,6 +5855,7 @@ _EOF
57865855
ShellBot.ChatPermissions \
57875856
ShellBot.setChatPermissions \
57885857
ShellBot.setChatAdministratorCustomTitle \
5858+
ShellBot.sendPoll \
57895859
ShellBot.setMessageRules \
57905860
ShellBot.manageRules \
57915861
ShellBot.getUpdates

0 commit comments

Comments
 (0)