added cats!

minor fixes to a bunch of stuff
This commit is contained in:
topkecleon 2015-08-23 02:46:34 -04:00
parent 2e31f2f604
commit 2e01ceec71
12 changed files with 87 additions and 20 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ loc/weeb.lua
console.lua
*.json
plugins/owm.lua
plugins/liberblock.lua

View File

@ -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',

View File

@ -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)

View File

@ -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'

33
plugins/cats.lua Normal file
View File

@ -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('<img src="(.*)">')
send_message(msg.chat.id, jstr, false, msg.message_id)
end
return {
doc = doc,
triggers = triggers,
action = action,
typing = true
}

View File

@ -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

View File

@ -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

View File

@ -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']

View File

@ -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 = {}

View File

@ -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))

View File

@ -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)

View File

@ -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('<h2>')
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