Übernehme Änderungen von Brawl345/Brawlbot-v2

Verwende in einigen Plugins HTML, statt Markdown
This commit is contained in:
Akamaru 2016-08-04 13:44:56 +02:00
parent 77eaa3976c
commit 440926765f
12 changed files with 108 additions and 110 deletions

View File

@ -82,11 +82,9 @@ function afk:pre_process(msg, self)
redis:hset(hash, 'afk', false) redis:hset(hash, 'afk', false)
if afk_text then if afk_text then
redis:hset(hash, 'afk_text', false) redis:hset(hash, 'afk_text', false)
local afk_text = afk_text:gsub("%*","") utilities.send_reply(self, msg, user_name..' ist wieder da! (war: <b>'..afk_text..'</b> für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}')
local afk_text = afk_text:gsub("_","")
utilities.send_reply(self, msg, user_name..' ist wieder da! (war: *'..afk_text..'* für '..duration..')', true, '{"hide_keyboard":true,"selective":true}')
else else
utilities.send_reply(self, msg, user_name..' ist wieder da! (war '..duration..' weg)', false, '{"hide_keyboard":true,"selective":true}') utilities.send_reply(self, msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}')
end end
end end

View File

@ -68,8 +68,8 @@ function app_store:send_appstore_data(data)
end end
local header = '*'..name..'* v'..version..' von *'..author..'* ('..price..'):' local header = '<b>'..name..'</b> v'..version..' von <b>'..author..'</b> ('..price..'):'
local body = '\n'..description..'\n_Benötigt mind. iOS '..min_ios_ver..'_\nGröße: '..size..' MB\nErstveröffentlicht am '..release..game_center..category local body = '\n'..description..'\n<i>Benötigt mind. iOS '..min_ios_ver..'</i>\nGröße: '..size..' MB\nErstveröffentlicht am '..release..game_center..category
local footer = '\n'..avg_rating..ratings local footer = '\n'..avg_rating..ratings
local text = header..body..footer local text = header..body..footer
@ -96,11 +96,11 @@ function app_store:action(msg, config, matches)
local data = app_store:get_appstore_data() local data = app_store:get_appstore_data()
if data == nil then print('Das Appstore-Plugin unterstützt nur Apps!') end if data == nil then print('Das Appstore-Plugin unterstützt nur Apps!') end
if data == 'HTTP-FEHLER' or data == 'NOTFOUND' then if data == 'HTTP-FEHLER' or data == 'NOTFOUND' then
utilities.send_reply(self, msg, '*App nicht gefunden!*', true) utilities.send_reply(self, msg, '<b>App nicht gefunden!</b>', 'HTML')
return return
else else
local output, image_url = app_store:send_appstore_data(data) local output, image_url = app_store:send_appstore_data(data)
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
if image_url then if image_url then
utilities.send_typing(self, msg.chat.id, 'upload_photo') utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(image_url) local file = download_to_file(image_url)

View File

@ -21,7 +21,7 @@ function echo:inline_callback(inline_query, config, matches)
results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/custom.jpg","title":"Eigenes Markdown","description":"'..text..'","input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}},' results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/custom.jpg","title":"Eigenes Markdown","description":"'..text..'","input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}},'
end end
local results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fett.jpg","title":"Fett","description":"*'..text..'*","input_message_content":{"message_text":"*'..text..'*","parse_mode":"Markdown"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/kursiv.jpg","title":"Kursiv","description":"_'..text..'_","input_message_content":{"message_text":"_'..text..'_","parse_mode":"Markdown"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fixedsys.jpg","title":"Feste Breite","description":"`'..text..'`","input_message_content":{"message_text":"`'..text..'`","parse_mode":"Markdown"}}]' local results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fett.jpg","title":"Fett","description":"*'..text..'*","input_message_content":{"message_text":"<b>'..text..'</b>","parse_mode":"HTML"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/kursiv.jpg","title":"Kursiv","description":"_'..text..'_","input_message_content":{"message_text":"<i>'..text..'</i>","parse_mode":"HTML"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fixedsys.jpg","title":"Feste Breite","description":"`'..text..'`","input_message_content":{"message_text":"<code>'..text..'</code>","parse_mode":"HTML"}}]'
utilities.answer_inline_query(self, inline_query, results, 0) utilities.answer_inline_query(self, inline_query, results, 0)
end end

