HOME FORUMS MEMBERS RECENT POSTS LOG IN  
× Авторизация
Имя пользователя:
Пароль:
Нет аккаунта? Регистрация
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ ЧАТ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby
   
 
 
Опции темы Поиск в этой теме Опции просмотра

  #11  
Старый 05.11.2024, 21:52
varkon
Участник форума
Регистрация: 28.11.2017
Сообщений: 180
С нами: 4450953

Репутация: 73
По умолчанию

Всем привет.

Как правильно юзать эту функи для обратной связи в телеге? (Не помню откуда вырезал, если честно)

Юзаю сейчас в onLoad(), но после reconnect(), игра никак не реагирует на команды отправленные с телеги

Lua:





Код:
function
onLoad
(
)
getLastUpdate
(
)
telegram_task
=
newTask
(
get_telegram_updates
,
1000
)
end


Lua:





Код:
function
getLastUpdate
(
)
async_http_request
(
'https://api.telegram.org/bot'
..
token_telegram
..
'/getUpdates?chat_id='
..
chatid_telegram
..
'&offset=-1'
,
''
,
function
(
result
)
if
result
then
local
proc_table
=
json
.
decode
(
result
)
if
proc_table
.
ok
then
if
#
proc_table
.
result
>
0
then
local
res_table
=
proc_table
.
result
[
1
]
if
res_table
then
updateid
=
res_table
.
update_id
end
else
updateid
=
1
end
end
end
end
)
end


Lua:





Код:
function
get_telegram_updates
(
)
-- функция получения сообщений от юзера
while
not
updateid
do
wait
(
0
)
end
-- ждем пока не узнаем последний ID
local
runner
=
requestRunner
(
)
local
reject
=
function
(
)
end
local
args
=
''
while
true
do
url
=
'https://api.telegram.org/bot'
..
token_telegram
..
'/getUpdates?chat_id='
..
chatid_telegram
..
'&offset=-1'
-- создаем ссылку
threadHandle
(
runner
,
url
,
args
,
processing_telegram_messages
,
reject
)
wait
(
0
)
end
end


Цитата:
Сообщение от Спойлер  


Lua:





Код:
function
processing_telegram_messages
(
result
)
-- функция проверОчки того что отправил чел
if
result
then
-- тута мы проверяем все ли верно
local
proc_table
=
json
.
decode
(
result
)
if
proc_table
.
ok
then
if
#
proc_table
.
result
>
0
then
local
res_table
=
proc_table
.
result
[
1
]
if
res_table
then
if
res_table
.
update_id
~=
updateid
then
updateid
=
res_table
.
update_id
local
message_from_user
=
res_table
.
message
.
text
if
message_from_user
then
-- и тут если чел отправил текст мы сверяем
local
textTg
=
u8
:
decode
(
message_from_user
)
..
" "
--добавляем в конец пробел дабы не произошли тех. шоколадки с командами(типо чтоб !q не считалось как !qq)
local
textTg2
=
u8
:
decode
(
message_from_user
)
if
textTg2
:
find
(
"%/send (%d+) (.+)"
)
then
local
local_bot_id
,
sendArg
=
textTg2
:
match
(
"^/send (%d+) (.+)"
)
if
tonumber
(
local_bot_id
)
==
getBotId
(
)
then
sendInput
(
sendArg
)
sendTelegramNotification
(
'Вы написали: "'
..
sendArg
..
'"'
)
end
end
if
textTg2
:
find
(
"^/stats (%d+)"
)
then
local
local_botid
=
textTg2
:
match
(
"/stats (%d+)"
)
if
tonumber
(
local_botid
)
==
getBotId
(
)
then
sendInput
(
"/stats"
)
show_stats_info
=
true
end
end
if
textTg2
:
find
(
"^/diag (%d+) (%d) (%d+) (.*)"
)
then
local
argument_id
,
argument_button
,
argument_listbox
,
argument_input
=
textTg2
:
match
(
"^/diag (%d+) (%d) (%d+) (.*)"
)
sendDialogResponse
(
tonumber
(
argument_id
)
,
tonumber
(
argument_button
)
,
tonumber
(
argument_listbox
)
,
tostring
(
argument_input
)
)
end
if
textTg2
:
match
(
'^/rsamp (%d+) (.+)'
)
then
local
id_rsamp_arg
,
rsamp_arg
=
textTg2
:
match
(
'^/rsamp (%d+) (.+)'
)
if
tonumber
(
id_rsamp_arg
)
==
getBotId
(
)
then
runCommand
(
rsamp_arg
)
end
end
if
textTg2
:
match
(
'^/log (%d+)'
)
then
local
ar_for_log
=
textTg2
:
match
(
'^/log (%d+)'
)
if
tonumber
(
ar_for_log
)
==
getBotId
(
)
then
log_chat_serv_info
=
not
log_chat_serv_info
sendTelegramNotification
(
log_chat_serv_info
and
"Логирование выключено"
or
"Логирование включено"
)
end
end
if
textTg2
:
match
(
'^/chatl (%d+)'
)
then
local
arg_for_id_bot
=
textTg2
:
match
(
'^/chatl (%d+)'
)
if
tonumber
(
arg_for_id_bot
)
==
getBotId
(
)
then
log_chat_all
=
not
log_chat_all
sendTelegramNotification
(
log_chat_all
and
"Логирование чата выключено"
or
"Логирование чата включено"
)
end
end
if
textTg2
:
match
(
'^/binfo'
)
then
sendTelegramNotification
(
getBotNick
(
)
..
"["
..
getBotId
(
)
..
"]"
)
if
next
(
staff_on_roulette
)
then
for
k
,
v
in
ipairs
(
staff_on_roulette
)
do
print
(
"Количество рулеток "
..
k
..
" Название рулеток "
..
v
)
end
end
end
if
textTg2
:
match
(
"^/case"
)
then
if
not
next
(
status
.
item_list
)
then
sendInput
(
"/stats"
)
save_case_item
=
true
end
for
k
,
v
in
pairs
(
status
.
item_list
)
do
sendTelegramNotification
(
"[№"
..
v
.
index
..
"] "
..
v
.
name
..
" "
..
" ["
..
v
.
count
..
"шт]"
)
end
end
end
end
end
end
end
end
end
[
/
spoiler
]


 
Ответить с цитированием
 





Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.