Fixed reddit.lua bug.

This commit is contained in:
topkecleon 2016-02-14 03:46:27 -05:00
parent 9d43f1ed8c
commit bcb1f43617

View File

@ -16,6 +16,12 @@ local action = function(msg)
msg.text_lower = msg.text_lower:gsub('/r/', '/r r/') msg.text_lower = msg.text_lower:gsub('/r/', '/r r/')
local input = msg.text_lower:input() local input = msg.text_lower:input()
if msg.text_lower:match('^/r/') then
msg.text_lower = msg.text_lower:gsub('/r/', '/r r/')
input = get_word(msg.text_lower, 1)
else
input = msg.text_lower:input()
end
local url local url
local limit = 4 local limit = 4
@ -26,10 +32,10 @@ local action = function(msg)
local source local source
if input then if input then
if input:match('^r/.') then if input:match('^r/.') then
url = 'http://www.reddit.com/' .. input .. '/.json?limit=' .. limit url = 'http://www.reddit.com/' .. URL.escape(input) .. '/.json?limit=' .. limit
source = '*/r/' .. input:match('^r/(.+)') .. '*\n' source = '*/r/' .. input:match('^r/(.+)') .. '*\n'
else else
url = 'http://www.reddit.com/search.json?q=' .. input .. '&limit=' .. limit url = 'http://www.reddit.com/search.json?q=' .. URL.escape(input) .. '&limit=' .. limit
source = '*reddit results for* _' .. input .. '_ *:*\n' source = '*reddit results for* _' .. input .. '_ *:*\n'
end end
else else
@ -51,7 +57,7 @@ local action = function(msg)
local output = '' local output = ''
for i,v in ipairs(jdat.data.children) do for i,v in ipairs(jdat.data.children) do
local title = v.data.title:gsub('%[.+%]', ''):gsub('&', '&') local title = v.data.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&')
if title:len() > 48 then if title:len() > 48 then
title = title:sub(1,45) .. '...' title = title:sub(1,45) .. '...'
end end