rule34.lua: Fix falls kein Ergebnis
This commit is contained in:
parent
9ac23e1b1b
commit
d43232777e
@ -19,12 +19,13 @@ function rule34:get_r34_info(tag)
|
||||
local url = BASE_URL..tag..END_URL
|
||||
local res, code = https.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local r34 = json.decode(res).query.results.posts.post
|
||||
if not r34[1] then return nil end
|
||||
local data = json.decode(res).query
|
||||
if not data.results or data.results.posts.count == '0' then return end
|
||||
local r34 = data.results.posts.post
|
||||
|
||||
|
||||
local i = math.random(#r34)
|
||||
local url = r34[i].file_url
|
||||
local url = 'http:'..r34[i].file_url
|
||||
local source_url = 'http://rule34.xxx/index.php?page=post&s=view&id='..r34[i].id
|
||||
return url, source_url
|
||||
end
|
||||
@ -34,10 +35,11 @@ function rule34:get_r34_post(id)
|
||||
local res ,code = https.request(url)
|
||||
|
||||
if code ~= 200 then return nil end
|
||||
local r34 = json.decode(res).query.results.posts.post
|
||||
if not r34 then return nil end
|
||||
local data = json.decode(res).query
|
||||
if not data.results or data.results.posts.count == '0' then return end
|
||||
local r34 = data.results.posts.post
|
||||
|
||||
local img_url = r34.file_url
|
||||
local img_url = 'http:'..r34.file_url
|
||||
return img_url
|
||||
end
|
||||
|
||||
@ -46,7 +48,7 @@ function rule34:action(msg, config, matches)
|
||||
local id = matches[2]
|
||||
local img_url = rule34:get_r34_post(id)
|
||||
if not img_url then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
utilities.send_reply(msg, 'Nobody here but us chickens!')
|
||||
return
|
||||
end
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
@ -64,7 +66,7 @@ function rule34:action(msg, config, matches)
|
||||
local tag = string.gsub(tag, "+", '%%2B')
|
||||
local url, id = rule34:get_r34_info(tag)
|
||||
if not url then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
utilities.send_reply(msg, 'Nobody here but us chickens!')
|
||||
return
|
||||
end
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
|
Reference in New Issue
Block a user