Database is now centralized. All data is stored in tables within the database table,
which is automatically saved. Please be sure to always stop the bot with /halt to prevent data loss.
This commit is contained in:
parent
03ce363c98
commit
02a7d411fa
18
bot.lua
18
bot.lua
@ -3,7 +3,7 @@ HTTPS = require('ssl.https')
|
|||||||
URL = require('socket.url')
|
URL = require('socket.url')
|
||||||
JSON = require('cjson')
|
JSON = require('cjson')
|
||||||
|
|
||||||
version = '3.2'
|
version = '3.4'
|
||||||
|
|
||||||
bot_init = function() -- The function run when the bot is started or reloaded.
|
bot_init = function() -- The function run when the bot is started or reloaded.
|
||||||
|
|
||||||
@ -11,6 +11,13 @@ bot_init = function() -- The function run when the bot is started or reloaded.
|
|||||||
dofile('bindings.lua') -- Load Telegram bindings.
|
dofile('bindings.lua') -- Load Telegram bindings.
|
||||||
dofile('utilities.lua') -- Load miscellaneous and cross-plugin functions.
|
dofile('utilities.lua') -- Load miscellaneous and cross-plugin functions.
|
||||||
|
|
||||||
|
-- Save the database if it exists. Load it otherwise.
|
||||||
|
if database then
|
||||||
|
save_data('otouto.db', database)
|
||||||
|
else
|
||||||
|
database = load_data('otouto.db')
|
||||||
|
end
|
||||||
|
|
||||||
-- Fetch bot information. Try until it succeeds.
|
-- Fetch bot information. Try until it succeeds.
|
||||||
repeat bot = getMe() until bot
|
repeat bot = getMe() until bot
|
||||||
bot = bot.result
|
bot = bot.result
|
||||||
@ -29,15 +36,15 @@ bot_init = function() -- The function run when the bot is started or reloaded.
|
|||||||
|
|
||||||
last_update = last_update or 0 -- Set loop variables: Update offset,
|
last_update = last_update or 0 -- Set loop variables: Update offset,
|
||||||
last_cron = last_cron or os.time() -- the time of the last cron job,
|
last_cron = last_cron or os.time() -- the time of the last cron job,
|
||||||
is_started = true -- whether the bot should be running or not.
|
is_started = true -- and whether or not the bot should be running.
|
||||||
usernames = usernames or {} -- Table to cache usernames by user ID.
|
database.usernames = database.usernames or {} -- Table to cache usernames by user ID.
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
on_msg_receive = function(msg) -- The fn run whenever a message is received.
|
on_msg_receive = function(msg) -- The fn run whenever a message is received.
|
||||||
|
|
||||||
if msg.from.username then
|
if msg.from.username then
|
||||||
usernames[msg.from.username:lower()] = msg.from.id
|
database.usernames[msg.from.username:lower()] = msg.from.id
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.date < os.time() - 5 then return end -- Do not process old messages.
|
if msg.date < os.time() - 5 then return end -- Do not process old messages.
|
||||||
@ -90,6 +97,7 @@ while is_started do -- Start a loop while the bot should be running.
|
|||||||
last_update = v.update_id
|
last_update = v.update_id
|
||||||
on_msg_receive(v.message)
|
on_msg_receive(v.message)
|
||||||
end
|
end
|
||||||
|
save_data('otouto.db', database)
|
||||||
else
|
else
|
||||||
print(config.errors.connection)
|
print(config.errors.connection)
|
||||||
end
|
end
|
||||||
@ -108,4 +116,6 @@ while is_started do -- Start a loop while the bot should be running.
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Save the database before exiting.
|
||||||
|
save_data('otouto.db', database)
|
||||||
print('Halted.')
|
print('Halted.')
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
admindata = load_data('administration.json')
|
if not database.administration then
|
||||||
if not admindata.global then
|
database.administration = {
|
||||||
admindata.global = {
|
global = {
|
||||||
bans = {},
|
bans = {},
|
||||||
admins = {}
|
admins = {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local sender = dofile('lua-tg/sender.lua')
|
local sender = dofile('lua-tg/sender.lua')
|
||||||
@ -59,21 +60,21 @@ local get_rank = function(target, chat)
|
|||||||
return 5
|
return 5
|
||||||
end
|
end
|
||||||
|
|
||||||
if admindata.global.admins[target] then
|
if database.administration.global.admins[target] then
|
||||||
return 4
|
return 4
|
||||||
end
|
end
|
||||||
|
|
||||||
if chat and admindata[chat] then
|
if chat and database.administration[chat] then
|
||||||
if admindata[chat].govs[target] then
|
if database.administration[chat].govs[target] then
|
||||||
return 3
|
return 3
|
||||||
elseif admindata[chat].mods[target] then
|
elseif database.administration[chat].mods[target] then
|
||||||
return 2
|
return 2
|
||||||
elseif admindata[chat].bans[target] then
|
elseif database.administration[chat].bans[target] then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if admindata.global.bans[target] then
|
if database.administration.global.bans[target] then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ local kick_user = function(target, chat)
|
|||||||
target = tonumber(target)
|
target = tonumber(target)
|
||||||
chat = tostring(chat)
|
chat = tostring(chat)
|
||||||
|
|
||||||
if admindata[chat].grouptype == 'group' then
|
if database.administration[chat].grouptype == 'group' then
|
||||||
tg:chat_del_user(tonumber(chat), target)
|
tg:chat_del_user(tonumber(chat), target)
|
||||||
else
|
else
|
||||||
tg:channel_kick(chat, target)
|
tg:channel_kick(chat, target)
|
||||||
@ -154,7 +155,7 @@ local commands = {
|
|||||||
if get_rank(msg.from.id, msg.chat.id) > 1 then
|
if get_rank(msg.from.id, msg.chat.id) > 1 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if not admindata[msg.chat.id_str].flags[2] == true then
|
if not database.administration[msg.chat.id_str].flags[2] == true then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
kick_user(msg.from.id, msg.chat.id)
|
kick_user(msg.from.id, msg.chat.id)
|
||||||
@ -173,7 +174,7 @@ local commands = {
|
|||||||
action = function(msg)
|
action = function(msg)
|
||||||
|
|
||||||
local rank = get_rank(msg.from.id, msg.chat.id)
|
local rank = get_rank(msg.from.id, msg.chat.id)
|
||||||
local group = admindata[msg.chat.id_str]
|
local group = database.administration[msg.chat.id_str]
|
||||||
|
|
||||||
-- banned
|
-- banned
|
||||||
if rank == 0 then
|
if rank == 0 then
|
||||||
@ -302,7 +303,7 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local output = ''
|
local output = ''
|
||||||
for k,v in pairs(admindata) do
|
for k,v in pairs(database.administration) do
|
||||||
-- no "global" or unlisted groups
|
-- no "global" or unlisted groups
|
||||||
if tonumber(k) and not v.flags[1] then
|
if tonumber(k) and not v.flags[1] then
|
||||||
if v.link then
|
if v.link then
|
||||||
@ -348,21 +349,21 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local modstring = ''
|
local modstring = ''
|
||||||
for k,v in pairs(admindata[msg.chat.id_str].mods) do
|
for k,v in pairs(database.administration[msg.chat.id_str].mods) do
|
||||||
modstring = modstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
modstring = modstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
||||||
end
|
end
|
||||||
if modstring ~= '' then
|
if modstring ~= '' then
|
||||||
modstring = '*Moderators for* _' .. msg.chat.title .. '_ *:*\n' .. modstring
|
modstring = '*Moderators for* _' .. msg.chat.title .. '_ *:*\n' .. modstring
|
||||||
end
|
end
|
||||||
local govstring = ''
|
local govstring = ''
|
||||||
for k,v in pairs(admindata[msg.chat.id_str].govs) do
|
for k,v in pairs(database.administration[msg.chat.id_str].govs) do
|
||||||
govstring = govstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
govstring = govstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
||||||
end
|
end
|
||||||
if govstring ~= '' then
|
if govstring ~= '' then
|
||||||
govstring = '*Governors for* _' .. msg.chat.title .. '_ *:*\n' .. govstring
|
govstring = '*Governors for* _' .. msg.chat.title .. '_ *:*\n' .. govstring
|
||||||
end
|
end
|
||||||
local adminstring = '*Administrators:*\n• ' .. config.admin_name .. ' (' .. config.admin .. ')\n'
|
local adminstring = '*Administrators:*\n• ' .. config.admin_name .. ' (' .. config.admin .. ')\n'
|
||||||
for k,v in pairs(admindata.global.admins) do
|
for k,v in pairs(database.administration.global.admins) do
|
||||||
adminstring = adminstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
adminstring = adminstring .. '• ' .. v .. ' (' .. k .. ')\n'
|
||||||
end
|
end
|
||||||
local output = modstring .. govstring .. adminstring
|
local output = modstring .. govstring .. adminstring
|
||||||
@ -382,8 +383,8 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local output = 'No rules have been set for ' .. msg.chat.title .. '.'
|
local output = 'No rules have been set for ' .. msg.chat.title .. '.'
|
||||||
if admindata[msg.chat.id_str].rules then
|
if database.administration[msg.chat.id_str].rules then
|
||||||
output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n' .. admindata[msg.chat.id_str].rules
|
output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n' .. database.administration[msg.chat.id_str].rules
|
||||||
end
|
end
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -401,8 +402,8 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local output = 'No MOTD has been set for ' .. msg.chat.title .. '.'
|
local output = 'No MOTD has been set for ' .. msg.chat.title .. '.'
|
||||||
if admindata[msg.chat.id_str].motd then
|
if database.administration[msg.chat.id_str].motd then
|
||||||
output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. admindata[msg.chat.id_str].motd
|
output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. database.administration[msg.chat.id_str].motd
|
||||||
end
|
end
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -419,8 +420,8 @@ local commands = {
|
|||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
local output = 'No link has been set for ' .. msg.chat.title .. '.'
|
local output = 'No link has been set for ' .. msg.chat.title .. '.'
|
||||||
if admindata[msg.chat.id_str].link then
|
if database.administration[msg.chat.id_str].link then
|
||||||
output = '[' .. msg.chat.title .. '](' .. admindata[msg.chat.id_str].link .. ')'
|
output = '[' .. msg.chat.title .. '](' .. database.administration[msg.chat.id_str].link .. ')'
|
||||||
end
|
end
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -491,12 +492,12 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if admindata[msg.chat.id_str].bans[target.id_str] then
|
if database.administration[msg.chat.id_str].bans[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is already banned.')
|
sendReply(msg, target.name .. ' is already banned.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
kick_user(target.id, msg.chat.id)
|
kick_user(target.id, msg.chat.id)
|
||||||
admindata[msg.chat.id_str].bans[target.id_str] = true
|
database.administration[msg.chat.id_str].bans[target.id_str] = true
|
||||||
sendMessage(msg.chat.id, target.name .. ' has been banned.')
|
sendMessage(msg.chat.id, target.name .. ' has been banned.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -516,15 +517,15 @@ local commands = {
|
|||||||
sendReply(msg, target.err)
|
sendReply(msg, target.err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not admindata[msg.chat.id_str].bans[target.id_str] then
|
if not database.administration[msg.chat.id_str].bans[target.id_str] then
|
||||||
if admindata.global.bans[target.id_str] then
|
if database.administration.global.bans[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is banned globally.')
|
sendReply(msg, target.name .. ' is banned globally.')
|
||||||
else
|
else
|
||||||
sendReply(msg, target.name .. ' is not banned.')
|
sendReply(msg, target.name .. ' is not banned.')
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].bans[target.id_str] = nil
|
database.administration[msg.chat.id_str].bans[target.id_str] = nil
|
||||||
sendMessage(msg.chat.id, target.name .. ' has been unbanned.')
|
sendMessage(msg.chat.id, target.name .. ' has been unbanned.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -551,7 +552,7 @@ local commands = {
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
output = output .. '*' .. i .. '.* ' .. m:trim() .. '\n'
|
output = output .. '*' .. i .. '.* ' .. m:trim() .. '\n'
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].rules = output
|
database.administration[msg.chat.id_str].rules = output
|
||||||
output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n' .. output
|
output = '*Rules for* _' .. msg.chat.title .. '_ *:*\n' .. output
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -573,7 +574,7 @@ local commands = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
input = input:trim()
|
input = input:trim()
|
||||||
admindata[msg.chat.id_str].motd = input
|
database.administration[msg.chat.id_str].motd = input
|
||||||
local output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. input
|
local output = '*MOTD for* _' .. msg.chat.title .. '_ *:*\n' .. input
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -594,7 +595,7 @@ local commands = {
|
|||||||
sendReply(msg, '/' .. command)
|
sendReply(msg, '/' .. command)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].link = input
|
database.administration[msg.chat.id_str].link = input
|
||||||
local output = '[' .. msg.chat.title .. '](' .. input .. ')'
|
local output = '[' .. msg.chat.title .. '](' .. input .. ')'
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -619,18 +620,18 @@ local commands = {
|
|||||||
if not input then
|
if not input then
|
||||||
local output = '*Flags for* _' .. msg.chat.title .. '_ *:*\n'
|
local output = '*Flags for* _' .. msg.chat.title .. '_ *:*\n'
|
||||||
for i,v in ipairs(flags) do
|
for i,v in ipairs(flags) do
|
||||||
local status = admindata[msg.chat.id_str].flags[i] or false
|
local status = database.administration[msg.chat.id_str].flags[i] or false
|
||||||
output = output .. '`[' .. i .. ']` *' .. v.name .. '* = `' .. tostring(status) .. '`\n• ' .. v.desc .. '\n'
|
output = output .. '`[' .. i .. ']` *' .. v.name .. '* = `' .. tostring(status) .. '`\n• ' .. v.desc .. '\n'
|
||||||
end
|
end
|
||||||
sendMessage(msg.chat.id, output, true, nil, true)
|
sendMessage(msg.chat.id, output, true, nil, true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local output
|
local output
|
||||||
if admindata[msg.chat.id_str].flags[input] == true then
|
if database.administration[msg.chat.id_str].flags[input] == true then
|
||||||
admindata[msg.chat.id_str].flags[input] = false
|
database.administration[msg.chat.id_str].flags[input] = false
|
||||||
sendReply(msg, flags[input].disabled)
|
sendReply(msg, flags[input].disabled)
|
||||||
else
|
else
|
||||||
admindata[msg.chat.id_str].flags[input] = true
|
database.administration[msg.chat.id_str].flags[input] = true
|
||||||
sendReply(msg, flags[input].enabled)
|
sendReply(msg, flags[input].enabled)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -655,10 +656,10 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if admindata[msg.chat.id_str].grouptype == 'supergroup' then
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
||||||
tg:channel_set_admin(msg.chat.id, target, 1)
|
tg:channel_set_admin(msg.chat.id, target, 1)
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].mods[target.id_str] = target.name
|
database.administration[msg.chat.id_str].mods[target.id_str] = target.name
|
||||||
sendReply(msg, target.name .. ' is now a moderator.')
|
sendReply(msg, target.name .. ' is now a moderator.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -682,10 +683,10 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' is not a moderator.')
|
sendReply(msg, target.name .. ' is not a moderator.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if admindata[msg.chat.id_str].grouptype == 'supergroup' then
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
||||||
tg:channel_set_admin(msg.chat.id, target, 0)
|
tg:channel_set_admin(msg.chat.id, target, 0)
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].mods[target.id_str] = nil
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
||||||
sendReply(msg, target.name .. ' is no longer a moderator.')
|
sendReply(msg, target.name .. ' is no longer a moderator.')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -710,12 +711,12 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
||||||
return
|
return
|
||||||
elseif target.rank == 2 then
|
elseif target.rank == 2 then
|
||||||
admindata[msg.chat.id_str].mods[target.id_str] = nil
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
||||||
end
|
end
|
||||||
if admindata[msg.chat.id_str].grouptype == 'supergroup' then
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
||||||
tg:channel_set_admin(msg.chat.id, target, 1)
|
tg:channel_set_admin(msg.chat.id, target, 1)
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].govs[target.id_str] = target.name
|
database.administration[msg.chat.id_str].govs[target.id_str] = target.name
|
||||||
sendReply(msg, target.name .. ' is now a governor.')
|
sendReply(msg, target.name .. ' is now a governor.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -739,10 +740,10 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' is not a governor.')
|
sendReply(msg, target.name .. ' is not a governor.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if admindata[msg.chat.id_str].grouptype == 'supergroup' then
|
if database.administration[msg.chat.id_str].grouptype == 'supergroup' then
|
||||||
tg:channel_set_admin(msg.chat.id, target, 0)
|
tg:channel_set_admin(msg.chat.id, target, 0)
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str].govs[target.id_str] = nil
|
database.administration[msg.chat.id_str].govs[target.id_str] = nil
|
||||||
sendReply(msg, target.name .. ' is no longer a governor.')
|
sendReply(msg, target.name .. ' is no longer a governor.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -767,16 +768,16 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
sendReply(msg, target.name .. ' cannot be banned: Too privileged.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if admindata.global.bans[target.id_str] then
|
if database.administration.global.bans[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is already banned globally.')
|
sendReply(msg, target.name .. ' is already banned globally.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for k,v in pairs(admindata) do
|
for k,v in pairs(database.administration) do
|
||||||
if tonumber(k) then
|
if tonumber(k) then
|
||||||
kick_user(target.id, k)
|
kick_user(target.id, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
admindata.global.bans[target.id_str] = true
|
database.administration.global.bans[target.id_str] = true
|
||||||
sendReply(msg, target.name .. ' has been globally banned.')
|
sendReply(msg, target.name .. ' has been globally banned.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -797,11 +798,11 @@ local commands = {
|
|||||||
sendReply(msg, target.err)
|
sendReply(msg, target.err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not admindata.global.bans[target.id_str] then
|
if not database.administration.global.bans[target.id_str] then
|
||||||
sendReply(msg, target.name .. ' is not banned globally.')
|
sendReply(msg, target.name .. ' is not banned globally.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
admindata.global.bans[target.id_str] = nil
|
database.administration.global.bans[target.id_str] = nil
|
||||||
sendReply(msg, target.name .. ' has been globally unbanned.')
|
sendReply(msg, target.name .. ' has been globally unbanned.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -825,11 +826,11 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
sendReply(msg, target.name .. ' cannot be promoted: Already privileged.')
|
||||||
return
|
return
|
||||||
elseif target.rank == 2 then
|
elseif target.rank == 2 then
|
||||||
admindata[msg.chat.id_str].mods[target.id_str] = nil
|
database.administration[msg.chat.id_str].mods[target.id_str] = nil
|
||||||
elseif target.rank == 3 then
|
elseif target.rank == 3 then
|
||||||
admindata[msg.chat.id_str].govs[target.id_str] = nil
|
database.administration[msg.chat.id_str].govs[target.id_str] = nil
|
||||||
end
|
end
|
||||||
admindata.global.admins[target.id_str] = target.name
|
database.administration.global.admins[target.id_str] = target.name
|
||||||
sendReply(msg, target.name .. ' is now an administrator.')
|
sendReply(msg, target.name .. ' is now an administrator.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -849,7 +850,7 @@ local commands = {
|
|||||||
sendReply(msg, target.name .. ' is not an administrator.')
|
sendReply(msg, target.name .. ' is not an administrator.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
admindata.global.admins[target.id_str] = nil
|
database.administration.global.admins[target.id_str] = nil
|
||||||
sendReply(msg, target.name .. ' is no longer an administrator.')
|
sendReply(msg, target.name .. ' is no longer an administrator.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -864,11 +865,11 @@ local commands = {
|
|||||||
interior = false,
|
interior = false,
|
||||||
|
|
||||||
action = function(msg)
|
action = function(msg)
|
||||||
if admindata[msg.chat.id_str] then
|
if database.administration[msg.chat.id_str] then
|
||||||
sendReply(msg, 'I am already administrating this group.')
|
sendReply(msg, 'I am already administrating this group.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
admindata[msg.chat.id_str] = {
|
database.administration[msg.chat.id_str] = {
|
||||||
mods = {},
|
mods = {},
|
||||||
govs = {},
|
govs = {},
|
||||||
bans = {},
|
bans = {},
|
||||||
@ -878,8 +879,8 @@ local commands = {
|
|||||||
founded = os.time()
|
founded = os.time()
|
||||||
}
|
}
|
||||||
if msg.chat.type == 'group' then
|
if msg.chat.type == 'group' then
|
||||||
admindata[msg.chat.id_str].photo = get_photo(msg.chat.id)
|
database.administration[msg.chat.id_str].photo = get_photo(msg.chat.id)
|
||||||
admindata[msg.chat.id_str].link = tg:export_chat_link(msg.chat.id)
|
database.administration[msg.chat.id_str].link = tg:export_chat_link(msg.chat.id)
|
||||||
end
|
end
|
||||||
sendReply(msg, 'I am now administrating this group.')
|
sendReply(msg, 'I am now administrating this group.')
|
||||||
end
|
end
|
||||||
@ -900,7 +901,7 @@ local commands = {
|
|||||||
if not input then
|
if not input then
|
||||||
input = msg.chat.id_str
|
input = msg.chat.id_str
|
||||||
end
|
end
|
||||||
admindata[input] = nil
|
database.administration[input] = nil
|
||||||
sendReply(msg, 'I am no longer administrating this group.')
|
sendReply(msg, 'I am no longer administrating this group.')
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -921,7 +922,7 @@ local commands = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
input = '*Admin Broadcast:*\n' .. input
|
input = '*Admin Broadcast:*\n' .. input
|
||||||
for k,v in pairs(admindata) do
|
for k,v in pairs(database.administration) do
|
||||||
if tonumber(k) then
|
if tonumber(k) then
|
||||||
sendMessage(k, input, true, nil, true)
|
sendMessage(k, input, true, nil, true)
|
||||||
end
|
end
|
||||||
@ -952,7 +953,7 @@ local action = function(msg) -- wee nesting
|
|||||||
for i,v in ipairs(commands) do
|
for i,v in ipairs(commands) do
|
||||||
for key,val in pairs(v.triggers) do
|
for key,val in pairs(v.triggers) do
|
||||||
if msg.text_lower:match(val) then
|
if msg.text_lower:match(val) then
|
||||||
if v.interior and not admindata[msg.chat.id_str] then
|
if v.interior and not database.administration[msg.chat.id_str] then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if msg.chat.type ~= 'private' and get_rank(msg.from.id, msg.chat.id) < v.privilege then
|
if msg.chat.type ~= 'private' and get_rank(msg.from.id, msg.chat.id) < v.privilege then
|
||||||
@ -972,7 +973,6 @@ local cron = function()
|
|||||||
if os.date('%M', os.time()) ~= last_admin_cron then
|
if os.date('%M', os.time()) ~= last_admin_cron then
|
||||||
last_admin_cron = os.date('%M', os.time())
|
last_admin_cron = os.date('%M', os.time())
|
||||||
tg = sender(localhost, config.cli_port)
|
tg = sender(localhost, config.cli_port)
|
||||||
save_data('administration.json', admindata)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
-- This plugin will allow the admin to blacklist users who will be unable to
|
-- This plugin will allow the admin to blacklist users who will be unable to
|
||||||
-- use the bot. This plugin should be at the top of your plugin list in config.
|
-- use the bot. This plugin should be at the top of your plugin list in config.
|
||||||
|
|
||||||
|
if not database.blacklist then
|
||||||
|
database.blacklist = {}
|
||||||
|
end
|
||||||
|
|
||||||
local triggers = {
|
local triggers = {
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
local blacklist = load_data('blacklist.json')
|
if database.blacklist[msg.from.id_str] then
|
||||||
|
|
||||||
if blacklist[msg.from.id_str] then
|
|
||||||
return -- End if the sender is blacklisted.
|
return -- End if the sender is blacklisted.
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,16 +33,14 @@ local triggers = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if blacklist[input] then
|
if database.blacklist[input] then
|
||||||
blacklist[input] = nil
|
database.blacklist[input] = nil
|
||||||
sendReply(msg, input .. ' has been removed from the blacklist.')
|
sendReply(msg, input .. ' has been removed from the blacklist.')
|
||||||
else
|
else
|
||||||
blacklist[input] = true
|
database.blacklist[input] = true
|
||||||
sendReply(msg, input .. ' has been added to the blacklist.')
|
sendReply(msg, input .. ' has been added to the blacklist.')
|
||||||
end
|
end
|
||||||
|
|
||||||
save_data('blacklist.json', blacklist)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -6,9 +6,7 @@ local triggers = {
|
|||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
local nicks = load_data('nicknames.json')
|
local nick = database.nicknames[msg.from.id_str] or msg.from.first_name
|
||||||
|
|
||||||
local nick = nicks[msg.from.id_str] or msg.from.first_name
|
|
||||||
|
|
||||||
for k,v in pairs(config.greetings) do
|
for k,v in pairs(config.greetings) do
|
||||||
for key,val in pairs(v) do
|
for key,val in pairs(v) do
|
||||||
|
@ -1,22 +1,29 @@
|
|||||||
-- Plugin for the Hearthstone database provided by hearthstonejson.com.
|
-- Plugin for the Hearthstone database provided by hearthstonejson.com.
|
||||||
|
|
||||||
if not hs_dat then
|
if not database.hearthstone or os.time() > database.hearthstone.expiration then
|
||||||
|
|
||||||
hs_dat = {}
|
print('Downloading Hearthstone database...')
|
||||||
|
|
||||||
|
database.hearthstone = {}
|
||||||
|
|
||||||
local jstr, res = HTTPS.request('http://hearthstonejson.com/json/AllSets.json')
|
local jstr, res = HTTPS.request('http://hearthstonejson.com/json/AllSets.json')
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
print('Error connecting to hearthstonejson.com.')
|
print('Error connecting to hearthstonejson.com.')
|
||||||
print('hearthstone.lua will not be enabled.')
|
print('hearthstone.lua will not be enabled.')
|
||||||
|
return
|
||||||
end
|
end
|
||||||
local jdat = JSON.decode(jstr)
|
local jdat = JSON.decode(jstr)
|
||||||
|
|
||||||
for k,v in pairs(jdat) do
|
for k,v in pairs(jdat) do
|
||||||
for key,val in pairs(v) do
|
for key,val in pairs(v) do
|
||||||
table.insert(hs_dat, val)
|
table.insert(database.hearthstone, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
database.hearthstone.expiration = os.time() + 600000
|
||||||
|
|
||||||
|
print('Download complete! It will be permanently stored.')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local command = 'hearthstone <query>'
|
local command = 'hearthstone <query>'
|
||||||
@ -96,7 +103,7 @@ local action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local output = ''
|
local output = ''
|
||||||
for k,v in pairs(hs_dat) do
|
for k,v in pairs(database.hearthstone) do
|
||||||
if string.lower(v.name):match(input) then
|
if string.lower(v.name):match(input) then
|
||||||
output = output .. format_card(v) .. '\n\n'
|
output = output .. format_card(v) .. '\n\n'
|
||||||
end
|
end
|
||||||
|
@ -4,6 +4,10 @@ if not config.lastfm_api_key then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not database.lastfm then
|
||||||
|
database.lastfm = {}
|
||||||
|
end
|
||||||
|
|
||||||
local command = 'lastfm'
|
local command = 'lastfm'
|
||||||
local doc = [[```
|
local doc = [[```
|
||||||
/np [username]
|
/np [username]
|
||||||
@ -21,7 +25,6 @@ local triggers = {
|
|||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
lastfm = load_data('lastfm.json')
|
|
||||||
local input = msg.text:input()
|
local input = msg.text:input()
|
||||||
|
|
||||||
if string.match(msg.text, '^/lastfm') then
|
if string.match(msg.text, '^/lastfm') then
|
||||||
@ -31,13 +34,12 @@ local action = function(msg)
|
|||||||
if not input then
|
if not input then
|
||||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||||
elseif input == '-' then
|
elseif input == '-' then
|
||||||
lastfm[msg.from.id_str] = nil
|
database.lastfm[msg.from.id_str] = nil
|
||||||
sendReply(msg, 'Your last.fm username has been forgotten.')
|
sendReply(msg, 'Your last.fm username has been forgotten.')
|
||||||
else
|
else
|
||||||
lastfm[msg.from.id_str] = input
|
database.lastfm[msg.from.id_str] = input
|
||||||
sendReply(msg, 'Your last.fm username has been set to "' .. input .. '".')
|
sendReply(msg, 'Your last.fm username has been set to "' .. input .. '".')
|
||||||
end
|
end
|
||||||
save_data('lastfm.json', lastfm)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,13 +49,12 @@ local action = function(msg)
|
|||||||
local output = ''
|
local output = ''
|
||||||
if input then
|
if input then
|
||||||
username = input
|
username = input
|
||||||
elseif lastfm[msg.from.id_str] then
|
elseif database.lastfm[msg.from.id_str] then
|
||||||
username = lastfm[msg.from.id_str]
|
username = database.lastfm[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 /fmset <username>.'
|
output = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /fmset <username>.'
|
||||||
lastfm[msg.from.id_str] = username
|
database.lastfm[msg.from.id_str] = username
|
||||||
save_data('lastfm.json', lastfm)
|
|
||||||
else
|
else
|
||||||
sendReply(msg, 'Please specify your last.fm username or set it with /fmset.')
|
sendReply(msg, 'Please specify your last.fm username or set it with /fmset.')
|
||||||
return
|
return
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if not database.librefm then
|
||||||
|
database.librefm = {}
|
||||||
|
end
|
||||||
|
|
||||||
local command = 'librefm'
|
local command = 'librefm'
|
||||||
local doc = [[```
|
local doc = [[```
|
||||||
/lnp [username]
|
/lnp [username]
|
||||||
@ -15,7 +19,6 @@ local triggers = {
|
|||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
lastfm = load_data('librefm.json')
|
|
||||||
local input = msg.text:input()
|
local input = msg.text:input()
|
||||||
|
|
||||||
if string.match(msg.text, '^/librefm') then
|
if string.match(msg.text, '^/librefm') then
|
||||||
@ -25,13 +28,12 @@ local action = function(msg)
|
|||||||
if not input then
|
if not input then
|
||||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||||
elseif input == '-' then
|
elseif input == '-' then
|
||||||
lastfm[msg.from.id_str] = nil
|
database.lastfm[msg.from.id_str] = nil
|
||||||
sendReply(msg, 'Your libre.fm username has been forgotten.')
|
sendReply(msg, 'Your libre.fm username has been forgotten.')
|
||||||
else
|
else
|
||||||
lastfm[msg.from.id_str] = input
|
database.lastfm[msg.from.id_str] = input
|
||||||
sendReply(msg, 'Your libre.fm username has been set to "' .. input .. '".')
|
sendReply(msg, 'Your libre.fm username has been set to "' .. input .. '".')
|
||||||
end
|
end
|
||||||
save_data('librefm.json', lastfm)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,13 +43,12 @@ local action = function(msg)
|
|||||||
local output = ''
|
local output = ''
|
||||||
if input then
|
if input then
|
||||||
username = input
|
username = input
|
||||||
elseif lastfm[msg.from.id_str] then
|
elseif database.lastfm[msg.from.id_str] then
|
||||||
username = lastfm[msg.from.id_str]
|
username = database.lastfm[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>.'
|
output = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /lfmset <username>.'
|
||||||
lastfm[msg.from.id_str] = username
|
database.lastfm[msg.from.id_str] = username
|
||||||
save_data('lastfm.json', lastfm)
|
|
||||||
else
|
else
|
||||||
sendReply(msg, 'Please specify your libre.fm username or set it with /lfmset.')
|
sendReply(msg, 'Please specify your libre.fm username or set it with /lfmset.')
|
||||||
return
|
return
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
-- Put this near the top, after blacklist.
|
-- Put this near the top, after blacklist.
|
||||||
-- If you want to enable antisquig, put that at the top, before blacklist.
|
-- If you want to enable antisquig, put that at the top, before blacklist.
|
||||||
|
|
||||||
moddat = load_data('moderation.json')
|
if not database.moderation then
|
||||||
|
database.moderation = {}
|
||||||
|
end
|
||||||
|
|
||||||
antisquig = {}
|
antisquig = {}
|
||||||
|
|
||||||
local commands = {
|
local commands = {
|
||||||
|
|
||||||
['^/modhelp[@'..bot.username..']*$'] = function(msg)
|
['^/modhelp[@'..bot.username..']*$'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
local message = [[
|
local message = [[
|
||||||
/modlist - List the moderators and administrators of this group.
|
/modlist - List the moderators and administrators of this group.
|
||||||
@ -31,11 +34,11 @@ local commands = {
|
|||||||
|
|
||||||
['^/modlist[@'..bot.username..']*$'] = function(msg)
|
['^/modlist[@'..bot.username..']*$'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
local message = ''
|
local message = ''
|
||||||
|
|
||||||
for k,v in pairs(moddat[msg.chat.id_str]) do
|
for k,v in pairs(database.moderation[msg.chat.id_str]) do
|
||||||
message = message .. ' - ' .. v .. ' (' .. k .. ')\n'
|
message = message .. ' - ' .. v .. ' (' .. k .. ')\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -67,7 +70,7 @@ local commands = {
|
|||||||
return config.errors.not_admin
|
return config.errors.not_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs(moddat) do
|
for k,v in pairs(database.moderation) do
|
||||||
sendMessage(k, message)
|
sendMessage(k, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,12 +84,11 @@ local commands = {
|
|||||||
return config.errors.not_admin
|
return config.errors.not_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
if moddat[msg.chat.id_str] then
|
if database.moderation[msg.chat.id_str] then
|
||||||
return 'I am already moderating this group.'
|
return 'I am already moderating this group.'
|
||||||
end
|
end
|
||||||
|
|
||||||
moddat[msg.chat.id_str] = {}
|
database.moderation[msg.chat.id_str] = {}
|
||||||
save_data('moderation.json', moddat)
|
|
||||||
return 'I am now moderating this group.'
|
return 'I am now moderating this group.'
|
||||||
|
|
||||||
end,
|
end,
|
||||||
@ -97,19 +99,18 @@ local commands = {
|
|||||||
return config.errors.not_admin
|
return config.errors.not_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then
|
if not database.moderation[msg.chat.id_str] then
|
||||||
return config.errors.moderation
|
return config.errors.moderation
|
||||||
end
|
end
|
||||||
|
|
||||||
moddat[msg.chat.id_str] = nil
|
database.moderation[msg.chat.id_str] = nil
|
||||||
save_data('moderation.json', moddat)
|
|
||||||
return 'I am no longer moderating this group.'
|
return 'I am no longer moderating this group.'
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
['^/modprom[@'..bot.username..']*$'] = function(msg)
|
['^/modprom[@'..bot.username..']*$'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
if not config.moderation.admins[msg.from.id_str] then
|
if not config.moderation.admins[msg.from.id_str] then
|
||||||
return config.errors.not_admin
|
return config.errors.not_admin
|
||||||
@ -126,12 +127,11 @@ local commands = {
|
|||||||
return modname .. ' is already an administrator.'
|
return modname .. ' is already an administrator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
if moddat[msg.chat.id_str][modid] then
|
if database.moderation[msg.chat.id_str][modid] then
|
||||||
return modname .. ' is already a moderator.'
|
return modname .. ' is already a moderator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
moddat[msg.chat.id_str][modid] = modname
|
database.moderation[msg.chat.id_str][modid] = modname
|
||||||
save_data('moderation.json', moddat)
|
|
||||||
|
|
||||||
return modname .. ' is now a moderator.'
|
return modname .. ' is now a moderator.'
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ local commands = {
|
|||||||
|
|
||||||
['^/moddem[@'..bot.username..']*'] = function(msg)
|
['^/moddem[@'..bot.username..']*'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
if not config.moderation.admins[msg.from.id_str] then
|
if not config.moderation.admins[msg.from.id_str] then
|
||||||
return config.errors.not_admin
|
return config.errors.not_admin
|
||||||
@ -159,13 +159,12 @@ local commands = {
|
|||||||
return config.moderation.admins[modid] .. ' is an administrator.'
|
return config.moderation.admins[modid] .. ' is an administrator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str][modid] then
|
if not database.moderation[msg.chat.id_str][modid] then
|
||||||
return 'User is not a moderator.'
|
return 'User is not a moderator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
local modname = moddat[msg.chat.id_str][modid]
|
local modname = database.moderation[msg.chat.id_str][modid]
|
||||||
moddat[msg.chat.id_str][modid] = nil
|
database.moderation[msg.chat.id_str][modid] = nil
|
||||||
save_data('moderation.json', moddat)
|
|
||||||
|
|
||||||
return modname .. ' is no longer a moderator.'
|
return modname .. ' is no longer a moderator.'
|
||||||
|
|
||||||
@ -173,9 +172,9 @@ local commands = {
|
|||||||
|
|
||||||
['/modkick[@'..bot.username..']*'] = function(msg)
|
['/modkick[@'..bot.username..']*'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str][msg.from.id_str] then
|
if not database.moderation[msg.chat.id_str][msg.from.id_str] then
|
||||||
if not config.moderation.admins[msg.from.id_str] then
|
if not config.moderation.admins[msg.from.id_str] then
|
||||||
return config.errors.not_mod
|
return config.errors.not_mod
|
||||||
end
|
end
|
||||||
@ -193,7 +192,7 @@ local commands = {
|
|||||||
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
||||||
end
|
end
|
||||||
|
|
||||||
if moddat[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
if database.moderation[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
||||||
return 'You cannot kick a moderator.'
|
return 'You cannot kick a moderator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -205,9 +204,9 @@ local commands = {
|
|||||||
|
|
||||||
['^/modban[@'..bot.username..']*'] = function(msg)
|
['^/modban[@'..bot.username..']*'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return end
|
if not database.moderation[msg.chat.id_str] then return end
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str][msg.from.id_str] then
|
if not database.moderation[msg.chat.id_str][msg.from.id_str] then
|
||||||
if not config.moderation.admins[msg.from.id_str] then
|
if not config.moderation.admins[msg.from.id_str] then
|
||||||
return config.errors.not_mod
|
return config.errors.not_mod
|
||||||
end
|
end
|
||||||
@ -225,7 +224,7 @@ local commands = {
|
|||||||
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
return 'Kicks must be done via reply or specification of a user/bot\'s ID or username.'
|
||||||
end
|
end
|
||||||
|
|
||||||
if moddat[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
if database.moderation[msg.chat.id_str][userid] or config.moderation.admins[userid] then
|
||||||
return 'You cannot ban a moderator.'
|
return 'You cannot ban a moderator.'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -240,9 +239,9 @@ local commands = {
|
|||||||
if config.antisquig then
|
if config.antisquig then
|
||||||
commands['[\216-\219][\128-\191]'] = function(msg)
|
commands['[\216-\219][\128-\191]'] = function(msg)
|
||||||
|
|
||||||
if not moddat[msg.chat.id_str] then return true end
|
if not database.moderation[msg.chat.id_str] then return true end
|
||||||
if config.moderation.admins[msg.from.id_str] then return true end
|
if config.moderation.admins[msg.from.id_str] then return true end
|
||||||
if moddat[msg.chat.id_str][msg.from.id_str] then return true end
|
if database.moderation[msg.chat.id_str][msg.from.id_str] then return true end
|
||||||
|
|
||||||
if antisquig[msg.from.id] == true then
|
if antisquig[msg.from.id] == true then
|
||||||
return
|
return
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if not database.nicknames then
|
||||||
|
database.nicknames = {}
|
||||||
|
end
|
||||||
|
|
||||||
local command = 'nick <nickname>'
|
local command = 'nick <nickname>'
|
||||||
local doc = [[```
|
local doc = [[```
|
||||||
/nick <nickname>
|
/nick <nickname>
|
||||||
@ -21,17 +25,14 @@ local action = function(msg)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
nicks = load_data('nicknames.json')
|
|
||||||
|
|
||||||
if input == '-' then
|
if input == '-' then
|
||||||
nicks[msg.from.id_str] = nil
|
database.nicknames[msg.from.id_str] = nil
|
||||||
sendReply(msg, 'Your nickname has been deleted.')
|
sendReply(msg, 'Your nickname has been deleted.')
|
||||||
else
|
else
|
||||||
nicks[msg.from.id_str] = input
|
database.nicknames[msg.from.id_str] = input
|
||||||
sendReply(msg, 'Your nickname has been set to "' .. input .. '".')
|
sendReply(msg, 'Your nickname has been set to "' .. input .. '".')
|
||||||
end
|
end
|
||||||
|
|
||||||
save_data('nicknames.json', nicks)
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
176
plugins/slap.lua
176
plugins/slap.lua
@ -9,105 +9,103 @@ local triggers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local slaps = {
|
local slaps = {
|
||||||
'$victim was shot by $victor.',
|
'VICTIM was shot by VICTOR.',
|
||||||
'$victim was pricked to death.',
|
'VICTIM was pricked to death.',
|
||||||
'$victim walked into a cactus while trying to escape $victor.',
|
'VICTIM walked into a cactus while trying to escape VICTOR.',
|
||||||
'$victim drowned.',
|
'VICTIM drowned.',
|
||||||
'$victim drowned whilst trying to escape $victor.',
|
'VICTIM drowned whilst trying to escape VICTOR.',
|
||||||
'$victim blew up.',
|
'VICTIM blew up.',
|
||||||
'$victim was blown up by $victor.',
|
'VICTIM was blown up by VICTOR.',
|
||||||
'$victim hit the ground too hard.',
|
'VICTIM hit the ground too hard.',
|
||||||
'$victim fell from a high place.',
|
'VICTIM fell from a high place.',
|
||||||
'$victim fell off a ladder.',
|
'VICTIM fell off a ladder.',
|
||||||
'$victim fell into a patch of cacti.',
|
'VICTIM fell into a patch of cacti.',
|
||||||
'$victim was doomed to fall by $victor.',
|
'VICTIM was doomed to fall by VICTOR.',
|
||||||
'$victim was blown from a high place by $victor.',
|
'VICTIM was blown from a high place by VICTOR.',
|
||||||
'$victim was squashed by a falling anvil.',
|
'VICTIM was squashed by a falling anvil.',
|
||||||
'$victim went up in flames.',
|
'VICTIM went up in flames.',
|
||||||
'$victim burned to death.',
|
'VICTIM burned to death.',
|
||||||
'$victim was burnt to a crisp whilst fighting $victor.',
|
'VICTIM was burnt to a crisp whilst fighting VICTOR.',
|
||||||
'$victim walked into a fire whilst fighting $victor.',
|
'VICTIM walked into a fire whilst fighting VICTOR.',
|
||||||
'$victim tried to swim in lava.',
|
'VICTIM tried to swim in lava.',
|
||||||
'$victim tried to swim in lava while trying to escape $victor.',
|
'VICTIM tried to swim in lava while trying to escape VICTOR.',
|
||||||
'$victim was struck by lightning.',
|
'VICTIM was struck by lightning.',
|
||||||
'$victim was slain by $victor.',
|
'VICTIM was slain by VICTOR.',
|
||||||
'$victim got finished off by $victor.',
|
'VICTIM got finished off by VICTOR.',
|
||||||
'$victim was killed by magic.',
|
'VICTIM was killed by magic.',
|
||||||
'$victim was killed by $victor using magic.',
|
'VICTIM was killed by VICTOR using magic.',
|
||||||
'$victim starved to death.',
|
'VICTIM starved to death.',
|
||||||
'$victim suffocated in a wall.',
|
'VICTIM suffocated in a wall.',
|
||||||
'$victim fell out of the world.',
|
'VICTIM fell out of the world.',
|
||||||
'$victim was knocked into the void by $victor.',
|
'VICTIM was knocked into the void by VICTOR.',
|
||||||
'$victim withered away.',
|
'VICTIM withered away.',
|
||||||
'$victim was pummeled by $victor.',
|
'VICTIM was pummeled by VICTOR.',
|
||||||
'$victim was fragged by $victor.',
|
'VICTIM was fragged by VICTOR.',
|
||||||
'$victim was desynchronized.',
|
'VICTIM was desynchronized.',
|
||||||
'$victim was wasted.',
|
'VICTIM was wasted.',
|
||||||
'$victim was busted.',
|
'VICTIM was busted.',
|
||||||
'$victim\'s bones are scraped clean by the desolate wind.',
|
'VICTIM\'s bones are scraped clean by the desolate wind.',
|
||||||
'$victim has died of dysentery.',
|
'VICTIM has died of dysentery.',
|
||||||
'$victim fainted.',
|
'VICTIM fainted.',
|
||||||
'$victim is out of usable Pokemon! $victim whited out!',
|
'VICTIM is out of usable Pokemon! VICTIM whited out!',
|
||||||
'$victim is out of usable Pokemon! $victim blacked out!',
|
'VICTIM is out of usable Pokemon! VICTIM blacked out!',
|
||||||
'$victim whited out!',
|
'VICTIM whited out!',
|
||||||
'$victim blacked out!',
|
'VICTIM blacked out!',
|
||||||
'$victim says goodbye to this cruel world.',
|
'VICTIM says goodbye to this cruel world.',
|
||||||
'$victim got rekt.',
|
'VICTIM got rekt.',
|
||||||
'$victim was sawn in half by $victor.',
|
'VICTIM was sawn in half by VICTOR.',
|
||||||
'$victim died. I blame $victor.',
|
'VICTIM died. I blame VICTOR.',
|
||||||
'$victim was axe-murdered by $victor.',
|
'VICTIM was axe-murdered by VICTOR.',
|
||||||
'$victim\'s melon was split by $victor.',
|
'VICTIM\'s melon was split by VICTOR.',
|
||||||
'$victim was slice and diced by $victor.',
|
'VICTIM was slice and diced by VICTOR.',
|
||||||
'$victim was split from crotch to sternum by $victor.',
|
'VICTIM was split from crotch to sternum by VICTOR.',
|
||||||
'$victim\'s death put another notch in $victor\'s axe.',
|
'VICTIM\'s death put another notch in VICTOR\'s axe.',
|
||||||
'$victim died impossibly!',
|
'VICTIM died impossibly!',
|
||||||
'$victim died from $victor\'s mysterious tropical disease.',
|
'VICTIM died from VICTOR\'s mysterious tropical disease.',
|
||||||
'$victim escaped infection by dying.',
|
'VICTIM escaped infection by dying.',
|
||||||
'$victim played hot-potato with a grenade.',
|
'VICTIM played hot-potato with a grenade.',
|
||||||
'$victim was knifed by $victor.',
|
'VICTIM was knifed by VICTOR.',
|
||||||
'$victim fell on his sword.',
|
'VICTIM fell on his sword.',
|
||||||
'$victim ate a grenade.',
|
'VICTIM ate a grenade.',
|
||||||
'$victim practiced being $victor\'s clay pigeon.',
|
'VICTIM practiced being VICTOR\'s clay pigeon.',
|
||||||
'$victim is what\'s for dinner!',
|
'VICTIM is what\'s for dinner!',
|
||||||
'$victim was terminated by $victor.',
|
'VICTIM was terminated by VICTOR.',
|
||||||
'$victim was shot before being thrown out of a plane.',
|
'VICTIM was shot before being thrown out of a plane.',
|
||||||
'$victim was not invincible.',
|
'VICTIM was not invincible.',
|
||||||
'$victim has encountered an error.',
|
'VICTIM has encountered an error.',
|
||||||
'$victim died and reincarnated as a goat.',
|
'VICTIM died and reincarnated as a goat.',
|
||||||
'$victor threw $victim off a building.',
|
'VICTOR threw VICTIM off a building.',
|
||||||
'$victim is sleeping with the fishes.',
|
'VICTIM is sleeping with the fishes.',
|
||||||
'$victim got a premature burial.',
|
'VICTIM got a premature burial.',
|
||||||
'$victor replaced all of $victim\'s music with Nickelback.',
|
'VICTOR replaced all of VICTIM\'s music with Nickelback.',
|
||||||
'$victor spammed $victim\'s email.',
|
'VICTOR spammed VICTIM\'s email.',
|
||||||
'$victor made $victim a knuckle sandwich.',
|
'VICTOR made VICTIM a knuckle sandwich.',
|
||||||
'$victor slapped $victim with pure nothing.',
|
'VICTOR slapped VICTIM with pure nothing.',
|
||||||
'$victor hit $victim with a small, interstellar spaceship.',
|
'VICTOR hit VICTIM with a small, interstellar spaceship.',
|
||||||
'$victim was quickscoped by $victor.',
|
'VICTIM was quickscoped by VICTOR.',
|
||||||
'$victor put $victim in check-mate.',
|
'VICTOR put VICTIM in check-mate.',
|
||||||
'$victor RSA-encrypted $victim and deleted the private key.',
|
'VICTOR RSA-encrypted VICTIM and deleted the private key.',
|
||||||
'$victor put $victim in the friendzone.',
|
'VICTOR put VICTIM in the friendzone.',
|
||||||
'$victor slaps $victim with a DMCA takedown request!',
|
'VICTOR slaps VICTIM with a DMCA takedown request!',
|
||||||
'$victim became a corpse blanket for $victor.',
|
'VICTIM became a corpse blanket for VICTOR.',
|
||||||
'Death is when the monsters get you. Death comes for $victim.',
|
'Death is when the monsters get you. Death comes for VICTIM.',
|
||||||
'Cowards die many times before their death. $victim never tasted death but once.'
|
'Cowards die many times before their death. VICTIM never tasted death but once.'
|
||||||
}
|
}
|
||||||
|
|
||||||
local action = function(msg)
|
local action = function(msg)
|
||||||
|
|
||||||
local nicks = load_data('nicknames.json')
|
|
||||||
|
|
||||||
local victim = msg.text:input()
|
local victim = msg.text:input()
|
||||||
if msg.reply_to_message then
|
if msg.reply_to_message then
|
||||||
if nicks[tostring(msg.reply_to_message.from.id)] then
|
if database.nicknames[tostring(msg.reply_to_message.from.id)] then
|
||||||
victim = nicks[tostring(msg.reply_to_message.from.id)]
|
victim = database.nicknames[tostring(msg.reply_to_message.from.id)]
|
||||||
else
|
else
|
||||||
victim = msg.reply_to_message.from.first_name
|
victim = msg.reply_to_message.from.first_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local victor = msg.from.first_name
|
local victor = msg.from.first_name
|
||||||
if nicks[msg.from.id_str] then
|
if database.nicknames[msg.from.id_str] then
|
||||||
victor = nicks[msg.from.id_str]
|
victor = database.nicknames[msg.from.id_str]
|
||||||
end
|
end
|
||||||
|
|
||||||
if not victim then
|
if not victim then
|
||||||
@ -116,8 +114,8 @@ local action = function(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local message = slaps[math.random(#slaps)]
|
local message = slaps[math.random(#slaps)]
|
||||||
message = message:gsub('$victim', victim)
|
message = message:gsub('VICTIM', victim)
|
||||||
message = message:gsub('$victor', victor)
|
message = message:gsub('VICTOR', victor)
|
||||||
|
|
||||||
sendMessage(msg.chat.id, message)
|
sendMessage(msg.chat.id, message)
|
||||||
|
|
||||||
|
@ -32,9 +32,8 @@ local action = function(msg)
|
|||||||
|
|
||||||
local message = 'You are ' .. from_name .. ' and you are messaging ' .. to_name
|
local message = 'You are ' .. from_name .. ' and you are messaging ' .. to_name
|
||||||
|
|
||||||
local nicks = load_data('nicknames.json')
|
if database.nicknames[msg.from.id_str] then
|
||||||
if nicks[msg.from.id_str] then
|
message = message .. '\nYour nickname is ' .. database.nicknames[msg.from.id_str] .. '.'
|
||||||
message = message .. '\nYour nickname is ' .. nicks[msg.from.id_str] .. '.'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sendReply(msg, message)
|
sendReply(msg, message)
|
||||||
|
@ -139,7 +139,7 @@ resolve_username = function(target)
|
|||||||
local input = tostring(target):lower()
|
local input = tostring(target):lower()
|
||||||
if input:match('^@') then
|
if input:match('^@') then
|
||||||
local uname = input:gsub('^@', '')
|
local uname = input:gsub('^@', '')
|
||||||
return usernames[uname]
|
return database.usernames[uname]
|
||||||
else
|
else
|
||||||
return tonumber(target) or false
|
return tonumber(target) or false
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user