View File

@ -45,7 +45,7 @@ function facebook:fb_post (id, story_id)
local message = data.message local message = data.message
local name = data.name local name = data.name
if data.link then if data.link then
link = '\n'..data.name..':\n'..utilities.md_escape(data.link) link = '\n<a href="'..data.link..'">'..data.name..'</a>'
else else
link = '' link = ''
end end
@ -56,7 +56,7 @@ function facebook:fb_post (id, story_id)
story = '' story = ''
end end
local text = '*'..from..'*'..story..':\n'..message..'\n'..link local text = '<b>'..from..'</b>'..story..':\n'..message..'\n'..link
return text return text
end end
@ -66,9 +66,9 @@ function facebook:send_facebook_photo(photo_id, receiver)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res) local data = json.decode(res)
local from = '*'..data.from.name..'*' local from = '<b>'..data.from.name..'</b>'
if data.name then if data.name then
text = from..' hat ein Bild gepostet:\n'..utilities.md_escape(data.name) text = from..' hat ein Bild gepostet:\n'..data.name
else else
text = from..' hat ein Bild gepostet:' text = from..' hat ein Bild gepostet:'
end end
@ -82,7 +82,7 @@ function facebook:send_facebook_video(video_id)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res) local data = json.decode(res)
local from = '*'..data.from.name..'*' local from = '<b>'..data.from.name..'</b>'
local description = data.description or '' local description = data.description or ''
local source = data.source local source = data.source
return from..' hat ein Video gepostet:\n'..description, source, data.title return from..' hat ein Video gepostet:\n'..description, source, data.title
@ -123,7 +123,7 @@ function facebook:facebook_info(name)
birth = '' birth = ''
end end
local text = '*'..name..'* ('..category..')_'..about..'_'..general_info..birth local text = '<b>'..name..'</b> ('..category..')<i>'..about..'</i>'..general_info..birth
return text return text
end end
@ -135,7 +135,7 @@ function facebook:action(msg, config, matches)
else else
id = matches[4] id = matches[4]
end end
utilities.send_reply(self, msg, facebook:fb_post(id, story_id), true) utilities.send_reply(self, msg, facebook:fb_post(id, story_id), 'HTML')
return return
elseif matches[1] == 'photo' or matches[2] == 'photos' then elseif matches[1] == 'photo' or matches[2] == 'photos' then
if not matches[4] then if not matches[4] then
@ -147,7 +147,7 @@ function facebook:action(msg, config, matches)
if not image_url then return end if not image_url then return end
utilities.send_typing(self, msg.chat.id, 'upload_photo') utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(image_url, 'photo.jpg') local file = download_to_file(image_url, 'photo.jpg')
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, 'HTML')
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
return return
elseif matches[1] == 'video' or matches[2] == 'videos' then elseif matches[1] == 'video' or matches[2] == 'videos' then
@ -163,10 +163,10 @@ function facebook:action(msg, config, matches)
title = 'VIDEO: '..title title = 'VIDEO: '..title
end end
if not video_url then return end if not video_url then return end
utilities.send_reply(self, msg, output, true, '{"inline_keyboard":[[{"text":"'..utilities.md_escape(title)..'","url":"'..video_url..'"}]]}') utilities.send_reply(self, msg, output, 'HTML', '{"inline_keyboard":[[{"text":"'..utilities.md_escape(title)..'","url":"'..video_url..'"}]]}')
return return
else else
utilities.send_reply(self, msg, facebook:facebook_info(matches[1]), true) utilities.send_reply(self, msg, facebook:facebook_info(matches[1]), 'HTML')
return return
end end
end end

View File

