added cron jobs for plugins

added example plugin with documentation
added liberbot-compliant flood control
	see Liberbot Support for details on getting compliant
added Kickass Torrent plugin
various bugfixes
all files seem to have been marked changed due to a shift in platform
	I will do a clean clone and testing to ensure there is no issue.
This commit is contained in:
topkecleon
2015-08-28 23:15:01 -07:00
parent 2e01ceec71
commit 60570e90f3
54 changed files with 281 additions and 66 deletions

0
plugins/8ball.lua Normal file → Executable file
View File

0
plugins/about.lua Normal file → Executable file
View File

0
plugins/admin.lua Normal file → Executable file
View File

0
plugins/bandersnatch.lua Normal file → Executable file
View File

0
plugins/bible.lua Normal file → Executable file
View File

15
plugins/blacklist.lua Normal file → Executable file
View File

@ -11,26 +11,29 @@ local action = function(msg)
return send_msg(msg, 'Permission denied.')
end
local name
local input = get_input(msg.text)
if not input then
if msg.reply_to_message then
input = msg.reply_to_message.from.id
name = msg.reply_to_message.from.first_name
else
return send_msg(msg, 'Must be used via reply or by specifying a user\'s ID.')
end
end
local id = tostring(input)
if not name then name = id end
if config.blacklist[id] then
config.blacklist[id] = nil
send_message(msg.chat.id, 'User has been removed from the blacklist.')
if blacklist[id] then
blacklist[id] = nil
send_message(msg.chat.id, name .. ' has been removed from the blacklist.')
else
config.blacklist[id] = true
send_message(msg.chat.id, 'User has been blacklisted.')
blacklist[id] = true
send_message(msg.chat.id, name .. ' has been blacklisted.')
end
save_data('blacklist.json', config.blacklist)
save_data('blacklist.json', blacklist)
end

0
plugins/btc.lua Normal file → Executable file
View File

0
plugins/calc.lua Normal file → Executable file
View File

0
plugins/cats.lua Normal file → Executable file
View File

0
plugins/chatter.lua Normal file → Executable file
View File

0
plugins/commit.lua Normal file → Executable file
View File

0
plugins/currency.lua Normal file → Executable file
View File

0
plugins/dice.lua Normal file → Executable file
View File

0
plugins/dogify.lua Normal file → Executable file
View File

0
plugins/echo.lua Normal file → Executable file
View File

46
plugins/floodcontrol.lua Executable file
View File

@ -0,0 +1,46 @@
floodcontrol = {}
local triggers = {
'/floodcontrol'
}
local action = function(msg)
local input, output
if msg.from.id ~= 100547061 then -- Only acknowledge Liberbot.
if not config.admins[msg.from.id] then -- or an admin. :)
return
end
end
input = get_input(msg.text) -- Remove the first word from the input.
input = JSON.decode(input) -- Parse the JSON into a table.
if not input.groupid then return end -- If no group is specified, end.
if not input.duration then -- If no duration is specified, set it to 5min.
input.duration = 600
end
floodcontrol[input.groupid] = os.time() + input.duration
local s = input.groupid .. ' silenced for ' .. input.duration .. ' seconds.'
send_message(-34496439, s)
end
local cron = function()
for k,v in pairs(floodcontrol) do
if os.time() > v then
floodcontrol[k] = nil
end
end
end
return {
triggers = triggers,
action = action,
cron = cron
}

0
plugins/fortune.lua Normal file → Executable file
View File

0
plugins/gImages.lua Normal file → Executable file
View File

0
plugins/gMaps.lua Normal file → Executable file
View File

0
plugins/gSearch.lua Normal file → Executable file
View File

3
plugins/giphy.lua Normal file → Executable file
View File

