Merge branch 'master' into less-magic

This commit is contained in:
Brayden Banks 2016-04-28 21:12:04 -07:00
commit 41181085ce
18 changed files with 71 additions and 68 deletions

View File

@ -16,13 +16,13 @@ function about:action(msg)
-- other plugins.
if msg.forward_from then return end
local message = self.config.about_text .. '\nBased on @otouto v'..bot.version..' by topkecleon.'
local output = self.config.about_text .. '\nBased on @otouto v'..bot.version..' by topkecleon.'
if (msg.new_chat_participant and msg.new_chat_participant.id == self.info.id)
or msg.text_lower:match('^/about')
or msg.text_lower:match('^/about@'..self.info.username:lower())
or msg.text_lower:match('^/start') then
bindings.sendMessage(self, msg.chat.id, message, true)
bindings.sendMessage(self, msg.chat.id, output, true)
return
end

View File

@ -21,15 +21,15 @@ local lastnames = { "Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch",
function bandersnatch:action(msg)
local message
local output
if math.random(10) == 10 then
message = fullnames[math.random(#fullnames)]
output = fullnames[math.random(#fullnames)]
else
message = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
output = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
end
bindings.sendReply(self, msg, message)
bindings.sendReply(self, msg, output)
end

View File

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

View File

@ -63,10 +63,10 @@ function chatter:action(msg)
bindings.sendMessage(self, msg.chat.id, self.config.errors.chatter_response)
return
end
local message = jdat.response
local output = jdat.response
if message:match('^I HAVE NO RESPONSE.') then
message = self.config.errors.chatter_response
if output:match('^I HAVE NO RESPONSE.') then
output = self.config.errors.chatter_response
end
-- Let's clean up the response a little. Capitalization & punctuation.
@ -78,14 +78,14 @@ function chatter:action(msg)
}
for k,v in pairs(filter) do
message = string.gsub(message, k, v)
output = string.gsub(output, k, v)
end
if not string.match(message, '%p$') then
message = message .. '.'
if not string.match(output, '%p$') then
output = output .. '.'
end
bindings.sendMessage(self, msg.chat.id, message)
bindings.sendMessage(self, msg.chat.id, output)
end

View File

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

View File

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

View File

@ -22,9 +22,9 @@ function echo:action(msg)
else
local output
if msg.chat.type == 'supergroup' then
output = 'Echo:\n"' .. input .. '"'
output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"'
else
output = utilities.latcyr(input)
output = utilities.md_escape(utilities.latcyr(input))
end
bindings.sendMessage(self, msg.chat.id, output, true)
end

View File

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

View File

@ -21,8 +21,10 @@ fortune.doc = '`Returns a UNIX fortune.`'
function fortune:action(msg)
local message = io.popen('fortune'):read('*all')
bindings.sendMessage(self, msg.chat.id, message)
local fortunef = io.popen('fortune')
local output = fortunef:read('*all')
bindings.sendMessage(self, msg.chat.id, output)
fortunef:close()
end

View File

@ -69,7 +69,7 @@ function gImages:action(msg)
if msg.text:match('nsfw') then
bindings.sendReply(self, msg, output)
bindings.sendReply(self, '*NSFW*\n'..msg, output)
else
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
end

View File

@ -43,10 +43,10 @@ function imdb:action(msg)
return
end
local output = '[' .. jdat.Title .. '](http://imdb.com/title/'
output = output .. jdat.imdbID .. ') ('.. jdat.Year ..')\n'
local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')*\n'
output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
output = output .. jdat.Plot
output = output .. '_' .. jdat.Plot .. '_\n'
output = output .. '[*Read more*](http://imdb.com/title/' .. jdat.imdbID .. ')'
bindings.sendMessage(self, msg.chat.id, output, true, nil, true)

View File

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

View File

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

View File

@ -10,7 +10,8 @@ function ping:init()
end
function ping:action(msg)
bindings.sendMessage(self, msg.chat.id, msg.text_lower:match('^/ping') and 'Pong!' or 'Annyong.')
local output = msg.text_lower:match('^/ping') and 'Pong!' or 'Annyong.'
bindings.sendMessage(self, msg.chat.id, output)
end
return ping

View File

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

View File

@ -53,9 +53,9 @@ function time:action(msg)
else
utcoff = utilities.pretty_float(utcoff)
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 .. ')``'
bindings.sendReply(self, msg, message)
bindings.sendReply(self, msg, output)
end

View File

@ -43,7 +43,7 @@ function translate:action(msg)
end
local output = jdat.text[1]
output = 'Translation:\n"' .. output .. '"'
output = '*Translation:*\n"' .. utilities.md_escape(output) .. '"'
bindings.sendReply(self, msg.reply_to_message or msg, output)

View File

@ -55,9 +55,9 @@ function weather:action(msg)
local celsius = string.format('%.2f', jdat.main.temp - 273.15)
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 .. '.`'
bindings.sendReply(self, msg, message)
bindings.sendReply(self, msg, output)
end