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. -- other plugins.
if msg.forward_from then return end 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) 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')
or msg.text_lower:match('^/about@'..self.info.username:lower()) or msg.text_lower:match('^/about@'..self.info.username:lower())
or msg.text_lower:match('^/start') then or msg.text_lower:match('^/start') then
bindings.sendMessage(self, msg.chat.id, message, true) bindings.sendMessage(self, msg.chat.id, output, true)
return return
end end

View File

@ -17,19 +17,19 @@ 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" }
function bandersnatch:action(msg) function bandersnatch:action(msg)
local message local output
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
bindings.sendReply(self, msg, message) bindings.sendReply(self, msg, output)
end 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 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) 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 end
if not message or res ~= 200 or message:len() == 0 then if not output or res ~= 200 or output:len() == 0 then
message = self.config.errors.results output = self.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
bindings.sendReply(self, msg, message) bindings.sendReply(self, msg, output)
end end

View File

@ -63,10 +63,10 @@ function chatter:action(msg)
bindings.sendMessage(self, msg.chat.id, self.config.errors.chatter_response) bindings.sendMessage(self, msg.chat.id, self.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 = self.config.errors.chatter_response output = self.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.
@ -78,14 +78,14 @@ function chatter:action(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
bindings.sendMessage(self, msg.chat.id, message) bindings.sendMessage(self, msg.chat.id, output)
end end

View File

@ -423,7 +423,8 @@ local commits = {
function commit:action(msg) 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 end

View File

@ -52,8 +52,7 @@ function currency:action(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 .. '`'
bindings.sendMessage(self, msg.chat.id, output, true, nil, true) bindings.sendMessage(self, msg.chat.id, output, true, nil, true)

View File

@ -22,9 +22,9 @@ function echo:action(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"' .. utilities.md_escape(input) .. '"'
else else
output = utilities.latcyr(input) output = utilities.md_escape(utilities.latcyr(input))
end end
bindings.sendMessage(self, msg.chat.id, output, true) bindings.sendMessage(self, msg.chat.id, output, true)
end end

View File

@ -43,15 +43,15 @@ local yesno_answers = {
function eightball:action(msg) function eightball:action(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
bindings.sendReply(self, msg, message) bindings.sendReply(self, msg, output)
end end

View File

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

View File

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

View File

@ -43,10 +43,10 @@ function imdb:action(msg)
return return
end end
local output = '[' .. jdat.Title .. '](http://imdb.com/title/' local output = '*' .. jdat.Title .. ' ('.. 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 .. '_\n'
output = output .. '[*Read more*](http://imdb.com/title/' .. jdat.imdbID .. ')'
bindings.sendMessage(self, msg.chat.id, output, true, nil, true) 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 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 username
local output = '' local alert = ''
if input then if input then
username = input username = input
elseif self.database.users[msg.from.id_str].lastfm then elseif self.database.users[msg.from.id_str].lastfm then
username = self.database.users[msg.from.id_str].lastfm username = self.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>.'
self.database.users[msg.from.id_str].lastfm = username self.database.users[msg.from.id_str].lastfm = username
else else
bindings.sendReply(self, msg, 'Please specify your last.fm username or set it with /fmset.') 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 jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
if not jdat then 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 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'
@ -101,8 +101,8 @@ function lastfm:action(msg)
artist = jdat.artist['#text'] artist = jdat.artist['#text']
end end
message = message .. title .. ' - ' .. artist .. output output = output .. title .. ' - ' .. artist .. alert
bindings.sendMessage(self, msg.chat.id, message) bindings.sendMessage(self, msg.chat.id, output)
end end

View File

@ -34,10 +34,10 @@ function librefm:action(msg)
if not input then if not input then
bindings.sendMessage(self, msg.chat.id, librefm.doc, true, msg.message_id, true) bindings.sendMessage(self, msg.chat.id, librefm.doc, true, msg.message_id, true)
elseif input == '-' then 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.') bindings.sendReply(self, msg, 'Your libre.fm username has been forgotten.')
else 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 .. '".') bindings.sendReply(self, msg, 'Your libre.fm username has been set to "' .. input .. '".')
end end
return 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 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 self.database.lastfm[msg.from.id_str] then elseif self.database.librefm[msg.from.id_str] then
username = self.database.lastfm[msg.from.id_str] username = self.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>.'
self.database.lastfm[msg.from.id_str] = username self.database.librefm[msg.from.id_str] = username
else else
bindings.sendReply(self, msg, 'Please specify your libre.fm username or set it with /lfmset.') bindings.sendReply(self, msg, 'Please specify your libre.fm username or set it with /lfmset.')
return return
@ -76,17 +76,17 @@ function librefm:action(msg)
jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track
if not jdat then 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 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'
@ -95,8 +95,8 @@ function librefm:action(msg)
artist = jdat.artist['#text'] artist = jdat.artist['#text']
end end
message = message .. title .. ' - ' .. artist .. output output = output .. title .. ' - ' .. artist .. alert
bindings.sendMessage(self, msg.chat.id, message) bindings.sendMessage(self, msg.chat.id, output)
end end

View File

@ -10,7 +10,8 @@ function ping:init()
end end
function ping:action(msg) 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 end
return ping return ping

View File

@ -76,8 +76,8 @@ function remind:cron()
-- 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"' .. utilities.md_escape(reminder.message) .. '"'
local res = bindings.sendMessage(self, chat_id, output, true) local res = bindings.sendMessage(self, 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 not res then if not res then
table.insert(new_group, reminder) table.insert(new_group, reminder)

View File

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

View File

@ -43,7 +43,7 @@ function translate:action(msg)
end end
local output = jdat.text[1] 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) 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 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 .. '.`'
bindings.sendReply(self, msg, message) bindings.sendReply(self, msg, output)
end end