Merge pull request #33 from TiagoDanin/Yandex
Migrating to yandex (translate)
This commit is contained in:
commit
f61eabf946
@ -7,6 +7,7 @@ return {
|
|||||||
biblia_api_key = '',
|
biblia_api_key = '',
|
||||||
thecatapi_key = '',
|
thecatapi_key = '',
|
||||||
nasa_api_key = '',
|
nasa_api_key = '',
|
||||||
|
yandex_key = '',
|
||||||
simsimi_key = '',
|
simsimi_key = '',
|
||||||
simsimi_trial = true,
|
simsimi_trial = true,
|
||||||
time_offset = 0,
|
time_offset = 0,
|
||||||
|
@ -20,7 +20,7 @@ local action = function(msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local url = 'https://translate.google.com/translate_a/single?client=t&ie=UTF-8&oe=UTF-8&hl=en&dt=t&sl=auto&tl=' .. config.lang .. '&text=' .. URL.escape(input)
|
local url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=' .. config.yandex_key .. '&lang=' .. config.lang .. '&text=' .. URL.escape(input)
|
||||||
|
|
||||||
local str, res = HTTPS.request(url)
|
local str, res = HTTPS.request(url)
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
@ -28,7 +28,13 @@ local action = function(msg)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = latcyr(str:gmatch("%[%[%[\"(.*)\"")():gsub("\"(.*)", ""))
|
local jdat = JSON.decode(str)
|
||||||
|
if jdat.code ~= 200 then
|
||||||
|
sendReply(msg, config.errors.connection)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local output = jdat.text[1]
|
||||||
|
|
||||||
sendReply(msg.reply_to_message or msg, output)
|
sendReply(msg.reply_to_message or msg, output)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user