New API for Simsimi
This commit is contained in:
parent
f56e2a4149
commit
bf0a4da83c
@ -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,
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user