@ -121,16 +121,6 @@ function get_new_entries(last, nentries)
return entries return entries
end end
function print_subs(id, chat_name)
local uhash = get_base_redis(id)
local subs = redis:smembers(uhash)
local text = '"'..chat_name..'" hat abonniert:\n---------\n'
for k,v in pairs(subs) do
text = text .. k .. ") " .. v .. '\n'
end
return text
end
function rss:subscribe(id, url) function rss:subscribe(id, url)
local baseurl, protocol = prot_url(url) local baseurl, protocol = prot_url(url)
@ -140,7 +130,7 @@ function rss:subscribe(id, url)
local uhash = get_base_redis(id) local uhash = get_base_redis(id)
if redis:sismember(uhash, baseurl) then if redis:sismember(uhash, baseurl) then
return "Du hast `"..url.."` bereits abonniert." return "Du hast <code>"..url.."</code> bereits abonniert."
end end
local parsed, err = get_rss(url, protocol) local parsed, err = get_rss(url, protocol)
@ -160,7 +150,7 @@ function rss:subscribe(id, url)
redis:sadd(lhash, id) redis:sadd(lhash, id)
redis:sadd(uhash, baseurl) redis:sadd(uhash, baseurl)
return "_"..name.."_ abonniert!" return "<i>"..name.."</i> abonniert!"
end end
function rss:unsubscribe(id, n) function rss:unsubscribe(id, n)
@ -188,18 +178,18 @@ function rss:unsubscribe(id, n)
redis:del(lasthash) redis:del(lasthash)
end end
return "Du hast `"..sub.."` deabonniert." return "Du hast <code>"..sub.."</code> deabonniert."
end end
function rss:print_subs(id, chat_name) function rss:print_subs(id, chat_name)
local uhash = get_base_redis(id) local uhash = get_base_redis(id)
local subs = redis:smembers(uhash) local subs = redis:smembers(uhash)
if not subs[1] then if not subs[1] then
return 'Keine Feeds abonniert!' return '<b>Keine Feeds abonniert!</b>'
end end
local keyboard = '{"keyboard":[[' local keyboard = '{"keyboard":[['
local keyboard_buttons = '' local keyboard_buttons = ''
local text = '*'..chat_name..'* hat abonniert:\n---------\n' local text = '<b>'..chat_name..'</b> hat abonniert:\n---------\n'
for k,v in pairs(subs) do for k,v in pairs(subs) do
text = text .. k .. ") " .. v .. '\n' text = text .. k .. ") " .. v .. '\n'
if k == #subs then if k == #subs then
@ -231,7 +221,7 @@ function rss:action(msg, config, matches)
return return
end end
local output = rss:subscribe(id, matches[2]) local output = rss:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
return return
elseif matches[1] == 'del' and matches[2] and matches[3] then elseif matches[1] == 'del' and matches[2] and matches[3] then
if msg.from.id ~= config.admin then if msg.from.id ~= config.admin then
@ -245,7 +235,7 @@ function rss:action(msg, config, matches)
return return
end end
local output = rss:unsubscribe(id, matches[2]) local output = rss:unsubscribe(id, matches[2])
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
return return
elseif matches[1] == 'rss' and matches[2] then elseif matches[1] == 'rss' and matches[2] then
local id = '@'..matches[2] local id = '@'..matches[2]
@ -256,7 +246,7 @@ function rss:action(msg, config, matches)
end end
local chat_name = result.result.title local chat_name = result.result.title
local output = rss:print_subs(id, chat_name) local output = rss:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
return return
end end
@ -272,7 +262,7 @@ function rss:action(msg, config, matches)
return return
end end
local output = rss:subscribe(id, matches[2]) local output = rss:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
return return
elseif matches[1] == 'del' and matches[2] then elseif matches[1] == 'del' and matches[2] then
if msg.from.id ~= config.admin then if msg.from.id ~= config.admin then
@ -280,11 +270,11 @@ function rss:action(msg, config, matches)
return return
end end
local output = rss:unsubscribe(id, matches[2]) local output = rss:unsubscribe(id, matches[2])
utilities.send_reply(self, msg, output, true, '{"hide_keyboard":true}') utilities.send_reply(self, msg, output, 'HTML', '{"hide_keyboard":true}')
return return
elseif matches[1] == 'del' and not matches[2] then elseif matches[1] == 'del' and not matches[2] then
local list_subs, keyboard = rss:print_subs(id, chat_name) local list_subs, keyboard = rss:print_subs(id, chat_name)
utilities.send_reply(self, msg, list_subs, true, keyboard) utilities.send_reply(self, msg, list_subs, 'HTML', keyboard)
return return
elseif matches[1] == 'sync' then elseif matches[1] == 'sync' then
if msg.from.id ~= config.admin then if msg.from.id ~= config.admin then
@ -296,7 +286,7 @@ function rss:action(msg, config, matches)
end end
local output = rss:print_subs(id, chat_name) local output = rss:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
return return
end end
@ -342,7 +332,7 @@ function rss:cron(self_plz)
content = '' content = ''
end end
content = cleanRSS(content) content = cleanRSS(content)
text = text..'\n*[*#RSS*] '..title..'*\n'..utilities.trim(utilities.md_escape(content))..' [Weiterlesen]('..link..')\n' text = text..'\n#RSS: <b>'..title..'</b>\n'..utilities.trim(content)..' <a href="'..link..'">Weiterlesen</a>\n'
end end
if text ~= '' then if text ~= '' then
local newlast = newentr[1].id local newlast = newentr[1].id
@ -350,7 +340,7 @@ function rss:cron(self_plz)
for k2, receiver in pairs(redis:smembers(v)) do for k2, receiver in pairs(redis:smembers(v)) do
local receiver = string.gsub(receiver, 'chat%#id', '') local receiver = string.gsub(receiver, 'chat%#id', '')
local receiver = string.gsub(receiver, 'user%#id', '') local receiver = string.gsub(receiver, 'user%#id', '')
utilities.send_message(self, receiver, text, true, nil, true) utilities.send_message(self, receiver, text, true, nil, 'HTML')
end end
end end
end end

