Page MenuHomePhabricator (Chris)

netflix.mattata
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

netflix.mattata

--[[
Copyright 2017 Matthew Hesketh <wrxck0@gmail.com>
This code is licensed under the MIT. See LICENSE for details.
]]
local netflix = {}
local mattata = require('mattata')
local http = require('socket.http')
local url = require('socket.url')
local json = require('dkjson')
function netflix:init()
netflix.commands = mattata.commands(self.info.username)
:command('netflix')
:command('nf').table
netflix.help = '/netflix <query> - Searches Netflix for the given search query and returns the most relevant result. Alias: /nf.'
end
function netflix.send_request(input, language)
local jstr, res = http.request('http://netflixroulette.net/api/api.php?title=' .. url.escape(input))
if res ~= 200
then
return false
end
local jdat = json.decode(jstr)
if jdat.errorcode
then
return false
end
local output = {}
table.insert(
output,
'<b>' .. mattata.escape_html(jdat.show_title) .. '</b>\n'
)
table.insert(
output,
'📅 ' .. jdat.release_year .. ' | ⭐ ' .. jdat.rating .. ' | ' .. mattata.escape_html(jdat.show_cast)
)
table.insert(
output,
'\n<i>' .. mattata.escape_html(jdat.summary) .. '</i>'
)
table.insert(
output,
'\n<a href="https://www.netflix.com/title/' .. jdat.show_id .. '">' .. language['netflix']['1'] .. '</a>'
)
return table.concat(
output,
'\n'
)
end
function netflix:on_message(message, configuration, language)
local input = mattata.input(message.text)
if not input
then
return mattata.send_reply(
message,
netflix.help
)
end
local output = netflix.send_request(
input,
language
)
if not output
then
return mattata.send_reply(
message,
language['errors']['results']
)
end
return mattata.send_message(
message.chat.id,
output,
'html'
)
end
return netflix

File Metadata

Mime Type
text/html
Expires
Sat, Nov 14, 11:23 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
136571
Default Alt Text
netflix.mattata (1 KB)

Event Timeline