acc7046d64
Added optional target for kick/ban logs. Added flag 7 to use default log per group. This way, a realm can have a public kick/ban log but governors are able to opt out. Added flag 8, antilink. Kicks for Telegram join links which do not refer to groups within the realm. Added flag 9, modrights, to give moderators access to changing the group photo, title, link, and motd (config option is deprecated. RIP). /unban will reset the target's autokick counter. Added configuration for default flag settings. Revision to bindings.lua. BASE_URL has been moved to bindings. There is no real reason for it to remain in instance. Token is passed to bindings.init at load. All plugins have been updated accordingly.
46 lines
1.4 KiB
Lua
46 lines
1.4 KiB
Lua
local translate = {}
|
|
|
|
local HTTPS = require('ssl.https')
|
|
local URL = require('socket.url')
|
|
local JSON = require('dkjson')
|
|
local utilities = require('otouto.utilities')
|
|
|
|
translate.command = 'translate [text]'
|
|
|
|
function translate:init(config)
|
|
assert(config.yandex_key,
|
|
'translate.lua requires a Yandex translate API key from http://tech.yandex.com/keys/get.'
|
|
)
|
|
|
|
translate.triggers = utilities.triggers(self.info.username, config.cmd_pat)
|
|
:t('translate', true):t('tl', true).table
|
|
translate.doc = config.cmd_pat .. [[translate [text]
|
|
Translates input or the replied-to message into the bot's language.]]
|
|
translate.base_url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=' .. config.yandex_key .. '&lang=' .. config.lang .. '&text=%s'
|
|
end
|
|
|
|
function translate:action(msg, config)
|
|
local input = utilities.input_from_msg(msg)
|
|
if not input then
|
|
utilities.send_reply(msg, translate.doc, true)
|
|
return
|
|
end
|
|
|
|
local url = translate.base_url:format(URL.escape(input))
|
|
local jstr, code = HTTPS.request(url)
|
|
if code ~= 200 then
|
|
utilities.send_reply(msg, config.errors.connection)
|
|
return
|
|
end
|
|
|
|
local data = JSON.decode(jstr)
|
|
if data.code ~= 200 then
|
|
utilities.send_reply(msg, config.errors.connection)
|
|
return
|
|
end
|
|
|
|
utilities.send_reply(msg.reply_to_message or msg, utilities.style.enquote('Translation', data.text[1]), true)
|
|
end
|
|
|
|
return translate
|