View File

@ -21,8 +21,8 @@ function entergroup:chat_new_user(msg, self)
if msg.new_chat_member.id == self.info.id then -- don't say hello to ourselves if msg.new_chat_member.id == self.info.id then -- don't say hello to ourselves
return return
end end
local text = 'Hallo '..user_name..', willkommen bei *'..chat_title..'*!'..added_by local text = 'Hallo '..user_name..', willkommen bei <b>'..chat_title..'</b>!'..added_by
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, 'HTML')
end end
function entergroup:chat_del_user(msg, self) function entergroup:chat_del_user(msg, self)
@ -35,8 +35,8 @@ function entergroup:chat_del_user(msg, self)
else else
at_name = '' at_name = ''
end end
local text = user_name..' wurde von '..msg.from.first_name..at_name..' aus der Gruppe gekickt.' local text = '<b>'..user_name..'</b> wurde von <b>'..msg.from.first_name..'</b>'..at_name..' aus der Gruppe gekickt.'
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, 'HTML')
end end
function entergroup:action(msg, config, matches) function entergroup:action(msg, config, matches)

View File

@ -5,28 +5,27 @@ function shell:init(config)
end end
function shell:action(msg, config) function shell:action(msg, config)
if not is_sudo(msg, config) then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
if msg.from.id ~= config.admin then local input = utilities.input(msg.text)
utilities.send_reply(self, msg, config.errors.sudo) if not input then
return utilities.send_reply(self, msg, 'Bitte gib ein Kommando ein.')
end return
end
local input = utilities.input(msg.text) input = input:gsub('', '--')
input = input:gsub('', '--')
if not input then
utilities.send_reply(self, msg, 'Bitte gebe ein Kommando ein.')
return
end
local output = io.popen(input):read('*all')
if output:len() == 0 then
output = 'Ausgeführt.'
else
output = '```\n' .. output .. '\n```'
end
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
local output = run_command(input)
if output:len() == 0 then
output = 'Ausgeführt.'
else
output = '<pre>\n' .. output .. '\n</pre>'
end
output = output:gsub('<pre>%\n', '<pre>')
output = output:gsub('%\n%\n</pre>', '</pre>')
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, 'HTML')
end end
return shell return shell

View File

