New API for Simsimi

This commit is contained in:
Tiago Danin 2016-01-21 16:57:06 -03:00
parent f56e2a4149
commit bf0a4da83c
2 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,8 @@ return {
biblia_api_key = '', biblia_api_key = '',
thecatapi_key = '', thecatapi_key = '',
nasa_api_key = '', nasa_api_key = '',
simsimi_key = '',
simsimi_trial = true,
time_offset = 0, time_offset = 0,
lang = 'en', lang = 'en',
antisquig = false, antisquig = false,

View File

@ -1,5 +1,11 @@
-- Put this absolutely at the end, even after greetings.lua. -- Put this absolutely at the end, even after greetings.lua.
if not config.simsimi_key then
print('Missing config value: simsimi_key.')
print('chatter.lua will not be enabled.')
return
end
local triggers = { local triggers = {
'', '',
'^' .. bot.first_name .. ',', '^' .. bot.first_name .. ',',
@ -28,7 +34,13 @@ local action = function(msg)
input = input:gsub(bot.first_name, 'simsimi') input = input:gsub(bot.first_name, 'simsimi')
input = input:gsub('@'..bot.username, 'simsimi') input = input:gsub('@'..bot.username, 'simsimi')
local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(input) if config.simsimi_trial then
sandbox = 'sandbox.'
else
sandbox = '' -- NO Sandbox
end
local url = 'http://' ..sandbox.. 'api.simsimi.com/request.p?key=' ..config.simsimi_key.. '&lc=' ..config.lang.. '&ft=1.0&text=' .. URL.escape(input)
local jstr, res = HTTP.request(url) local jstr, res = HTTP.request(url)
if res ~= 200 then if res ~= 200 then
@ -37,7 +49,11 @@ local action = function(msg)
end end
local jdat = JSON.decode(jstr) local jdat = JSON.decode(jstr)
local message = jdat.res.msg if not jdat.response then
sendMessage(msg.chat.id, config.errors.chatter_response)
return
end
local message = jdat.response
if message:match('^I HAVE NO RESPONSE.') then if message:match('^I HAVE NO RESPONSE.') then
message = config.errors.chatter_response message = config.errors.chatter_response