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)
if afk_text then
redis:hset(hash, 'afk_text', false)
local afk_text = afk_text:gsub("%*","")
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}')
utilities.send_reply(self, msg, user_name..' ist wieder da (war: <b>'..afk_text..'</b> für '..duration..')!', 'HTML', '{"hide_keyboard":true,"selective":true}')
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

View File

@ -68,8 +68,8 @@ function app_store:send_appstore_data(data)
end
local header = '*'..name..'* v'..version..' von *'..author..'* ('..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 header = '<b>'..name..'</b> v'..version..' von <b>'..author..'</b> ('..price..'):'
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 text = header..body..footer
@ -96,11 +96,11 @@ function app_store:action(msg, config, matches)
local data = app_store:get_appstore_data()
if data == nil then print('Das Appstore-Plugin unterstützt nur Apps!') end
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
else
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
utilities.send_typing(self, msg.chat.id, 'upload_photo')
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 name = data.name
if data.link then
link = '\n'..data.name..':\n'..utilities.md_escape(data.link)
link = '\n<a href="'..data.link..'">'..data.name..'</a>'
else
link = ""
end
@ -56,7 +56,7 @@ function facebook:fb_post (id, story_id)
story = ""
end
local text = '*'..from..'*'..story..':\n'..message..'\n'..link
local text = '<b>'..from..'</b>'..story..':\n'..message..'\n'..link
return text
end
@ -66,9 +66,9 @@ function facebook:send_facebook_photo(photo_id, receiver)
if code ~= 200 then return nil end
local data = json.decode(res)
local from = '*'..data.from.name..'*'
local from = '<b>'..data.from.name..'</b>'
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
text = from..' hat ein Bild gepostet:'
end
@ -82,7 +82,7 @@ function facebook:send_facebook_video(video_id)
if code ~= 200 then return nil end
local data = json.decode(res)
local from = '*'..data.from.name..'*'
local from = '<b>'..data.from.name..'</b>'
local description = data.description or ''
local source = data.source
return from..' hat ein Video gepostet:\n'..description, source, data.title
@ -123,7 +123,7 @@ function facebook:facebook_info(name)
birth = ""
end
local text = '*'..name..'* ('..category..')_'..about..'_'..general_info..birth
local text = '<b>'..name..'</b> ('..category..')<i>'..about..'</i>'..general_info..birth
return text
end
@ -135,7 +135,7 @@ function facebook:action(msg, config, matches)
else
id = matches[4]
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
elseif matches[1] == 'photo' or matches[2] == 'photos' then
if not matches[4] then
@ -147,7 +147,7 @@ function facebook:action(msg, config, matches)
if not image_url then return end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
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)
return
elseif matches[1] == 'video' or matches[2] == 'videos' then
@ -163,10 +163,10 @@ function facebook:action(msg, config, matches)
title = 'VIDEO: '..title
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
else
utilities.send_reply(self, msg, facebook:facebook_info(matches[1]), true)
utilities.send_reply(self, msg, facebook:facebook_info(matches[1]), 'HTML')
return
end
end

View File

