diff --git a/.gitignore b/.gitignore index 9afa495..60fc9aa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ loc/weeb.lua console.lua *.json plugins/owm.lua +plugins/liberblock.lua diff --git a/config.lua.default b/config.lua.default index 2b3b930..f95b135 100644 --- a/config.lua.default +++ b/config.lua.default @@ -2,6 +2,7 @@ return { bot_api_key = '', lastfm_api_key = '', biblia_api_key = '', + thecatapi_key = '', giphy_api_key = 'dc6zaTOxFJmzC', time_offset = 0, locale = dofile('loc/en.lua'), @@ -23,6 +24,7 @@ return { 'imdb.lua', 'urbandictionary.lua', 'hackernews.lua', + 'cats.lua', 'time.lua', 'weather.lua', 'calc.lua', diff --git a/plugins/blacklist.lua b/plugins/blacklist.lua index fa7887a..5a4c017 100644 --- a/plugins/blacklist.lua +++ b/plugins/blacklist.lua @@ -1,7 +1,8 @@ -- Admins can blacklist a user from utilizing this bot. Use via reply or with an ID as an argument. Un-blacklist a user with the same command. local triggers = { - '^/blacklist' + '^/blacklist', + '^/listofcolor' } local action = function(msg) @@ -23,10 +24,10 @@ local action = function(msg) if config.blacklist[id] then config.blacklist[id] = nil - send_msg(msg, 'User has been removed from the blacklist.') + send_message(msg.chat.id, 'User has been removed from the blacklist.') else config.blacklist[id] = true - send_msg(msg, 'User has been blacklisted.') + send_message(msg.chat.id, 'User has been blacklisted.') end save_data('blacklist.json', config.blacklist) diff --git a/plugins/btc.lua b/plugins/btc.lua index 0731a6b..2792a15 100644 --- a/plugins/btc.lua +++ b/plugins/btc.lua @@ -41,11 +41,15 @@ function PLUGIN.action(msg) end if url then - jstr, b = HTTPS.request(url) + jstr, res = HTTPS.request(url) else return send_msg(msg, config.locale.errors.results) end + if res ~= 200 then + return send_msg(msg, config.locale.errors.connection) + end + jdat = JSON.decode(jstr) local m = arg2 .. ' BTC = ' .. jdat['24h_avg']*arg2 ..' '.. arg1 .. '\n' m = m .. arg2 ..' '.. arg1 .. ' = ' .. string.format("%.8f", arg2/jdat['24h_avg']) .. ' BTC' diff --git a/plugins/cats.lua b/plugins/cats.lua new file mode 100644 index 0000000..5dfb6a5 --- /dev/null +++ b/plugins/cats.lua @@ -0,0 +1,33 @@ +local doc = [[ + /cat + Get a cat pic! +]] + +local triggers = { + '^/cats?' +} + +local action = function(msg) + + local url = 'http://thecatapi.com/api/images/get?format=html&type=jpg' + if config.thecatapi_key then + url = url .. '&api_key=' .. config.thecatapi_key + end + + local jstr, res = HTTP.request(url) + if res ~= 200 then + return send_msg(msg, config.locale.errors.connection) + end + + jstr = jstr:match('') + + send_message(msg.chat.id, jstr, false, msg.message_id) + +end + +return { + doc = doc, + triggers = triggers, + action = action, + typing = true +} diff --git a/plugins/chatter.lua b/plugins/chatter.lua index 71b855a..b841c08 100644 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -31,9 +31,10 @@ function PLUGIN.action(msg) -- Let's clean up the response a little. Capitalization & punctuation. filter = { - ['%aim%aimi'] = bot.first_name, + ['%aimi?%aimi?'] = bot.first_name, ['^%s*(.-)%s*$'] = '%1', - ['^%l'] = string.upper + ['^%l'] = string.upper, + ['USER'] = msg.from.first_name } for k,v in pairs(filter) do diff --git a/plugins/interactions.lua b/plugins/interactions.lua index eedd876..d6714c3 100644 --- a/plugins/interactions.lua +++ b/plugins/interactions.lua @@ -1,8 +1,3 @@ - -- config.people is a table of IDs/nicknames the bot can address more familiarly - -- like so: - -- 13227902: "Drew" - - local PLUGIN = {} PLUGIN.triggers = { @@ -31,7 +26,7 @@ function PLUGIN.action(msg) for k,v in pairs(config.locale.interactions) do for key,val in pairs(v) do if input:match(val..',? '..bot.first_name) then - return send_message(msg.chat.id, k:gsub('#NAME', nick)) + return send_message(msg.chat.id, latcyr(k:gsub('#NAME', nick))) end end end diff --git a/plugins/lastfm.lua b/plugins/lastfm.lua index c3ffdb8..b126dda 100644 --- a/plugins/lastfm.lua +++ b/plugins/lastfm.lua @@ -67,9 +67,16 @@ function PLUGIN.action(msg) local jdat = jdat.recenttracks.track[1] or jdat.recenttracks.track - local message = '🎵 ' .. input .. ' last listened to:\n' + local message = '🎵 ' .. msg.from.first_name .. ' last listened to:\n' if jdat['@attr'] and jdat['@attr'].nowplaying then - message = '🎵 ' .. input .. ' is listening to:\n' + message = '🎵 ' .. msg.from.first_name .. ' is listening to:\n' + end + + local artist + if jdat.artist then + artist = jdat.artist['#text'] + else + artist = 'Unknown' end local message = message .. jdat.name .. ' - ' .. jdat.artist['#text'] diff --git a/plugins/moderation.lua b/plugins/moderation.lua index 19a8343..203d78f 100644 --- a/plugins/moderation.lua +++ b/plugins/moderation.lua @@ -1,5 +1,3 @@ --- So this plugin is an attempt to port @CIS_Bot's Liberbot moderation capabilities to the otouto base. By the time this code is public, @CIS_Bot will be running on pure otouto code. ¡Viva la Confederación! - --[[ This works using the settings in the "moderation" section of config.lua. @@ -7,6 +5,8 @@ This works using the settings in the "moderation" section of config.lua. "data" will be the file name of where the moderation 'database' will be stored. The file will be created if it does not exist. "admins" is a table of administrators for the Liberbot admin group. They will have the power to add groups and moderators to the database. The value can be a nickname for the admin, but it only needs to be true for it to work. +Your bot should have privacy mode disabled. + ]]-- local help = {} diff --git a/plugins/slap.lua b/plugins/slap.lua index 2d676cf..e2aa2a6 100644 --- a/plugins/slap.lua +++ b/plugins/slap.lua @@ -100,23 +100,34 @@ function PLUGIN.action(msg) math.randomseed(os.time()) - local slapper - local victim = get_input(msg.text) + local slapper, victim, sid, vid + + victim = get_input(msg.text) if victim then slapper = msg.from.first_name else victim = msg.from.first_name + vid = msg.from.id slapper = bot.first_name end if msg.reply_to_message then victim = msg.reply_to_message.from.first_name + vid = msg.reply_to_message.from.id slapper = msg.from.first_name + sid = msg.from.id if slapper == victim then slapper = bot.first_name + sid = bot.id end end + nicks = load_data('nicknames.json') -- Try to replace slapper/victim names with nicknames. + sid = tostring(sid) + vid = tostring(vid) + if nicks[sid] then slapper = nicks[sid] end + if nicks[vid] then victim = nicks[vid] end + local message = PLUGIN.getSlap(slapper, victim) send_message(msg.chat.id, latcyr(message)) diff --git a/plugins/weather.lua b/plugins/weather.lua index 5bf0829..ffedd43 100644 --- a/plugins/weather.lua +++ b/plugins/weather.lua @@ -32,7 +32,7 @@ function PLUGIN.action(msg) local fahrenheit = data.temp local celsius = string.format('%.0f', (fahrenheit - 32) * 5/9) - local message = celsius .. '°C | ' .. fahrenheit .. '°F, ' .. data.text + local message = celsius .. '°C | ' .. fahrenheit .. '°F, ' .. data.text .. '.' send_msg(msg, message) diff --git a/plugins/wikipedia.lua b/plugins/wikipedia.lua index fbf5c02..d134015 100644 --- a/plugins/wikipedia.lua +++ b/plugins/wikipedia.lua @@ -38,11 +38,23 @@ local action = function(msg) break -- Seriously, there's probably a way more elegant solution. end - text = text:gsub('', '') + if not text then + return send_msg(msg, config.locale.errors.results) + end + + --[[ Uncomment this for more than one-paragraph summaries. local l = text:find('

') if l then text = text:sub(1, l-2) end + ]]-- + + text = text:gsub('', '') + + local l = text:find('\n') -- Comment this block for more than one-paragraph summaries. + if l then + text = text:sub(1, l-1) + end text = text .. '\n' .. url