Merge pull request #30 from TiagoDanin/Chatter

New API for Simsimi
This commit is contained in:
Drew 2016-02-13 06:42:56 -05:00
commit a0e1eccd46
2 changed files with 20 additions and 2 deletions

View File

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

View File

@ -1,5 +1,11 @@
-- 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 = {
'',
'^' .. bot.first_name .. ',',
@ -28,7 +34,13 @@ local action = function(msg)
input = input:gsub(bot.first_name, '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)
if res ~= 200 then
@ -37,7 +49,11 @@ local action = function(msg)
end
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
message = config.errors.chatter_response