@ -122,16 +122,6 @@ function get_new_entries(last, nentries)
return entries
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)
local baseurl, protocol = prot_url(url)
@ -141,7 +131,7 @@ function rss:subscribe(id, url)
local uhash = get_base_redis(id)
if redis:sismember(uhash, baseurl) then
return "Du hast `"..url.."` bereits abonniert."
return "Du hast <code>"..url.."</code> bereits abonniert."
end
local parsed, err = get_rss(url, protocol)
@ -161,7 +151,7 @@ function rss:subscribe(id, url)
redis:sadd(lhash, id)
redis:sadd(uhash, baseurl)
return "_"..name.."_ abonniert!"
return "<i>"..name.."</i> abonniert!"
end
function rss:unsubscribe(id, n)
@ -189,18 +179,18 @@ function rss:unsubscribe(id, n)
redis:del(lasthash)
end
return "Du hast `"..sub.."` deabonniert."
return "Du hast <code>"..sub.."</code> deabonniert."
end
function rss:print_subs(id, chat_name)
local uhash = get_base_redis(id)
local subs = redis:smembers(uhash)
if not subs[1] then
return 'Keine Feeds abonniert!'
return '<b>Keine Feeds abonniert!</b>'
end
local keyboard = '{"keyboard":[['
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
text = text .. k .. ") " .. v .. '\n'
if k == #subs then
@ -232,7 +222,7 @@ function rss:action(msg, config, matches)
return
end
local output = rss:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
return
elseif matches[1] == 'del' and matches[2] and matches[3] then
if msg.from.id ~= config.admin then
@ -246,7 +236,7 @@ function rss:action(msg, config, matches)
return
end
local output = rss:unsubscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
return
elseif matches[1] == 'rss' and matches[2] then
local id = '@'..matches[2]
@ -257,7 +247,7 @@ function rss:action(msg, config, matches)
end
local chat_name = result.result.title
local output = rss:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
return
end
@ -273,7 +263,7 @@ function rss:action(msg, config, matches)
return
end
local output = rss:subscribe(id, matches[2])
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
return
elseif matches[1] == 'del' and matches[2] then
if msg.from.id ~= config.admin then
@ -281,11 +271,11 @@ function rss:action(msg, config, matches)
return
end
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
elseif matches[1] == 'del' and not matches[2] then
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
elseif matches[1] == 'sync' then
if msg.from.id ~= config.admin then
@ -297,7 +287,7 @@ function rss:action(msg, config, matches)
end
local output = rss:print_subs(id, chat_name)
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
return
end
@ -342,7 +332,7 @@ function rss:cron(self_plz)
else
content = ''
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
if text ~= '' then
local newlast = newentr[1].id
@ -350,7 +340,7 @@ function rss:cron(self_plz)
for k2, receiver in pairs(redis:smembers(v)) do
local receiver = string.gsub(receiver, 'chat%#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

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
return
end
local text = 'Hallo '..user_name..', willkommen bei *'..chat_title..'*!'..added_by
utilities.send_reply(self, msg, text, true)
local text = 'Hallo '..user_name..', willkommen bei <b>'..chat_title..'</b>!'..added_by
utilities.send_reply(self, msg, text, 'HTML')
end
function entergroup:chat_del_user(msg, self)
@ -35,8 +35,8 @@ function entergroup:chat_del_user(msg, self)
else
at_name = ''
end
local text = user_name..' wurde von '..msg.from.first_name..at_name..' aus der Gruppe gekickt.'
utilities.send_reply(self, msg, text, true)
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, 'HTML')
end
function entergroup:action(msg, config, matches)

View File

@ -5,28 +5,27 @@ function shell:init(config)
end
function shell:action(msg, config)
if msg.from.id ~= config.admin then
if not is_sudo(msg, config) then
utilities.send_reply(self, msg, config.errors.sudo)
return
end
local input = utilities.input(msg.text)
input = input:gsub('', '--')
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
end
input = input:gsub('', '--')
local output = io.popen(input):read('*all')
local output = run_command(input)
if output:len() == 0 then
output = 'Ausgeführt.'
else
output = '```\n' .. output .. '\n```'
output = '<pre>\n' .. output .. '\n</pre>'
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
return shell

View File

@ -30,7 +30,7 @@ function tagesschau:get_tagesschau_article(article)
local news = data.shorttext
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
return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext
else
@ -55,7 +55,7 @@ function tagesschau:inline_callback(inline_query, config, matches)
end
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)
end
@ -67,7 +67,7 @@ function tagesschau:action(msg, config, matches)
local file = download_to_file(image_url)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end
utilities.send_reply(self, msg, text, true)
utilities.send_reply(self, msg, text, 'HTML')
end
return tagesschau

View File

@ -86,17 +86,17 @@ function tagesschau_eil:cron(self_plz)
if not data then return end
if data.breakingnews[1] 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 posted_at = makeOurDate(data.breakingnews[1].date)..' Uhr'
local post_url = string.gsub(data.breakingnews[1].details, '/api/', '/')
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)
for _,user in pairs(redis:smembers(hash..':subs')) do
local user = string.gsub(user, 'chat%#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

View File

@ -59,8 +59,7 @@ function twitter:action(msg, config, matches)
else
verified = ''
end
-- MD: local header = 'Tweet von '..full_name..' ([@' ..user_name.. '](https://twitter.com/'..user_name..')'..verified..')\n'
local header = 'Tweet von '..full_name..' (@' ..user_name..verified..')\n'
local header = '<b>Tweet von '..full_name..'</b> (<a href="https://twitter.com/'..user_name..'">@' ..user_name..'</a>'..verified..'):'
local text = response.text
@ -76,11 +75,11 @@ function twitter:action(msg, config, matches)
favorites = response.favorite_count..'x favorisiert'
end
if retweets == "" and favorites ~= "" then
footer = favorites
footer = '<i>'..favorites..'</i>'
elseif retweets ~= "" and favorites == "" then
footer = retweets
footer = '<i>'..retweets..'</i>'
elseif retweets ~= "" and favorites ~= "" then
footer = retweets..' - '..favorites
footer = '<i>'..retweets..' - '..favorites..'</i>'
else
footer = ""
end
@ -126,14 +125,13 @@ function twitter:action(msg, config, matches)
else
quoted_verified = ''
end
-- MD: quote = 'Als Antwort auf '..quoted_name..' ([@' ..quoted_screen_name.. '](https://twitter.com/'..quoted_screen_name..')'..quoted_verified..'):\n'..quoted_text
quote = 'Als Antwort auf '..quoted_name..' (@' ..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
text = text..'\n\n'..quote..'\n'
end
-- send the parts
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
local file = download_to_file(v)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)

View File

@ -38,14 +38,14 @@ function urbandictionary:action(msg, config)
return
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
output = output .. '_\n' .. utilities.trim(jdat.list[1].example) .. '_'
output = output .. '<i>\n' .. utilities.trim(jdat.list[1].example) .. '</i>'
end
output = output:gsub('%[', ''):gsub('%]', '')
utilities.send_reply(self, msg, output, true)
utilities.send_reply(self, msg, output, 'HTML')
end

View File

@ -28,13 +28,6 @@ local makeOurDate = function(dateString)
return day..'.'..month..'.'..year
end
function markdown_escape_simple(text)
text = text:gsub('_', '\\_')
text = text:gsub('%*', '\\*')
text = text:gsub('`', '\\`')
return text
end
function get_yt_data (yt_code)
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)))'
@ -99,7 +92,7 @@ function get_yt_thumbnail(data)
end
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 uploader = data.snippet.channelTitle
local upload_date = makeOurDate(data.snippet.publishedAt)
@ -127,13 +120,13 @@ function send_youtube_data(data, msg, self, link, sendpic)
blocked = false
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
text = link..'\n'..text
end
if blocked then
text = text..'\n*ACHTUNG, Video ist in Deutschland gesperrt!*'
text = text..'\n<b>ACHTUNG, Video ist in Deutschland gesperrt!</b>'
end
if sendpic then
@ -146,7 +139,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
local file = download_to_file(image_url)
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
else
utilities.send_reply(self, msg, text, true)
utilities.send_reply(self, msg, text, 'HTML')
end
end

View File

@ -23,18 +23,28 @@ https.timeout = 5
-- For the sake of ease to new contributors and familiarity to old contributors,
-- 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)
if use_markdown == true then
use_markdown = 'Markdown'
elseif not use_markdown then
use_markdown = nil
end
return bindings.request(self, 'sendMessage', {
chat_id = chat_id,
text = text,
disable_web_page_preview = disable_web_page_preview,
reply_to_message_id = reply_to_message_id,
parse_mode = use_markdown and 'Markdown' or nil,
parse_mode = use_markdown,
reply_markup = reply_markup
} )
end
-- https://core.telegram.org/bots/api#editmessagetext
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', {
chat_id = chat_id,
message_id = message_id,
@ -46,12 +56,17 @@ function utilities:edit_message(chat_id, message_id, text, disable_web_page_prev
end
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', {
chat_id = old_msg.chat.id,
text = text,
disable_web_page_preview = true,
reply_to_message_id = old_msg.message_id,
parse_mode = use_markdown and 'Markdown' or nil,
parse_mode = use_markdown,
reply_markup = reply_markup
} )
end