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:
parent
2e01ceec71
commit
60570e90f3
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
2
bindings.lua
Normal file → Executable file
2
bindings.lua
Normal file → Executable file
@ -11,7 +11,7 @@ local function send_request(url)
|
|||||||
local tab = JSON.decode(dat)
|
local tab = JSON.decode(dat)
|
||||||
|
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
print('Connection error.')
|
print('','Connection error.\n',url)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
60
bot.lua
Normal file → Executable file
60
bot.lua
Normal file → Executable file
@ -1,16 +1,14 @@
|
|||||||
-- bot.lua
|
|
||||||
-- Run this!
|
|
||||||
|
|
||||||
HTTP = require('socket.http')
|
HTTP = require('socket.http')
|
||||||
HTTPS = require('ssl.https')
|
HTTPS= require('ssl.https')
|
||||||
URL = require('socket.url')
|
URL = require('socket.url')
|
||||||
JSON = require('dkjson')
|
JSON = require('dkjson')
|
||||||
|
|
||||||
VERSION = 2.8
|
VERSION = 2.9
|
||||||
|
|
||||||
function on_msg_receive(msg)
|
function on_msg_receive(msg)
|
||||||
|
|
||||||
if config.blacklist[tostring(msg.from.id)] then return end
|
if blacklist[tostring(msg.from.id)] then return end
|
||||||
|
if floodcontrol[-msg.chat.id] then return end
|
||||||
|
|
||||||
msg = process_msg(msg)
|
msg = process_msg(msg)
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ function on_msg_receive(msg)
|
|||||||
v.action(msg)
|
v.action(msg)
|
||||||
end)
|
end)
|
||||||
if not a then
|
if not a then
|
||||||
print(b)
|
print('',msg.text,'\n',b) -- For debugging purposes.
|
||||||
send_msg(msg, b)
|
send_msg(msg, b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,53 +36,40 @@ function on_msg_receive(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function bot_init()
|
function bot_init()
|
||||||
require('utilities')
|
|
||||||
|
|
||||||
print('\nLoading configuration...')
|
print('Loading configuration...')
|
||||||
|
|
||||||
config = dofile('config.lua')
|
config = dofile('config.lua')
|
||||||
|
|
||||||
print(#config.plugins .. ' plugins enabled.')
|
|
||||||
|
|
||||||
require('bindings')
|
require('bindings')
|
||||||
|
require('utilities')
|
||||||
|
blacklist = load_data('blacklist.json')
|
||||||
|
|
||||||
print('\nFetching bot information...')
|
print('Fetching bot information...')
|
||||||
|
|
||||||
bot = get_me().result
|
bot = get_me().result
|
||||||
if not bot then
|
if not bot then
|
||||||
error('Failure fetching bot information.')
|
error('Failure fetching bot information.')
|
||||||
end
|
end
|
||||||
for k,v in pairs(bot) do
|
|
||||||
print('',k,v)
|
|
||||||
end
|
|
||||||
|
|
||||||
print('Bot information retrieved!\n')
|
|
||||||
print('Loading plugins...')
|
print('Loading plugins...')
|
||||||
|
|
||||||
plugins = {}
|
plugins = {}
|
||||||
for i,v in ipairs(config.plugins) do
|
for i,v in ipairs(config.plugins) do
|
||||||
print('',v)
|
|
||||||
local p = dofile('plugins/'..v)
|
local p = dofile('plugins/'..v)
|
||||||
table.insert(plugins, p)
|
table.insert(plugins, p)
|
||||||
end
|
end
|
||||||
|
|
||||||
print('Done! Plugins loaded: ' .. #plugins .. '\n')
|
print('Plugins loaded: ' .. #plugins .. '. Generating help message...')
|
||||||
print('Generating help message...')
|
|
||||||
|
|
||||||
help_message = ''
|
help_message = ''
|
||||||
for i,v in ipairs(plugins) do
|
for i,v in ipairs(plugins) do
|
||||||
if v.doc then
|
if v.doc then
|
||||||
local a = string.sub(v.doc, 1, string.find(v.doc, '\n')-1)
|
local a = string.sub(v.doc, 1, string.find(v.doc, '\n')-1)
|
||||||
print(a)
|
|
||||||
help_message = help_message .. ' - ' .. a .. '\n'
|
help_message = help_message .. ' - ' .. a .. '\n'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print('Help message generated!\n')
|
print('@'.. bot.username ..', AKA '.. bot.first_name ..' ('.. bot.id ..')')
|
||||||
|
|
||||||
print('username: @'..bot.username)
|
|
||||||
print('name: '..bot.first_name)
|
|
||||||
print('ID: '..bot.id)
|
|
||||||
|
|
||||||
is_started = true
|
is_started = true
|
||||||
|
|
||||||
@ -92,12 +77,18 @@ end
|
|||||||
|
|
||||||
function process_msg(msg)
|
function process_msg(msg)
|
||||||
|
|
||||||
|
if msg.text and msg.reply_to_message and string.sub(msg.text, 1, 1) ~= '/' and msg.reply_to_message.from.id == bot.id then
|
||||||
|
msg.text = bot.first_name .. ', ' .. msg.text
|
||||||
|
end
|
||||||
|
|
||||||
if msg.new_chat_participant and msg.new_chat_participant.id ~= bot.id then
|
if msg.new_chat_participant and msg.new_chat_participant.id ~= bot.id then
|
||||||
|
if msg.from.id == 100547061 then return msg end
|
||||||
msg.text = 'hi '..bot.first_name
|
msg.text = 'hi '..bot.first_name
|
||||||
msg.from = msg.new_chat_participant
|
msg.from = msg.new_chat_participant
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.left_chat_participant and msg.left_chat_participant.id ~= bot.id then
|
if msg.left_chat_participant and msg.left_chat_participant.id ~= bot.id then
|
||||||
|
if msg.from.id == 100547061 then return msg end
|
||||||
msg.text = 'bye '..bot.first_name
|
msg.text = 'bye '..bot.first_name
|
||||||
msg.from = msg.left_chat_participant
|
msg.from = msg.left_chat_participant
|
||||||
end
|
end
|
||||||
@ -111,8 +102,8 @@ function process_msg(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
bot_init()
|
bot_init()
|
||||||
reminders = {}
|
|
||||||
last_update = 0
|
last_update = 0
|
||||||
|
|
||||||
while is_started do
|
while is_started do
|
||||||
|
|
||||||
local res = get_updates(last_update+1)
|
local res = get_updates(last_update+1)
|
||||||
@ -127,13 +118,16 @@ while is_started do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,v in pairs(reminders) do
|
-- cron-like thing
|
||||||
if os.time() > v.alarm then
|
-- run PLUGIN.cron() every five seconds
|
||||||
local a = send_message(v.chat_id, 'Reminder: '..v.text)
|
if os.date('%S', os.time()) % 5 == 0 then -- Only check every five seconds.
|
||||||
if a then
|
for k,v in pairs(plugins) do
|
||||||
table.remove(reminders, i)
|
if v.cron then
|
||||||
|
pcall(function() v.cron() end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print('Halted.')
|
print('Halted.')
|
||||||
|
5
config.lua.default
Normal file → Executable file
5
config.lua.default
Normal file → Executable file
@ -23,6 +23,7 @@ return {
|
|||||||
'wikipedia.lua',
|
'wikipedia.lua',
|
||||||
'imdb.lua',
|
'imdb.lua',
|
||||||
'urbandictionary.lua',
|
'urbandictionary.lua',
|
||||||
|
'kickass.lua',
|
||||||
'hackernews.lua',
|
'hackernews.lua',
|
||||||
'cats.lua',
|
'cats.lua',
|
||||||
'time.lua',
|
'time.lua',
|
||||||
@ -48,12 +49,12 @@ return {
|
|||||||
'translate.lua',
|
'translate.lua',
|
||||||
'currency.lua',
|
'currency.lua',
|
||||||
'blacklist.lua',
|
'blacklist.lua',
|
||||||
'nick.lua'
|
'nick.lua',
|
||||||
|
'floodcontrol.lua'
|
||||||
},
|
},
|
||||||
moderation = {
|
moderation = {
|
||||||
realm = -000,
|
realm = -000,
|
||||||
realmname = 'Realm name or ident',
|
realmname = 'Realm name or ident',
|
||||||
data = 'moderation.json',
|
|
||||||
admins = {
|
admins = {
|
||||||
['000'] = 'nickname',
|
['000'] = 'nickname',
|
||||||
}
|
}
|
||||||
|
0
dkjson.lua
Normal file → Executable file
0
dkjson.lua
Normal file → Executable file
47
example-plugin.lua
Executable file
47
example-plugin.lua
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
local doc = [[
|
||||||
|
/example <required> [optional]
|
||||||
|
Info about the plugin goes here.
|
||||||
|
]]
|
||||||
|
|
||||||
|
local triggers = {
|
||||||
|
'^/example',
|
||||||
|
'^/e '
|
||||||
|
}
|
||||||
|
|
||||||
|
local action = function(msg) do
|
||||||
|
|
||||||
|
-- do stuff
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local cron = function() do
|
||||||
|
|
||||||
|
-- do stuff
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
doc = doc,
|
||||||
|
triggers = triggers,
|
||||||
|
action = action,
|
||||||
|
cron = cron,
|
||||||
|
typing = true
|
||||||
|
}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
|
||||||
|
Here's an example plugin.
|
||||||
|
|
||||||
|
"doc" is a string. It contains info on the plugin's usage.
|
||||||
|
The first line should be only the command and its expected arguments. Arguments should be encased in <> if they are required, and [] if they are optional.
|
||||||
|
The entire thing is sent as a message when "/help example" is used.
|
||||||
|
|
||||||
|
"triggers" is a table of triggers. A trigger is a string that should pattern-match the desired input.
|
||||||
|
|
||||||
|
"action" is the main function. It's what the plugin does. It takes a single argument, msg, which is a table of the contents of a message.
|
||||||
|
|
||||||
|
"cron" is another function. It is run every five seconds without regard to triggers or messages.
|
||||||
|
|
||||||
|
"typing" is a boolean. Set it to true if you want the bot to send a typing notification when the plugin is triggered.
|
||||||
|
|
||||||
|
]]--
|
0
loc/en.lua
Normal file → Executable file
0
loc/en.lua
Normal file → Executable file
0
plugins/8ball.lua
Normal file → Executable file
0
plugins/8ball.lua
Normal file → Executable file
0
plugins/about.lua
Normal file → Executable file
0
plugins/about.lua
Normal file → Executable file
0
plugins/admin.lua
Normal file → Executable file
0
plugins/admin.lua
Normal file → Executable file
0
plugins/bandersnatch.lua
Normal file → Executable file
0
plugins/bandersnatch.lua
Normal file → Executable file
0
plugins/bible.lua
Normal file → Executable file
0
plugins/bible.lua
Normal file → Executable file
15
plugins/blacklist.lua
Normal file → Executable file
15
plugins/blacklist.lua
Normal file → Executable file
@ -11,26 +11,29 @@ local action = function(msg)
|
|||||||
return send_msg(msg, 'Permission denied.')
|
return send_msg(msg, 'Permission denied.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local name
|
||||||
local input = get_input(msg.text)
|
local input = get_input(msg.text)
|
||||||
if not input then
|
if not input then
|
||||||
if msg.reply_to_message then
|
if msg.reply_to_message then
|
||||||
input = msg.reply_to_message.from.id
|
input = msg.reply_to_message.from.id
|
||||||
|
name = msg.reply_to_message.from.first_name
|
||||||
else
|
else
|
||||||
return send_msg(msg, 'Must be used via reply or by specifying a user\'s ID.')
|
return send_msg(msg, 'Must be used via reply or by specifying a user\'s ID.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local id = tostring(input)
|
local id = tostring(input)
|
||||||
|
if not name then name = id end
|
||||||
|
|
||||||
if config.blacklist[id] then
|
if blacklist[id] then
|
||||||
config.blacklist[id] = nil
|
blacklist[id] = nil
|
||||||
send_message(msg.chat.id, 'User has been removed from the blacklist.')
|
send_message(msg.chat.id, name .. ' has been removed from the blacklist.')
|
||||||
else
|
else
|
||||||
config.blacklist[id] = true
|
blacklist[id] = true
|
||||||
send_message(msg.chat.id, 'User has been blacklisted.')
|
send_message(msg.chat.id, name .. ' has been blacklisted.')
|
||||||
end
|
end
|
||||||
|
|
||||||
save_data('blacklist.json', config.blacklist)
|
save_data('blacklist.json', blacklist)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
0
plugins/btc.lua
Normal file → Executable file
0
plugins/btc.lua
Normal file → Executable file
0
plugins/calc.lua
Normal file → Executable file
0
plugins/calc.lua
Normal file → Executable file
0
plugins/cats.lua
Normal file → Executable file
0
plugins/cats.lua
Normal file → Executable file
0
plugins/chatter.lua
Normal file → Executable file
0
plugins/chatter.lua
Normal file → Executable file
0
plugins/commit.lua
Normal file → Executable file
0
plugins/commit.lua
Normal file → Executable file
0
plugins/currency.lua
Normal file → Executable file
0
plugins/currency.lua
Normal file → Executable file
0
plugins/dice.lua
Normal file → Executable file
0
plugins/dice.lua
Normal file → Executable file
0
plugins/dogify.lua
Normal file → Executable file
0
plugins/dogify.lua
Normal file → Executable file
0
plugins/echo.lua
Normal file → Executable file
0
plugins/echo.lua
Normal file → Executable file
46
plugins/floodcontrol.lua
Executable file
46
plugins/floodcontrol.lua
Executable 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
0
plugins/fortune.lua
Normal file → Executable file
0
plugins/gImages.lua
Normal file → Executable file
0
plugins/gImages.lua
Normal file → Executable file
0
plugins/gMaps.lua
Normal file → Executable file
0
plugins/gMaps.lua
Normal file → Executable file
0
plugins/gSearch.lua
Normal file → Executable file
0
plugins/gSearch.lua
Normal file → Executable file
3
plugins/giphy.lua
Normal file → Executable file
3
plugins/giphy.lua
Normal file → Executable file
@ -43,6 +43,9 @@ function PLUGIN.action(msg)
|
|||||||
return send_msg(msg, config.locale.errors.connection)
|
return send_msg(msg, config.locale.errors.connection)
|
||||||
end
|
end
|
||||||
local jdat = JSON.decode(jstr)
|
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
|
result_url = jdat.data[math.random(#jdat.data)].images.original.url
|
||||||
|
|
||||||
end
|
end
|
||||||
|
0
plugins/hackernews.lua
Normal file → Executable file
0
plugins/hackernews.lua
Normal file → Executable file
0
plugins/help.lua
Normal file → Executable file
0
plugins/help.lua
Normal file → Executable file
0
plugins/hex.lua
Normal file → Executable file
0
plugins/hex.lua
Normal file → Executable file
0
plugins/imdb.lua
Normal file → Executable file
0
plugins/imdb.lua
Normal file → Executable file
0
plugins/interactions.lua
Normal file → Executable file
0
plugins/interactions.lua
Normal file → Executable file
69
plugins/kickass.lua
Executable file
69
plugins/kickass.lua
Executable 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('&', '&')
|
||||||
|
|
||||||
|
send_msg(msg, message)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
doc = doc,
|
||||||
|
triggers = triggers,
|
||||||
|
action = action,
|
||||||
|
typing = true
|
||||||
|
}
|
3
plugins/lastfm.lua
Normal file → Executable file
3
plugins/lastfm.lua
Normal file → Executable file
@ -72,6 +72,7 @@ function PLUGIN.action(msg)
|
|||||||
message = '🎵 ' .. msg.from.first_name .. ' is listening to:\n'
|
message = '🎵 ' .. msg.from.first_name .. ' is listening to:\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local name = jdat.name or 'Unknown'
|
||||||
local artist
|
local artist
|
||||||
if jdat.artist then
|
if jdat.artist then
|
||||||
artist = jdat.artist['#text']
|
artist = jdat.artist['#text']
|
||||||
@ -79,7 +80,7 @@ function PLUGIN.action(msg)
|
|||||||
artist = 'Unknown'
|
artist = 'Unknown'
|
||||||
end
|
end
|
||||||
|
|
||||||
local message = message .. jdat.name .. ' - ' .. jdat.artist['#text']
|
local message = message .. name .. ' - ' .. artist
|
||||||
|
|
||||||
send_message(msg.chat.id, message)
|
send_message(msg.chat.id, message)
|
||||||
|
|
||||||
|
0
plugins/lmgtfy.lua
Normal file → Executable file
0
plugins/lmgtfy.lua
Normal file → Executable file
26
plugins/moderation.lua
Normal file → Executable file
26
plugins/moderation.lua
Normal file → Executable file
@ -15,7 +15,7 @@ help.trigger = '^/modhelp'
|
|||||||
|
|
||||||
help.action = function(msg)
|
help.action = function(msg)
|
||||||
|
|
||||||
local data = load_data(config.moderation.data)
|
local data = load_data('moderation.json')
|
||||||
|
|
||||||
local do_send = false
|
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
|
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)
|
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)] then return end
|
||||||
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
|
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
|
||||||
@ -84,7 +84,7 @@ kick.trigger = '^/modkick'
|
|||||||
|
|
||||||
kick.action = function(msg)
|
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)] then return end
|
||||||
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
|
if not data[tostring(msg.chat.id)][tostring(msg.from.id)] then
|
||||||
@ -121,7 +121,7 @@ add.trigger = '^/[mod]*add$'
|
|||||||
|
|
||||||
add.action = function(msg)
|
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
|
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ add.action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
data[tostring(msg.chat.id)] = {}
|
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.')
|
send_message(msg.chat.id, 'Group has been added.')
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ rem.trigger = '^/[mod]*rem[ove]*$'
|
|||||||
|
|
||||||
rem.action = function(msg)
|
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
|
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ rem.action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
data[tostring(msg.chat.id)] = nil
|
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.')
|
send_message(msg.chat.id, 'Group has been removed.')
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ promote.trigger = '^/[mod]*prom[ote]*$'
|
|||||||
|
|
||||||
promote.action = function(msg)
|
promote.action = function(msg)
|
||||||
|
|
||||||
local data = load_data(config.moderation.data)
|
local data = load_data('moderation.json')
|
||||||
local chatid = tostring(msg.chat.id)
|
local chatid = tostring(msg.chat.id)
|
||||||
|
|
||||||
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||||
@ -193,7 +193,7 @@ promote.action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
data[chatid][targid] = msg.reply_to_message.from.first_name
|
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.')
|
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)
|
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
|
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ demote.action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
data[tostring(msg.chat.id)][tostring(input)] = nil
|
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.')
|
send_message(msg.chat.id, input..' has been demoted.')
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ broadcast.trigger = '^/modcast'
|
|||||||
|
|
||||||
broadcast.action = function(msg)
|
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
|
if not config.moderation.admins[tostring(msg.from.id)] then return end
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ modlist.trigger = '^/modlist'
|
|||||||
|
|
||||||
modlist.action = function(msg)
|
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
|
if not data[tostring(msg.chat.id)] then
|
||||||
return send_message(msg.chat.id, 'Group is not added.')
|
return send_message(msg.chat.id, 'Group is not added.')
|
||||||
|
15
plugins/nick.lua
Normal file → Executable file
15
plugins/nick.lua
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
local doc = [[
|
local doc = [[
|
||||||
/nick <nickname>
|
/nick <nickname>
|
||||||
Set your nickname for the bot to call you.
|
Set your nickname for the bot to call you.
|
||||||
|
Use -- to clear your nickname.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local triggers = {
|
local triggers = {
|
||||||
@ -13,9 +14,21 @@ local action = function(msg)
|
|||||||
local id = tostring(msg.from.id)
|
local id = tostring(msg.from.id)
|
||||||
local input = get_input(msg.text)
|
local input = get_input(msg.text)
|
||||||
if not input then
|
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
|
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
|
data[id] = input
|
||||||
save_data('nicknames.json', data)
|
save_data('nicknames.json', data)
|
||||||
send_msg(msg, 'Your nickname has been set to ' .. input .. '.')
|
send_msg(msg, 'Your nickname has been set to ' .. input .. '.')
|
||||||
|
0
plugins/pokedex.lua
Normal file → Executable file
0
plugins/pokedex.lua
Normal file → Executable file
0
plugins/pun.lua
Normal file → Executable file
0
plugins/pun.lua
Normal file → Executable file
0
plugins/reaction.lua
Normal file → Executable file
0
plugins/reaction.lua
Normal file → Executable file
0
plugins/reddit.lua
Normal file → Executable file
0
plugins/reddit.lua
Normal file → Executable file
39
plugins/remind.lua
Normal file → Executable file
39
plugins/remind.lua
Normal file → Executable file
@ -1,20 +1,20 @@
|
|||||||
local PLUGIN = {}
|
reminders = load_data('reminders.json')
|
||||||
|
|
||||||
PLUGIN.doc = [[
|
local doc = [[
|
||||||
/remind <delay> <message>
|
/remind <delay> <message>
|
||||||
Set a reminder for yourself. First argument is the number of minutes until you wish to be reminded.
|
Set a reminder for yourself. First argument is the number of minutes until you wish to be reminded.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
PLUGIN.triggers = {
|
local triggers = {
|
||||||
'^/remind$',
|
'^/remind$',
|
||||||
'^/remind '
|
'^/remind '
|
||||||
}
|
}
|
||||||
|
|
||||||
function PLUGIN.action(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
local input = get_input(msg.text)
|
local input = get_input(msg.text)
|
||||||
if not input then
|
if not input then
|
||||||
return send_msg(msg, PLUGIN.doc)
|
return send_msg(msg, doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
local delay = first_word(input)
|
local delay = first_word(input)
|
||||||
@ -39,6 +39,7 @@ function PLUGIN.action(msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
table.insert(reminders, reminder)
|
table.insert(reminders, reminder)
|
||||||
|
save_data('reminders.json', reminders)
|
||||||
|
|
||||||
if delay <= 1 then
|
if delay <= 1 then
|
||||||
delay = (delay * 60) .. ' seconds'
|
delay = (delay * 60) .. ' seconds'
|
||||||
@ -52,4 +53,30 @@ function PLUGIN.action(msg)
|
|||||||
|
|
||||||
end
|
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
0
plugins/slap.lua
Normal file → Executable file
0
plugins/time.lua
Normal file → Executable file
0
plugins/time.lua
Normal file → Executable file
0
plugins/translate.lua
Normal file → Executable file
0
plugins/translate.lua
Normal file → Executable file
0
plugins/urbandictionary.lua
Normal file → Executable file
0
plugins/urbandictionary.lua
Normal file → Executable file
0
plugins/weather.lua
Normal file → Executable file
0
plugins/weather.lua
Normal file → Executable file
8
plugins/whoami.lua
Normal file → Executable file
8
plugins/whoami.lua
Normal file → Executable file
@ -23,6 +23,12 @@ function PLUGIN.action(msg)
|
|||||||
msg = msg.reply_to_message
|
msg = msg.reply_to_message
|
||||||
end
|
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
|
local from_name = msg.from.first_name
|
||||||
if msg.from.last_name then
|
if msg.from.last_name then
|
||||||
from_name = from_name .. ' ' .. msg.from.last_name
|
from_name = from_name .. ' ' .. msg.from.last_name
|
||||||
@ -32,7 +38,7 @@ function PLUGIN.action(msg)
|
|||||||
end
|
end
|
||||||
from_name = from_name .. ' (' .. msg.from.id .. ')'
|
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)
|
send_msg(msg, message)
|
||||||
|
|
||||||
|
0
plugins/wikipedia.lua
Normal file → Executable file
0
plugins/wikipedia.lua
Normal file → Executable file
9
plugins/xkcd.lua
Normal file → Executable file
9
plugins/xkcd.lua
Normal file → Executable file
@ -18,6 +18,7 @@ function PLUGIN.action(msg)
|
|||||||
return send_msg(msg, config.locale.errors.connection)
|
return send_msg(msg, config.locale.errors.connection)
|
||||||
end
|
end
|
||||||
local latest = JSON.decode(jstr).num
|
local latest = JSON.decode(jstr).num
|
||||||
|
local jdat
|
||||||
|
|
||||||
if input then
|
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)
|
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')
|
print('here')
|
||||||
return send_msg(msg, config.locale.errors.connection)
|
return send_msg(msg, config.locale.errors.connection)
|
||||||
end
|
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
|
else
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
url = 'http://xkcd.com/' .. math.random(latest) .. '/info.0.json'
|
url = 'http://xkcd.com/' .. math.random(latest) .. '/info.0.json'
|
||||||
@ -36,7 +41,7 @@ function PLUGIN.action(msg)
|
|||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
return send_msg(msg, config.locale.errors.connection)
|
return send_msg(msg, config.locale.errors.connection)
|
||||||
end
|
end
|
||||||
local jdat = JSON.decode(jstr)
|
jdat = JSON.decode(jstr)
|
||||||
|
|
||||||
local message = '[' .. jdat.num .. '] ' .. jdat.alt .. '\n' .. jdat.img
|
local message = '[' .. jdat.num .. '] ' .. jdat.alt .. '\n' .. jdat.img
|
||||||
|
|
||||||
|
0
utilities.lua
Normal file → Executable file
0
utilities.lua
Normal file → Executable file
Reference in New Issue
Block a user