@maximsum
Я это я

Что не так в коде?

Я написал код для бота самп, он через API ВК говорит информацию на сервере и выполняет команды через RakSamp.
И когда я его запускаю он пишет что запустился - https://imgur.com/vJeESTJ но при этом не видит мои сообщения, с чем это может быть связано? Бот у меня администратор в группе и по идеи должен видеть сообщения. Где скорее всего возникает ошибка -
function vk_request_user(id, msg)
	msg = AnsiToUtf8(msg)
	msg = url_encode(msg)
	async_http_request('https://api.vk.com/method/messages.send', 'user_id=' .. id .. '&random_id=' .. math.random(-2147483648, 2147483647) .. '&message=' .. msg .. '&access_token=' .. access_token .. '&v=5.154',
	function (result)
		local t = json.decode(result)
		if not t then print(result) return end
		if t.error then print('Ошибка! Код: ' .. t.error.error_code .. ' Причина: ' .. t.error.error_msg) return end
		vkerrsend = nil
	end)
end

function partOfVkSystem(msg)
	local rnd = math.random(-2147000000, 2147000000)
	async_http_request('https://api.vk.com/method/messages.send', 'chat_id='..tonumber(chat_id)..'&random_id=' .. rnd .. '&message=' .. msg .. '&access_token=' .. access_token .. '&v=5.154',
	function (result)
		local t = json.decode(result)
		if not t then print(result) return end
		if t.error then print('Ошибка! Код: ' .. t.error.error_code .. ' Причина: ' .. t.error.error_msg) return end
		vkerrsend = nil
	end)
	print('https://api.vk.com/method/messages.send', 'chat_id='..tonumber(chat_id)..'&random_id=' .. rnd .. '&message=' .. msg .. '&access_token=' .. access_token .. '&v=5.154')
end

function longpollResolve(result)
	if result then
		if result:sub(1,1) ~= '{' then
			vkerr = 'Ошибка!\nПричина: Нет соединения с VK!'
			return
		end
		local t = json.decode(result)
		if t.failed then
			if t.failed == 1 then
				ts = t.ts
			else
				key = nil
				longpollGetKey()
			end
			return
		end
		if t.ts then
			ts = t.ts
		end
		if t.updates then
			for k, v in ipairs(t.updates) do
				if v.type == 'message_new' and v.object.message then
					if v.object.message.payload then
						local pl = json.decode(v.object.message.payload)
						if pl.button then
						local chat_id = v.object.message.chat_id
						if tonumber(chat_id) == tonumber(chat_id) then
								if pl.button == 'report' then
									send_info_report()
								elseif pl.button == 'online' then
									send_info_online()
								elseif pl.button == 'admin_online' then
									send_info_admins()
								elseif pl.button == 'start_captcha' then
									startCaptcha()
									VkMessage('🔢 Капча на скин была запущена победитель????')
								elseif pl.button == 'start_question' then
									startQuestion()
									VkMessage('❓ Рандомный вопрос на рандомный новый LUXE автомобиль запущен.')
								elseif pl.button == 'help' then
									send_info_commands()
								elseif pl.button == 'check_server_online' then
									keyboard_vk('📈 Выберите тип статистики онлайна:', 'onl')
								elseif pl.button == 'onlday_stats' then
									send_online_stats('day')
								elseif pl.button == 'onlweek_stats' then
									send_online_stats('week')
								elseif pl.button == 'onlall_stats' then
									send_online_stats('all')
								elseif pl.button == 'repday_stats' then
									send_report_stats('day')
								elseif pl.button == 'repweek_stats' then
									send_report_stats('week')
								elseif pl.button == 'repall_stats' then
									send_report_stats('all')
								elseif pl.button == 'admday_stats' then
									send_admins_stats('day')
								elseif pl.button == 'admweek_stats' then
									send_admins_stats('week')
								elseif pl.button == 'admall_stats' then
									send_admins_stats('all')
								elseif pl.button == 'return_business_ban' then
									send_bans_businessis()
								elseif pl.button == 'return_house_ban' then
									send_bans_housis()
								elseif pl.button == 'no_stop' and start_button then
									start_button = false
									auto_slet = true
									set_position = true
								end
							end
						end
						return
					end
					if v.object.message.text then
						local text = v.object.message.text 
						local chat_id = v.object.message.chat_id 
						local from_id = tonumber(v.object.message.from_id)
						if tonumber(chat_id) == tonumber(chat_id) then
							text = Utf8ToAnsi(text)
							if text:find('^/botoff') then
								newTask(function()
									VkMessage('🚫 Бот отключен.')
									wait(500)
									exit()
								end)
							elseif text:find('^/ifind (.*)') then
								name_find_item = text:match('^/ifind (.*)')
								find_item = true
								sendInput('/itemsinfo')
							elseif text:find('^/checkbusiness (%d+) (%d+)') then
								min_biz, max_biz = text:match('^/checkbusiness (%d+) (%d+)')
								local f = io.open(bot_name..'/Logs/checkbusinessis_ban.ini', 'w')
								f:write('')
								f:close()
								if not check_biz then
									if tonumber(min_biz) < tonumber(max_biz) then
										if tonumber(min_biz) >= 0 and tonumber(max_biz) <= 360 then
											if (tonumber(max_biz) - tonumber(min_biz)) <= 40 then
												VkMessage('&#8987; Ожидайте, начинаю собирать информацию. Проверка будет длиться ~ '..tonumber(("%.1f"):format((tonumber(max_biz) - tonumber(min_biz))*0.75))..'сек. [1 бизнес - 750 мс].')
												check_biz = true
												sendInput('/checkbiz '..min_biz)
											else
												VkMessage('&#128683; Нельзя проверять более 40 бизнесов за один раз (из-за органичения длины сообщения в VK)!')
											end
										else
											VkMessage('&#128683; Параметры промежутка бизнесов указаны неверно!')
										end
									else
										VkMessage('&#128683; ID начального бизнеса не может быть меньше IDa конечного бизнеса!')
									end
								end
							elseif text:find('^/checkhouse (%d+) (%d+)') then
								min_house, max_house = text:match('^/checkhouse (%d+) (%d+)')
								local f = io.open(bot_name..'/Logs/checkhousis_ban.ini', 'w')
								f:write('')
								f:close()
								if not check_house then
									if tonumber(min_house) < tonumber(max_house) then
										if tonumber(min_house) >= 0 and tonumber(max_house) <= 1300 then
											if (tonumber(max_house) - tonumber(min_house)) <= 40 then
												VkMessage('&#8987; Ожидайте, начинаю собирать информацию.\n-- Проверка будет длиться ~ '..tonumber(("%.1f"):format((tonumber(max_house) - tonumber(min_house))*0.75))..'сек. [1 дом - 750 мс].')
												check_house = true
												sendInput('/checkhouse '..min_house)
											else
												VkMessage('&#128683; Нельзя проверять более 40 домов за один раз (из-за органичения длины сообщения в VK)!')
											end
										else
											VkMessage('&#128683; Параметры промежутка домов указаны неверно!')
										end
									else
										VkMessage('&#128683; ID начального дома не может быть меньше IDa конечного дома!')
									end
								end
  • Вопрос задан
  • 229 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы