Merge pull request #56 from TiagoDanin/Markdown

Improvements and fix
This commit is contained in:
Drew 2016-04-28 14:01:53 -04:00
commit 0483edb0c3
23 changed files with 77 additions and 76 deletions

View File

@ -8,15 +8,15 @@ local triggers = {
local action = function(msg) local action = function(msg)
-- Filthy hack, but here is where we'll stop forwarded messages from hitting -- Filthy hack, but here is where we'll stop forwarded messages from hitting
-- other plugins. -- Other plugins.
if msg.forward_from then return end if msg.forward_from then return end
local message = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.' local output = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.'
if (msg.new_chat_participant and msg.new_chat_participant.id == bot.id) if (msg.new_chat_participant and msg.new_chat_participant.id == bot.id)
or msg.text_lower:match('^/about[@'..bot.username..']*') or msg.text_lower:match('^/about[@'..bot.username..']*')
or msg.text_lower:match('^/start') then or msg.text_lower:match('^/start') then
sendMessage(msg.chat.id, message, true) sendMessage(msg.chat.id, output, true)
return return
end end

View File

@ -13,25 +13,25 @@ local fullnames = { "Wimbledon Tennismatch", "Rinkydink Curdlesnoot", "Butawhite
local firstnames = { "Bumblebee", "Bandersnatch", "Broccoli", "Rinkydink", "Bombadil", "Boilerdang", "Bandicoot", "Fragglerock", "Muffintop", "Congleton", "Blubberdick", "Buffalo", "Benadryl", "Butterfree", "Burberry", "Whippersnatch", "Buttermilk", "Beezlebub", "Budapest", "Boilerdang", "Blubberwhale", "Bumberstump", "Bulbasaur", "Cogglesnatch", "Liverswort", "Bodybuild", "Johnnycash", "Bendydick", "Burgerking", "Bonaparte", "Bunsenburner", "Billiardball", "Bukkake", "Baseballmitt", "Blubberbutt", "Baseballbat", "Rumblesack", "Barister", "Danglerack", "Rinkydink", "Bombadil", "Honkytonk", "Billyray", "Bumbleshack", "Snorkeldink", "Anglerfish", "Beetlejuice", "Bedlington", "Bandicoot", "Boobytrap", "Blenderdick", "Bentobox", "Anallube", "Pallettown", "Wimbledon", "Buttercup", "Blasphemy", "Snorkeldink", "Brandenburg", "Barbituate", "Snozzlebert", "Tiddleywomp", "Bouillabaisse", "Wellington", "Benetton", "Bendandsnap", "Timothy", "Brewery", "Bentobox", "Brandybuck", "Benjamin", "Buckminster", "Bourgeoisie", "Bakery", "Oscarbait", "Buckyball", "Bourgeoisie", "Burlington", "Buckingham", "Barnoldswick" } local firstnames = { "Bumblebee", "Bandersnatch", "Broccoli", "Rinkydink", "Bombadil", "Boilerdang", "Bandicoot", "Fragglerock", "Muffintop", "Congleton", "Blubberdick", "Buffalo", "Benadryl", "Butterfree", "Burberry", "Whippersnatch", "Buttermilk", "Beezlebub", "Budapest", "Boilerdang", "Blubberwhale", "Bumberstump", "Bulbasaur", "Cogglesnatch", "Liverswort", "Bodybuild", "Johnnycash", "Bendydick", "Burgerking", "Bonaparte", "Bunsenburner", "Billiardball", "Bukkake", "Baseballmitt", "Blubberbutt", "Baseballbat", "Rumblesack", "Barister", "Danglerack", "Rinkydink", "Bombadil", "Honkytonk", "Billyray", "Bumbleshack", "Snorkeldink", "Anglerfish", "Beetlejuice", "Bedlington", "Bandicoot", "Boobytrap", "Blenderdick", "Bentobox", "Anallube", "Pallettown", "Wimbledon", "Buttercup", "Blasphemy", "Snorkeldink", "Brandenburg", "Barbituate", "Snozzlebert", "Tiddleywomp", "Bouillabaisse", "Wellington", "Benetton", "Bendandsnap", "Timothy", "Brewery", "Bentobox", "Brandybuck", "Benjamin", "Buckminster", "Bourgeoisie", "Bakery", "Oscarbait", "Buckyball", "Bourgeoisie", "Burlington", "Buckingham", "Barnoldswick" }
local lastnames = { "Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch", "Humperdinck", "Rivendell", "Cuttlefish", "Lingerie", "Vegemite", "Ampersand", "Cumberbund", "Candycrush", "Clombyclomp", "Cragglethatch", "Nottinghill", "Cabbagepatch", "Camouflage","Creamsicle", "Curdlemilk", "Upperclass", "Frumblesnatch", "Crumplehorn", "Talisman", "Candlestick", "Chesterfield", "Bumbersplat", "Scratchnsniff", "Snugglesnatch", "Charizard", "Carrotstick", "Cumbercooch", "Crackerjack", "Crucifix", "Cuckatoo", "Cockletit", "Collywog", "Capncrunch", "Covergirl", "Cumbersnatch", "Countryside","Coggleswort", "Splishnsplash", "Copperwire", "Animorph", "Curdledmilk", "Cheddarcheese", "Cottagecheese", "Crumplehorn", "Snickersbar", "Banglesnatch", "Stinkyrash", "Cameltoe", "Chickenbroth", "Concubine", "Candygram", "Moldyspore", "Chuckecheese", "Cankersore", "Crimpysnitch", "Wafflesmack", "Chowderpants", "Toodlesnoot", "Clavichord", "Cuckooclock", "Oxfordshire", "Cumbersome", "Chickenstrips", "Battleship", "Commonwealth", "Cunningsnatch", "Custardbath", "Kryptonite", "Curdlesnoot", "Cummerbund", "Coochyrash", "Crackerdong", "Crackerdong", "Curdledong", "Crackersprout", "Crumplebutt", "Colonist", "Coochierash", "Thundersnatch" } local lastnames = { "Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch", "Humperdinck", "Rivendell", "Cuttlefish", "Lingerie", "Vegemite", "Ampersand", "Cumberbund", "Candycrush", "Clombyclomp", "Cragglethatch", "Nottinghill", "Cabbagepatch", "Camouflage", "Creamsicle", "Curdlemilk", "Upperclass", "Frumblesnatch", "Crumplehorn", "Talisman", "Candlestick", "Chesterfield", "Bumbersplat", "Scratchnsniff", "Snugglesnatch", "Charizard", "Carrotstick", "Cumbercooch", "Crackerjack", "Crucifix", "Cuckatoo", "Cockletit", "Collywog", "Capncrunch", "Covergirl", "Cumbersnatch", "Countryside", "Coggleswort", "Splishnsplash", "Copperwire", "Animorph", "Curdledmilk", "Cheddarcheese", "Cottagecheese", "Crumplehorn", "Snickersbar", "Banglesnatch", "Stinkyrash", "Cameltoe", "Chickenbroth", "Concubine", "Candygram", "Moldyspore", "Chuckecheese", "Cankersore", "Crimpysnitch", "Wafflesmack", "Chowderpants", "Toodlesnoot", "Clavichord", "Cuckooclock", "Oxfordshire", "Cumbersome", "Chickenstrips", "Battleship", "Commonwealth", "Cunningsnatch", "Custardbath", "Kryptonite", "Curdlesnoot", "Cummerbund", "Coochyrash", "Crackerdong", "Crackerdong", "Curdledong", "Crackersprout", "Crumplebutt", "Colonist", "Coochierash", "Thundersnatch" }
local action = function(msg) local action = function(msg)
local message local message
if math.random(10) == 10 then if math.random(10) == 10 then
message = fullnames[math.random(#fullnames)] output = fullnames[math.random(#fullnames)]
else else
message = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)] output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
end end
sendReply(msg, message) sendMessage(msg.chat.id, output, true, nil, true)
end end
return { return {
action = action, action = action,
triggers = triggers, triggers = triggers,
command = command, doc = doc,
desc = desc command = command
} }

View File

@ -27,22 +27,22 @@ local action = function(msg)
local url = 'http://api.biblia.com/v1/bible/content/ASV.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input) local url = 'http://api.biblia.com/v1/bible/content/ASV.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
local message, res = HTTP.request(url) local output, res = HTTP.request(url)
if not message or res ~= 200 or message:len() == 0 then if not output or res ~= 200 or output:len() == 0 then
url = 'http://api.biblia.com/v1/bible/content/KJVAPOC.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input) url = 'http://api.biblia.com/v1/bible/content/KJVAPOC.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
message, res = HTTP.request(url) output, res = HTTP.request(url)
end end
if not message or res ~= 200 or message:len() == 0 then if not output or res ~= 200 or output:len() == 0 then
message = config.errors.results output = config.errors.results
end end
if message:len() > 4000 then if output:len() > 4000 then
message = 'The text is too long to post here. Try being more specific.' output = 'The text is too long to post here. Try being more specific.'
end end
sendReply(msg, message) sendMessage(msg.chat.id, output, true, msg.message_id, true)
end end

View File

@ -28,7 +28,7 @@ local action = function(msg)
return return
end end
output = '`' .. output .. '`' output = '*Result:* `' .. output .. '`'
sendMessage(msg.chat.id, output, true, msg.message_id, true) sendMessage(msg.chat.id, output, true, msg.message_id, true)

View File

@ -33,7 +33,7 @@ local action = function(msg)
local input = msg.text_lower local input = msg.text_lower
input = input:gsub(bot.first_name, 'simsimi') input = input:gsub(bot.first_name, 'simsimi')
input = input:gsub('@'..bot.username, 'simsimi') input = input:gsub('@'..bot.username, 'simsimi')
if config.simsimi_trial then if config.simsimi_trial then
sandbox = 'sandbox.' sandbox = 'sandbox.'
else else
@ -53,10 +53,10 @@ local action = function(msg)
sendMessage(msg.chat.id, config.errors.chatter_response) sendMessage(msg.chat.id, config.errors.chatter_response)
return return
end end
local message = jdat.response local output = jdat.response
if message:match('^I HAVE NO RESPONSE.') then if output:match('^I HAVE NO RESPONSE.') then
message = config.errors.chatter_response output = config.errors.chatter_response
end end
-- Let's clean up the response a little. Capitalization & punctuation. -- Let's clean up the response a little. Capitalization & punctuation.
@ -68,14 +68,14 @@ local action = function(msg)
} }
for k,v in pairs(filter) do for k,v in pairs(filter) do
message = string.gsub(message, k, v) output = string.gsub(output, k, v)
end end
if not string.match(message, '%p$') then if not string.match(output, '%p$') then
message = message .. '.' output = output .. '.'
end end
sendMessage(msg.chat.id, message) sendMessage(msg.chat.id, output)
end end

View File

@ -418,7 +418,8 @@ local commits = {
local action = function(msg) local action = function(msg)
sendMessage(msg.chat.id, '`'..commits[math.random(#commits)]..'`', true, nil, true) local output = '*Commit:* '..commits[math.random(#commits)]
sendMessage(msg.chat.id, output, true, nil, true)
end end

View File

@ -45,9 +45,8 @@ local action = function(msg)
end end
local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n\n' local output = '*' .. amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '*\n\n'
output = output .. os.date('!%F %T UTC') .. '\nSource: Google Finance' output = output .. '`' .. os.date('!%F %T UTC') .. '\nSource: Google Finance`'
output = '`' .. output .. '`'
sendMessage(msg.chat.id, output, true, nil, true) sendMessage(msg.chat.id, output, true, nil, true)

View File

@ -17,7 +17,7 @@ local action = function(msg)
else else
local output local output
if msg.chat.type == 'supergroup' then if msg.chat.type == 'supergroup' then
output = 'Echo:\n"' .. input .. '"' output = 'Echo:\n"' .. markdown_escape(input) .. '"'
else else
output = latcyr(input) output = latcyr(input)
end end

View File

@ -39,15 +39,15 @@ local yesno_answers = {
local action = function(msg) local action = function(msg)
local message local output
if msg.text_lower:match('y/n%p?$') then if msg.text_lower:match('y/n%p?$') then
message = yesno_answers[math.random(#yesno_answers)] output = yesno_answers[math.random(#yesno_answers)]
else else
message = ball_answers[math.random(#ball_answers)] output = ball_answers[math.random(#ball_answers)]
end end
sendReply(msg, message) sendReply(msg, output)
end end

View File

@ -16,8 +16,8 @@ local triggers = {
local action = function(msg) local action = function(msg)
local message = io.popen('fortune'):read('*all') local output = io.popen('fortune'):read('*all')
sendMessage(msg.chat.id, message) sendMessage(msg.chat.id, output)
end end

View File

@ -64,7 +64,8 @@ local action = function(msg)
if msg.text:match('nsfw') then if msg.text:match('nsfw') then
sendReply(msg, result) output = 'NSFW Image ' .. output
sendMessage(msg.chat.id, output, true, nil, true)
else else
sendMessage(msg.chat.id, output, false, nil, true) sendMessage(msg.chat.id, output, false, nil, true)
end end

View File

@ -13,6 +13,8 @@ local triggers = {
local action = function(msg) local action = function(msg)
sendChatAction(msg.chat.id, "find_location")
local input = msg.text:input() local input = msg.text:input()
if not input then if not input then
if msg.reply_to_message and msg.reply_to_message.text then if msg.reply_to_message and msg.reply_to_message.text then

View File

@ -11,8 +11,6 @@ local triggers = {
local action = function(msg) local action = function(msg)
sendChatAction(msg.chat.id, 'typing')
local jstr, res = HTTPS.request('https://hacker-news.firebaseio.com/v0/topstories.json') local jstr, res = HTTPS.request('https://hacker-news.firebaseio.com/v0/topstories.json')
if res ~= 200 then if res ~= 200 then
sendReply(msg, config.errors.connection) sendReply(msg, config.errors.connection)

View File

@ -38,7 +38,7 @@ local action = function(msg)
local output = '[' .. jdat.Title .. '](http://imdb.com/title/' local output = '[' .. jdat.Title .. '](http://imdb.com/title/'
output = output .. jdat.imdbID .. ') ('.. jdat.Year ..')\n' output = output .. jdat.imdbID .. ') ('.. jdat.Year ..')\n'
output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n' output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
output = output .. jdat.Plot output = output .. '`' .. jdat.Plot .. '`'
sendMessage(msg.chat.id, output, true, nil, true) sendMessage(msg.chat.id, output, true, nil, true)

View File

@ -45,14 +45,14 @@ local action = function(msg)
local url = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&format=json&limit=1&api_key=' .. config.lastfm_api_key .. '&user=' local url = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&format=json&limit=1&api_key=' .. config.lastfm_api_key .. '&user='
local username local username
local output = '' local alert = ''
if input then if input then
username = input username = input
elseif database.users[msg.from.id_str].lastfm then elseif database.users[msg.from.id_str].lastfm then
username = database.users[msg.from.id_str].lastfm username = database.users[msg.from.id_str].lastfm
elseif msg.from.username then elseif msg.from.username then
username = msg.from.username username = msg.from.username
output = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /fmset <username>.' alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /fmset <username>.'
database.users[msg.from.id_str].lastfm = username database.users[msg.from.id_str].lastfm = username
else else
sendReply(msg, 'Please specify your last.fm username or set it with /fmset.') sendReply(msg, 'Please specify your last.fm username or set it with /fmset.')
@ -75,17 +75,17 @@ local action = function(msg)
local jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track local jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
if not jdat then if not jdat then
sendReply(msg, 'No history for this user.' .. output) sendReply(msg, 'No history for this user.' .. alert)
return return
end end
local message = input or msg.from.first_name local output = input or msg.from.first_name
message = '🎵 ' .. message output = '🎵 ' .. output
if jdat['@attr'] and jdat['@attr'].nowplaying then if jdat['@attr'] and jdat['@attr'].nowplaying then
message = message .. ' is currently listening to:\n' output = output .. ' is currently listening to:\n'
else else
message = message .. ' last listened to:\n' output = output .. ' last listened to:\n'
end end
local title = jdat.name or 'Unknown' local title = jdat.name or 'Unknown'
@ -94,8 +94,8 @@ local action = function(msg)
artist = jdat.artist['#text'] artist = jdat.artist['#text']
end end
message = message .. title .. ' - ' .. artist .. output output = output .. title .. ' - ' .. artist .. alert
sendMessage(msg.chat.id, message) sendMessage(msg.chat.id, output)
end end

View File

@ -28,10 +28,10 @@ local action = function(msg)
if not input then if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true) sendMessage(msg.chat.id, doc, true, msg.message_id, true)
elseif input == '-' then elseif input == '-' then
database.lastfm[msg.from.id_str] = nil database.librefm[msg.from.id_str] = nil
sendReply(msg, 'Your libre.fm username has been forgotten.') sendReply(msg, 'Your libre.fm username has been forgotten.')
else else
database.lastfm[msg.from.id_str] = input database.librefm[msg.from.id_str] = input
sendReply(msg, 'Your libre.fm username has been set to "' .. input .. '".') sendReply(msg, 'Your libre.fm username has been set to "' .. input .. '".')
end end
return return
@ -40,15 +40,15 @@ local action = function(msg)
local url = 'http://alpha.libre.fm/2.0/?method=user.getrecenttracks&format=json&limit=1&api_key=0&user=' local url = 'http://alpha.libre.fm/2.0/?method=user.getrecenttracks&format=json&limit=1&api_key=0&user='
local username local username
local output = '' local alert = ''
if input then if input then
username = input username = input
elseif database.lastfm[msg.from.id_str] then elseif database.librefm[msg.from.id_str] then
username = database.lastfm[msg.from.id_str] username = database.librefm[msg.from.id_str]
elseif msg.from.username then elseif msg.from.username then
username = msg.from.username username = msg.from.username
output = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /lfmset <username>.' alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /lfmset <username>.'
database.lastfm[msg.from.id_str] = username database.librefm[msg.from.id_str] = username
else else
sendReply(msg, 'Please specify your libre.fm username or set it with /lfmset.') sendReply(msg, 'Please specify your libre.fm username or set it with /lfmset.')
return return
@ -70,17 +70,17 @@ local action = function(msg)
local jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track local jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
if not jdat then if not jdat then
sendReply(msg, 'No history for this user.' .. output) sendReply(msg, 'No history for this user.' .. alert)
return return
end end
local message = input or msg.from.first_name local output = input or msg.from.first_name
message = '🎵 ' .. message output = '🎵 ' .. output
if jdat['@attr'] and jdat['@attr'].nowplaying then if jdat['@attr'] and jdat['@attr'].nowplaying then
message = message .. ' is currently listening to:\n' output = output .. ' is currently listening to:\n'
else else
message = message .. ' last listened to:\n' output = output .. ' last listened to:\n'
end end
local title = jdat.name or 'Unknown' local title = jdat.name or 'Unknown'
@ -89,8 +89,8 @@ local action = function(msg)
artist = jdat.artist['#text'] artist = jdat.artist['#text']
end end
message = message .. title .. ' - ' .. artist .. output output = output .. title .. ' - ' .. artist .. alert
sendMessage(msg.chat.id, message) sendMessage(msg.chat.id, output)
end end

View File

@ -39,7 +39,7 @@ local action = function(msg)
output = target.name .. '\'s nickname has been set to "' .. input .. '".' output = target.name .. '\'s nickname has been set to "' .. input .. '".'
end end
sendReply(msg, output) sendMessage(msg.chat.id, output, true, nil, true)
end end

View File

@ -12,8 +12,8 @@ local action = function(msg)
local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$') local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
if not m2 then return true end if not m2 then return true end
output = output:gsub(m1, m2) output = output:gsub(m1, m2)
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"' output = '*Did you mean:*\n"' .. output:sub(1, 4000) .. '"'
sendReply(msg.reply_to_message, output) sendMessage(msg.chat.id, output, true, msg.message_id, true)
end end

View File

@ -6,7 +6,7 @@ local triggers = {
} }
local action = function(msg) local action = function(msg)
sendMessage(msg.chat.id, msg.text_lower:match('^/ping') and 'Pong!' or 'Annyong.') sendMessage(msg.chat.id, msg.text_lower:match('^/ping') and '*Pong!*' or '*Annyong.*', true, nil, true)
end end
return { return {

View File

@ -71,8 +71,8 @@ local cron = function()
-- If the reminder is past-due, send it and nullify it. -- If the reminder is past-due, send it and nullify it.
-- Otherwise, add it to the replacement table. -- Otherwise, add it to the replacement table.
if time > reminder.time then if time > reminder.time then
local output = 'Reminder:\n"' .. reminder.message .. '"' local output = '*Reminder:*\n"' .. markdown_escape(reminder.message) .. '"'
local res = sendMessage(chat_id, output, true) local res = sendMessage(chat_id, output, true, nil, true)
-- If the message fails to send, save it for later. -- If the message fails to send, save it for later.
if res then if res then
reminder = nil reminder = nil

View File

@ -41,9 +41,9 @@ local action = function(msg)
if utcoff == math.abs(utcoff) then if utcoff == math.abs(utcoff) then
utcoff = '+' .. utcoff utcoff = '+' .. utcoff
end end
local message = os.date('%I:%M %p\n', timestamp) .. os.date('%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')' local output = '`' .. os.date('%I:%M %p\n', timestamp) .. os.date('%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')' .. '`'
sendReply(msg, message) sendMessage(msg.chat.id, output, true, nil, true)
end end

View File

@ -36,9 +36,9 @@ local action = function(msg)
end end
local output = jdat.text[1] local output = jdat.text[1]
output = 'Translation:\n"' .. output .. '"' output = '*Translation:*\n"' .. output .. '"'
sendReply(msg.reply_to_message or msg, output) sendMessage(msg.chat.id, output, true, msg.message_id, true)
end end

View File

@ -48,9 +48,9 @@ local action = function(msg)
local celsius = string.format('%.2f', jdat.main.temp - 273.15) local celsius = string.format('%.2f', jdat.main.temp - 273.15)
local fahrenheit = string.format('%.2f', celsius * (9/5) + 32) local fahrenheit = string.format('%.2f', celsius * (9/5) + 32)
local message = celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.' local output = celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.'
sendReply(msg, message) sendMessage(msg.chat.id, output, true, msg.message_id, true)
end end