added translation plugin
This commit is contained in:
parent
02d30f8451
commit
547bdec7af
@ -16,6 +16,7 @@ return {
|
||||
results = 'No results found.',
|
||||
argument = 'Invalid argument.',
|
||||
syntax = 'Invalid syntax.'
|
||||
}
|
||||
},
|
||||
translate = 'en'
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ local PLUGIN = {}
|
||||
PLUGIN.doc = [[
|
||||
/images <query>
|
||||
This command performs a Google Images search for the given query. One random top result is returned. Safe search is enabled by default; use '/insfw' to get potentially NSFW results.
|
||||
Want images sent directly to chat? Try @ImageBot.
|
||||
]]
|
||||
|
||||
PLUGIN.triggers = {
|
||||
|
@ -3,6 +3,7 @@ local PLUGIN = {}
|
||||
PLUGIN.doc = [[
|
||||
/giphy [query]
|
||||
Returns a random or search-resulted GIF from giphy.com. Results are limited to PG-13 by default; use '/gifnsfw' to get potentially NSFW results.
|
||||
Want GIFs sent directly to chat? Try @ImageBot.
|
||||
]]
|
||||
|
||||
PLUGIN.triggers = {
|
||||
|
@ -101,7 +101,7 @@ PLUGIN.puns = {
|
||||
"Why are there no knock-knock jokes about America? Because freedom rings.",
|
||||
"When the cannibal showed up late to dinner, they gave him the cold shoulder.",
|
||||
"I should have been sad when my flashlight died, but I was delighted.",
|
||||
"Why don't tennis players ever get marries? Love means nothing to them.",
|
||||
"Why don't tennis players ever get married? Love means nothing to them.",
|
||||
"Pterodactyls can't be heard going to the bathroom because the P is silent.",
|
||||
"Mermaids make calls on their shell phones.",
|
||||
"What do you call an aardvark with three feet? A yaardvark.",
|
||||
@ -125,7 +125,7 @@ PLUGIN.puns = {
|
||||
"Visitors in Cuba are always Havana good time.",
|
||||
"Why does electricity shock people? It doesn't know how to conduct itself.",
|
||||
"Lancelot had a scary dream about his horse. It was a knight mare.",
|
||||
"A tribe of cannibals caught a missionary and ate him. Afterward, they all had violent food poisoning. This just goes to show that you can't keep a good man down.",
|
||||
"A tribe of cannibals captured a missionary and ate him. Afterward, they all had violent food poisoning. This just goes to show that you can't keep a good man down.",
|
||||
"Heaven for gamblers is a paradise.",
|
||||
"Old wheels aren't thrown away, they're just retired.",
|
||||
"Horses are very stable animals.",
|
||||
|
40
plugins/translate.lua
Normal file
40
plugins/translate.lua
Normal file
@ -0,0 +1,40 @@
|
||||
-- Glanced at https://github.com/yagop/telegram-bot/blob/master/plugins/translate.lua
|
||||
|
||||
local PLUGIN = {}
|
||||
|
||||
PLUGIN.triggers = {
|
||||
'^/translate'
|
||||
}
|
||||
|
||||
PLUGIN.doc = [[
|
||||
/translate [target lang]
|
||||
Reply to a message to translate it to the default language.
|
||||
]]
|
||||
|
||||
PLUGIN.action = function(msg)
|
||||
|
||||
if not msg.reply_to_message then
|
||||
return send_msg(msg, PLUGIN.doc)
|
||||
end
|
||||
|
||||
local tl = config.locale.translate or 'en'
|
||||
local input = get_input(msg.text)
|
||||
if input then
|
||||
tl = input
|
||||
end
|
||||
|
||||
local url = 'http://translate.google.com/translate_a/single?client=t&ie=UTF-8&oe=UTF-8&hl=en&dt=t&tl=' .. tl .. '&sl=auto&text=' .. URL.escape(msg.reply_to_message.text)
|
||||
|
||||
local str, res = HTTP.request(url)
|
||||
|
||||
if res ~= 200 then
|
||||
return send_msg(msg, config.locale.errors.connection)
|
||||
end
|
||||
|
||||
local output = str:gmatch("%[%[%[\"(.*)\"")():gsub("\"(.*)", "")
|
||||
|
||||
send_msg(msg.reply_to_message, output)
|
||||
|
||||
end
|
||||
|
||||
return PLUGIN
|
Reference in New Issue
Block a user