@ -30,7 +30,7 @@ function tagesschau:get_tagesschau_article(article)
local news = data.shorttext local news = data.shorttext
local posted_at = makeOurDate(data.date)..' Uhr' local posted_at = makeOurDate(data.date)..' Uhr'
local text = '*'..title..'*\n_'..posted_at..'_\n'..news local text = '<b>'..title..'</b>\n<i>'..posted_at..'</i>\n'..news
if data.banner[1] then if data.banner[1] then
return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext
else else
@ -55,7 +55,7 @@ function tagesschau:inline_callback(inline_query, config, matches)
end end
local text = text:gsub('\n', '\\n') local text = text:gsub('\n', '\\n')
local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..headline..'","description":"'..shorttext..'","url":"'..full_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/tagesschau/tagesschau.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Artikel aufrufen","url":"'..full_url..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}}]' local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..headline..'","description":"'..shorttext..'","url":"'..full_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/tagesschau/tagesschau.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Artikel aufrufen","url":"'..full_url..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}}]'
utilities.answer_inline_query(self, inline_query, results, 7200) utilities.answer_inline_query(self, inline_query, results, 7200)
end end
@ -67,7 +67,7 @@ function tagesschau:action(msg, config, matches)
local file = download_to_file(image_url) local file = download_to_file(image_url)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end end
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, 'HTML')
end end
return tagesschau return tagesschau

View File

@ -2,20 +2,20 @@ local twitter = {}
function twitter:init(config) function twitter:init(config)
if not cred_data.tw_consumer_key then if not cred_data.tw_consumer_key then
print('Fehlender Key: tw_consumer_key.') print('Missing config value: tw_consumer_key.')
print('twitter.lua wird nicht aktiviert.') print('twitter.lua will not be enabled.')
return return
elseif not cred_data.tw_consumer_secret then elseif not cred_data.tw_consumer_secret then
print('Fehlender Key: tw_consumer_secret.') print('Missing config value: tw_consumer_secret.')
print('twitter.lua wird nicht aktiviert.') print('twitter.lua will not be enabled.')
return return
elseif not cred_data.tw_access_token then elseif not cred_data.tw_access_token then
print('Fehlender Key: tw_access_token.') print('Missing config value: tw_access_token.')
print('twitter.lua wird nicht aktiviert.') print('twitter.lua will not be enabled.')
return return
elseif not cred_data.tw_access_token_secret then elseif not cred_data.tw_access_token_secret then
print('Fehlender Key: tw_access_token_secret.') print('Missing config value: tw_access_token_secret.')
print('twitter.lua wird nicht aktiviert.') print('twitter.lua will not be enabled.')
return return
end end
@ -59,8 +59,7 @@ function twitter:action(msg, config, matches)
else else
verified = '' verified = ''
end end
-- MD: local header = 'Tweet von '..full_name..' ([@' ..user_name.. '](https://twitter.com/'..user_name..')'..verified..')\n' local header = '<b>Tweet von '..full_name..'</b> (<a href="https://twitter.com/'..user_name..'">@' ..user_name..'</a>'..verified..'):'
local header = 'Tweet von '..full_name..' (@' ..user_name..verified..')\n'
local text = response.text local text = response.text
@ -76,11 +75,11 @@ function twitter:action(msg, config, matches)
favorites = response.favorite_count..'x favorisiert' favorites = response.favorite_count..'x favorisiert'
end end
if retweets == "" and favorites ~= "" then if retweets == "" and favorites ~= "" then
footer = favorites footer = '<i>'..favorites..'</i>'
elseif retweets ~= "" and favorites == "" then elseif retweets ~= "" and favorites == "" then
footer = retweets footer = '<i>'..retweets..'</i>'
elseif retweets ~= "" and favorites ~= "" then elseif retweets ~= "" and favorites ~= "" then
footer = retweets..' - '..favorites footer = '<i>'..retweets..' - '..favorites..'</i>'
else else
footer = "" footer = ""
end end
@ -126,14 +125,13 @@ function twitter:action(msg, config, matches)
else else
quoted_verified = '' quoted_verified = ''
end end
-- MD: quote = 'Als Antwort auf '..quoted_name..' ([@' ..quoted_screen_name.. '](https://twitter.com/'..quoted_screen_name..')'..quoted_verified..'):\n'..quoted_text quote = '<b>Als Antwort auf '..quoted_name..'</b> (<a href="https://twitter.com/'..quoted_screen_name..'">@' ..quoted_screen_name..'</a>'..quoted_verified..'):\n'..quoted_text
quote = 'Als Antwort auf '..quoted_name..' (@' ..quoted_screen_name..quoted_verified..'):\n'..quoted_text
text = text..'\n\n'..quote..'\n' text = text..'\n\n'..quote..'\n'
end end
-- send the parts -- send the parts
local text = unescape(text) utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer, 'HTML')
utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer) if videos[1] then images = {} end
for k, v in pairs(images) do for k, v in pairs(images) do
local file = download_to_file(v) local file = download_to_file(v)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)