@ -43,6 +43,9 @@ function PLUGIN.action(msg)
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
if #jdat.data == 0 then
return send_msg(msg, config.locale.errors.results)
end
result_url = jdat.data[math.random(#jdat.data)].images.original.url
end

0
plugins/hackernews.lua Normal file → Executable file
View File

0
plugins/help.lua Normal file → Executable file
View File

0
plugins/hex.lua Normal file → Executable file
View File

0
plugins/imdb.lua Normal file → Executable file
View File

0
plugins/interactions.lua Normal file → Executable file
View File

69
plugins/kickass.lua Executable file
View File

@ -0,0 +1,69 @@
-- Kickass Torrents
-- Based on @Imandaneshi's torrent.lua
-- https://github.com/Imandaneshi/Jack/blob/master/plugins/torrent.lua
local doc = [[
/torrent <query>
Search Kickass Torrents. Results may be NSFW.
]]
local triggers = {
'^/torrent',
'^/kickass'
}
local action = function(msg)
local url = 'http://kat.cr/json.php?q='
local input = get_input(msg.text)
if not input then
return send_msg(msg, doc)
end
local jstr, res = HTTP.request(url..URL.escape(input))
if res ~= 200 then
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
if #jdat.total_results == 0 then
return send_msg(msg, config.locale.errors.results)
end
local limit = 4 -- If the request is made in a PM, send 8 results instead of 4.
if msg.chat.id == msg.from.id then
limit = 8
end
if #jdat.total_results < limit then -- If there are not that many results, do as many as possible.
limit = #jdat.total_results
end
for i,v in ipairs(jdat.list) do -- Remove any entries that have zero seeds.
if v.seeds == 0 then
table.remove(jdat.list, i)
end
end
if #jdat.list == 0 then
return send_msg(msg, config.locale.errors.results)
end
local message = ''
for i = 1, limit do
local torrenturl = jdat.list[i].torrentLink:sub(1, jdat.list[i].torrentLink:find('?')-1) -- Clean up the torrent link.
message = message .. jdat.list[i].title .. '\n' .. jdat.list[i].category .. ' | ' .. string.format('%.3f', jdat.list[i].size/1000000) .. 'MB | ' .. jdat.list[i].seeds .. 'S/' .. jdat.list[i].peers .. 'L\n' .. torrenturl .. '\n\n'
end
message = message:gsub('&amp;', '&')
send_msg(msg, message)
end
return {
doc = doc,
triggers = triggers,
action = action,
typing = true
}

3
plugins/lastfm.lua Normal file → Executable file
View File

@ -72,6 +72,7 @@ function PLUGIN.action(msg)
message = '🎵 ' .. msg.from.first_name .. ' is listening to:\n'
end
local name = jdat.name or 'Unknown'
local artist
if jdat.artist then
artist = jdat.artist['#text']
@ -79,7 +80,7 @@ function PLUGIN.action(msg)
artist = 'Unknown'
end
local message = message .. jdat.name .. ' - ' .. jdat.artist['#text']
local message = message .. name .. ' - ' .. artist
send_message(msg.chat.id, message)

0
plugins/lmgtfy.lua Normal file → Executable file
View File

26
plugins/moderation.lua Normal file → Executable file
View File

@ -15,7 +15,7 @@ help.trigger = '^/modhelp'
help.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
local do_send = false
if data[tostring(msg.chat.id)] and data[tostring(msg.chat.id)][tostring(msg.from.id)] then do_send = true end
@ -47,7 +47,7 @@ ban.trigger = '^/modban'
ban.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not data[tostring(msg.chat.id)] then return end
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
@ -84,7 +84,7 @@ kick.trigger = '^/modkick'
kick.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not data[tostring(msg.chat.id)] then return end
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
@ -121,7 +121,7 @@ add.trigger = '^/[mod]*add$'
add.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not config.moderation.admins[tostring(msg.from.id)] then return end
@ -130,7 +130,7 @@ add.action = function(msg)
end
data[tostring(msg.chat.id)] = {}
save_data(config.moderation.data, data)
save_data('moderation.json', data)
send_message(msg.chat.id, 'Group has been added.')
@ -143,7 +143,7 @@ rem.trigger = '^/[mod]*rem[ove]*$'
rem.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not config.moderation.admins[tostring(msg.from.id)] then return end
@ -152,7 +152,7 @@ rem.action = function(msg)
end
data[tostring(msg.chat.id)] = nil
save_data(config.moderation.data, data)
save_data('moderation.json', data)
send_message(msg.chat.id, 'Group has been removed.')
@ -165,7 +165,7 @@ promote.trigger = '^/[mod]*prom[ote]*$'
promote.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
local chatid = tostring(msg.chat.id)
if not config.moderation.admins[tostring(msg.from.id)] then return end
@ -193,7 +193,7 @@ promote.action = function(msg)
end
data[chatid][targid] = msg.reply_to_message.from.first_name
save_data(config.moderation.data, data)
save_data('moderation.json', data)
send_message(msg.chat.id, msg.reply_to_message.from.first_name..' has been promoted.')
@ -206,7 +206,7 @@ demote.trigger = '^/[mod]*dem[ote]*'
demote.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not config.moderation.admins[tostring(msg.from.id)] then return end
@ -228,7 +228,7 @@ demote.action = function(msg)
end
data[tostring(msg.chat.id)][tostring(input)] = nil
save_data(config.moderation.data, data)
save_data('moderation.json', data)
send_message(msg.chat.id, input..' has been demoted.')
@ -241,7 +241,7 @@ broadcast.trigger = '^/modcast'
broadcast.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not config.moderation.admins[tostring(msg.from.id)] then return end
@ -268,7 +268,7 @@ modlist.trigger = '^/modlist'
modlist.action = function(msg)
local data = load_data(config.moderation.data)
local data = load_data('moderation.json')
if not data[tostring(msg.chat.id)] then
return send_message(msg.chat.id, 'Group is not added.')

15
plugins/nick.lua Normal file → Executable file
View File

@ -1,6 +1,7 @@
local doc = [[
/nick <nickname>
Set your nickname for the bot to call you.
Use -- to clear your nickname.
]]
local triggers = {
@ -13,9 +14,21 @@ local action = function(msg)
local id = tostring(msg.from.id)
local input = get_input(msg.text)
if not input then
return send_msg(msg, doc)
local message = ''
if data[id] then
message = '\nYour nickname is currently ' .. data[id] .. '.'
end
return send_msg(msg, doc..message)
end
if input == '--' then
data[id] = nil
save_data('nicknames.json', data)
send_msg(msg, 'Your nickname has been deleted.')
return
end
input = input:sub(1,64):gsub('\n',' ')
data[id] = input
save_data('nicknames.json', data)
send_msg(msg, 'Your nickname has been set to ' .. input .. '.')

0
plugins/pokedex.lua Normal file → Executable file
View File

0
plugins/pun.lua Normal file → Executable file
View File

0
plugins/reaction.lua Normal file → Executable file
View File

0
plugins/reddit.lua Normal file → Executable file
View File

39
plugins/remind.lua Normal file → Executable file
View File

@ -1,20 +1,20 @@
local PLUGIN = {}
reminders = load_data('reminders.json')
PLUGIN.doc = [[
local doc = [[
/remind <delay> <message>
Set a reminder for yourself. First argument is the number of minutes until you wish to be reminded.
]]
PLUGIN.triggers = {
local triggers = {
'^/remind$',
'^/remind '
}
function PLUGIN.action(msg)
local action = function(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
return send_msg(msg, doc)
end
local delay = first_word(input)
@ -39,6 +39,7 @@ function PLUGIN.action(msg)
}
table.insert(reminders, reminder)
save_data('reminders.json', reminders)
if delay <= 1 then
delay = (delay * 60) .. ' seconds'
@ -52,4 +53,30 @@ function PLUGIN.action(msg)
end
return PLUGIN
local cron = function()
reminders = load_data('reminders.json')
for k,v in pairs(reminders) do
if os.time() > v.alarm then
local a = send_message(v.chat_id, 'Reminder: '..v.text)
if a then
reminders[k] = nil
save_data('reminders.json', reminders)
end
end
-- If the bot is no longer in the chat, he won't be able to send reminders.
-- To prevent abuse, check for old reminders and remove them.
if v.alarm < os.time() + 3600 then
reminders[k] = nil
save_data('reminders.json', reminders)
end
end
end
return {
doc = doc,
triggers = triggers,
action = action,
cron = cron
}

0
plugins/slap.lua Normal file → Executable file
View File

0
plugins/time.lua Normal file → Executable file
View File

0
plugins/translate.lua Normal file → Executable file
View File

0
plugins/urbandictionary.lua Normal file → Executable file
View File

0
plugins/weather.lua Normal file → Executable file
View File

8
plugins/whoami.lua Normal file → Executable file
View File

@ -23,6 +23,12 @@ function PLUGIN.action(msg)
msg = msg.reply_to_message
end
local nicknames = load_data('nicknames.json')
local message = ''
if nicknames[tostring(msg.from.id)] then
message = 'Hi, ' .. nicknames[tostring(msg.from.id)] .. '!\n'
end
local from_name = msg.from.first_name
if msg.from.last_name then
from_name = from_name .. ' ' .. msg.from.last_name
@ -32,7 +38,7 @@ function PLUGIN.action(msg)
end
from_name = from_name .. ' (' .. msg.from.id .. ')'
local message = 'You are ' .. from_name .. ' and you are messaging ' .. to_name .. '.'
local message = message .. 'You are ' .. from_name .. ' and you are messaging ' .. to_name .. '.'
send_msg(msg, message)

0
plugins/wikipedia.lua Normal file → Executable file
View File

9
plugins/xkcd.lua Normal file → Executable file
View File

@ -18,6 +18,7 @@ function PLUGIN.action(msg)
return send_msg(msg, config.locale.errors.connection)
end
local latest = JSON.decode(jstr).num
local jdat
if input then
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=active&q=site%3axkcd%2ecom%20' .. URL.escape(input)
@ -26,7 +27,11 @@ function PLUGIN.action(msg)
print('here')
return send_msg(msg, config.locale.errors.connection)
end
url = JSON.decode(jstr).responseData.results[1].url .. 'info.0.json'
jdat = JSON.decode(jstr)
if #jdat.responseData.results == 0 then
return send_msg(msg, config.locale.errors.results)
end
url = jdat.responseData.results[1].url .. 'info.0.json'
else
math.randomseed(os.time())
url = 'http://xkcd.com/' .. math.random(latest) .. '/info.0.json'
@ -36,7 +41,7 @@ function PLUGIN.action(msg)
if res ~= 200 then
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
jdat = JSON.decode(jstr)
local message = '[' .. jdat.num .. '] ' .. jdat.alt .. '\n' .. jdat.img