From bf0a4da83cb0d73609199d547543e45a83cc775e Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Thu, 21 Jan 2016 16:57:06 -0300 Subject: [PATCH] New API for Simsimi --- config.lua | 2 ++ plugins/chatter.lua | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.lua b/config.lua index 13f0004..14d116c 100755 --- a/config.lua +++ b/config.lua @@ -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, diff --git a/plugins/chatter.lua b/plugins/chatter.lua index 08460fd..6f532d9 100755 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -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 .. ',', @@ -27,8 +33,14 @@ local action = function(msg) local input = msg.text_lower input = input:gsub(bot.first_name, 'simsimi') input = input:gsub('@'..bot.username, 'simsimi') + + if config.simsimi_trial then + sandbox = 'sandbox.' + else + sandbox = '' -- NO Sandbox + end - local url = 'http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=' .. URL.escape(input) + 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