View File

@ -38,14 +38,14 @@ function urbandictionary:action(msg, config)
return return
end end
local output = '*' .. jdat.list[1].word .. '*\n' .. utilities.trim(jdat.list[1].definition) local output = '<b>' .. jdat.list[1].word .. '</b>\n' .. utilities.trim(jdat.list[1].definition)
if string.len(jdat.list[1].example) > 0 then if string.len(jdat.list[1].example) > 0 then
output = output .. '_\n' .. utilities.trim(jdat.list[1].example) .. '_' output = output .. '<i>\n' .. utilities.trim(jdat.list[1].example) .. '</i>'
end end
output = output:gsub('%[', ''):gsub('%]', '') output = output:gsub('%[', ''):gsub('%]', '')
utilities.send_reply(self, msg, output, true) utilities.send_reply(self, msg, output, 'HTML')
end end

View File

@ -2,8 +2,8 @@ local youtube = {}
function youtube:init(config) function youtube:init(config)
if not cred_data.google_apikey then if not cred_data.google_apikey then
print('Fehlender Key: google_apikey.') print('Missing config value: google_apikey.')
print('youtube.lua wird nicht aktiviert.') print('youtube.lua will not be enabled.')
return return
end end
@ -28,13 +28,6 @@ local makeOurDate = function(dateString)
return day..'.'..month..'.'..year return day..'.'..month..'.'..year
end end
function markdown_escape_simple(text)
text = text:gsub('_', '\\_')
text = text:gsub('%*', '\\*')
text = text:gsub('`', '\\`')
return text
end
function get_yt_data (yt_code) function get_yt_data (yt_code)
local apikey = cred_data.google_apikey local apikey = cred_data.google_apikey
local url = BASE_URL..'/videos?part=snippet,statistics,contentDetails&key='..apikey..'&id='..yt_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description),thumbnails),statistics(viewCount,likeCount,dislikeCount,commentCount),contentDetails(duration,regionRestriction(blocked)))' local url = BASE_URL..'/videos?part=snippet,statistics,contentDetails&key='..apikey..'&id='..yt_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description),thumbnails),statistics(viewCount,likeCount,dislikeCount,commentCount),contentDetails(duration,regionRestriction(blocked)))'
@ -99,7 +92,7 @@ function get_yt_thumbnail(data)
end end
function send_youtube_data(data, msg, self, link, sendpic) function send_youtube_data(data, msg, self, link, sendpic)
local title = markdown_escape_simple(data.snippet.localized.title) local title = data.snippet.localized.title
-- local description = data.snippet.localized.description -- local description = data.snippet.localized.description
local uploader = data.snippet.channelTitle local uploader = data.snippet.channelTitle
local upload_date = makeOurDate(data.snippet.publishedAt) local upload_date = makeOurDate(data.snippet.publishedAt)
@ -127,13 +120,13 @@ function send_youtube_data(data, msg, self, link, sendpic)
blocked = false blocked = false
end end
text = '*'..title..'*\n_('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..likeCount..dislikeCount..commentCount..')_\n' text = '<b>'..title..'</b>\n<i>('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..likeCount..dislikeCount..commentCount..')</i>\n'
if link then if link then
text = link..'\n'..text text = link..'\n'..text
end end
if blocked then if blocked then
text = text..'\n*ACHTUNG, Video ist in Deutschland gesperrt!*' text = text..'\n<b>ACHTUNG, Video ist in Deutschland gesperrt!</b>'
end end
if sendpic then if sendpic then
@ -146,7 +139,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
local file = download_to_file(image_url) local file = download_to_file(image_url)
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
else else
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, 'HTML')
end end
end end

