Verwende in einigen Plugins HTML, statt Markdown

This commit is contained in:
Andreas Bielawski 2016-08-04 13:02:47 +02:00
parent 0969aeb9c3
commit bd877e5642
12 changed files with 90 additions and 97 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

@ -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

@ -122,16 +122,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)
@ -141,7 +131,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)
@ -161,7 +151,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)
@ -189,18 +179,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
@ -232,7 +222,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
@ -246,7 +236,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]
@ -257,7 +247,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
@ -273,7 +263,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
@ -281,11 +271,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
@ -297,7 +287,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)
else else
content = '' content = ''
end end
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
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo) utilities.send_reply(self, msg, config.errors.sudo)
return return
end end
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
input = input:gsub('', '--')
if not input then if not input then
utilities.send_reply(self, msg, 'Bitte gebe ein Kommando ein.') utilities.send_reply(self, msg, 'Bitte gib ein Kommando ein.')
return return
end end
input = input:gsub('', '--')
local output = io.popen(input):read('*all') local output = run_command(input)
if output:len() == 0 then if output:len() == 0 then
output = 'Ausgeführt.' output = 'Ausgeführt.'
else else
output = '```\n' .. output .. '\n```' output = '<pre>\n' .. output .. '\n</pre>'
end end
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true) 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

@ -86,17 +86,17 @@ function tagesschau_eil:cron(self_plz)
if not data then return end if not data then return end
if data.breakingnews[1] then if data.breakingnews[1] then
if data.breakingnews[1].date ~= last_eil then if data.breakingnews[1].date ~= last_eil then
local title = '#EIL: *'..data.breakingnews[1].headline..'*' local title = '#EIL: <b>'..data.breakingnews[1].headline..'</b>'
local news = data.breakingnews[1].shorttext local news = data.breakingnews[1].shorttext
local posted_at = makeOurDate(data.breakingnews[1].date)..' Uhr' local posted_at = makeOurDate(data.breakingnews[1].date)..' Uhr'
local post_url = string.gsub(data.breakingnews[1].details, '/api/', '/') local post_url = string.gsub(data.breakingnews[1].details, '/api/', '/')
local post_url = string.gsub(post_url, '.json', '.html') local post_url = string.gsub(post_url, '.json', '.html')
local eil = title..'\n_'..posted_at..'_\n'..news local eil = title..'\n<i>'..posted_at..'</i>\n'..news
redis:set(hash..':last_entry', data.breakingnews[1].date) redis:set(hash..':last_entry', data.breakingnews[1].date)
for _,user in pairs(redis:smembers(hash..':subs')) do for _,user in pairs(redis:smembers(hash..':subs')) do
local user = string.gsub(user, 'chat%#id', '') local user = string.gsub(user, 'chat%#id', '')
local user = string.gsub(user, 'user%#id', '') local user = string.gsub(user, 'user%#id', '')
utilities.send_message(self, user, eil, true, nil, true, '{"inline_keyboard":[[{"text":"Eilmeldung aufrufen","url":"'..post_url..'"}]]}') utilities.send_message(self, user, eil, true, nil, 'HTML', '{"inline_keyboard":[[{"text":"Eilmeldung aufrufen","url":"'..post_url..'"}]]}')
end end
end end
end end

View File

@ -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) local text = unescape(text)
utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer) utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer, 'HTML')
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

@ -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,18 +23,28 @@ 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,
@ -46,12 +56,17 @@ function utilities:edit_message(chat_id, message_id, text, disable_web_page_prev
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