View File

@ -23,35 +23,50 @@ https.timeout = 5
-- For the sake of ease to new contributors and familiarity to old contributors, -- For the sake of ease to new contributors and familiarity to old contributors,
-- we'll provide a couple of aliases to real bindings here. -- we'll provide a couple of aliases to real bindings here.
function utilities:send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup) function utilities:send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup)
if use_markdown == true then
use_markdown = 'Markdown'
elseif not use_markdown then
use_markdown = nil
end
return bindings.request(self, 'sendMessage', { return bindings.request(self, 'sendMessage', {
chat_id = chat_id, chat_id = chat_id,
text = text, text = text,
disable_web_page_preview = disable_web_page_preview, disable_web_page_preview = disable_web_page_preview,
reply_to_message_id = reply_to_message_id, reply_to_message_id = reply_to_message_id,
parse_mode = use_markdown and 'Markdown' or nil, parse_mode = use_markdown,
reply_markup = reply_markup reply_markup = reply_markup
} ) } )
end end
-- https://core.telegram.org/bots/api#editmessagetext -- https://core.telegram.org/bots/api#editmessagetext
function utilities:edit_message(chat_id, message_id, text, disable_web_page_preview, use_markdown, reply_markup) function utilities:edit_message(chat_id, message_id, text, disable_web_page_preview, use_markdown, reply_markup)
if use_markdown == true then
use_markdown = 'Markdown'
elseif not use_markdown then
use_markdown = nil
end
return bindings.request(self, 'editMessageText', { return bindings.request(self, 'editMessageText', {
chat_id = chat_id, chat_id = chat_id,
message_id = message_id, message_id = message_id,
text = text, text = text,
disable_web_page_preview = disable_web_page_preview, disable_web_page_preview = disable_web_page_preview,
parse_mode = use_markdown and 'Markdown' or nil, parse_mode = use_markdown,
reply_markup = reply_markup reply_markup = reply_markup
} ) } )
end end
function utilities:send_reply(old_msg, text, use_markdown, reply_markup) function utilities:send_reply(old_msg, text, use_markdown, reply_markup)
if use_markdown == true then
use_markdown = 'Markdown'
elseif not use_markdown then
use_markdown = nil
end
return bindings.request(self, 'sendMessage', { return bindings.request(self, 'sendMessage', {
chat_id = old_msg.chat.id, chat_id = old_msg.chat.id,
text = text, text = text,
disable_web_page_preview = true, disable_web_page_preview = true,
reply_to_message_id = old_msg.message_id, reply_to_message_id = old_msg.message_id,
parse_mode = use_markdown and 'Markdown' or nil, parse_mode = use_markdown,
reply_markup = reply_markup reply_markup = reply_markup
} ) } )
end end
@ -1005,6 +1020,7 @@ function unescape(str)
-- Character encoding -- Character encoding
str = string.gsub(str, "&acute;", "´") str = string.gsub(str, "&acute;", "´")
str = string.gsub(str, "&bull;", "") str = string.gsub(str, "&bull;", "")
str = string.gsub(str, "&eacute;", "é")
str = string.gsub(str, "&gt;", ">") str = string.gsub(str, "&gt;", ">")
str = string.gsub(str, "&hellip;", "") str = string.gsub(str, "&hellip;", "")
str = string.gsub(str, "&lt;", "<") str = string.gsub(str, "&lt;", "<")
@ -1051,6 +1067,10 @@ function unescape(str)
str = string.gsub(str, "&Uuml;", "Ü") str = string.gsub(str, "&Uuml;", "Ü")
str = string.gsub(str, "&#252;", "ü") str = string.gsub(str, "&#252;", "ü")
str = string.gsub(str, "&#220;", "Ü") str = string.gsub(str, "&#220;", "Ü")
--emoticons
str = string.gsub(str, "&#11088;&#65039;", "⭐️")
--str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) --str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
--str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) --str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others