administration.lua: 1.9 - Added flag antihammer. Groups with

antihammer enabled will not be affected by global bans. However,
 users who are hammer'd from an antihammer group will also be
 banned locally. Bot will now also attempt to kick via bot API
 before using tg. Added autobanning after (default) 3 autokicks.
 Threshold onfigurable with antiflood. Autokick counters reset
 within twenty-four hours. Merged antisquig action into generic.
 There is no automatic migration; simply add the following to
 database.administration:
  autokick_timer = 0
  groups[*].flags[6] = false
  groups[*].autoban = 3
  groups[*].autokicks = {}

luarun.lua: Autoload more libraries by default, because the entire
 purpose of this plugin is for me to be lazy.

pun.lua: Added puns.

slap.lua: Added slaps.
This commit is contained in:
topkecleon 2016-05-19 02:34:24 -04:00
parent 523eb8eecd
commit 8dd43e6f37
4 changed files with 241 additions and 167 deletions

View File

@ -1,6 +1,6 @@
--[[ --[[
administration.lua administration.lua
Version 1.8.3 Version 1.9
Part of the otouto project. Part of the otouto project.
© 2016 topkecleon <drew@otou.to> © 2016 topkecleon <drew@otou.to>
GNU General Public License, version 2 GNU General Public License, version 2
@ -13,20 +13,13 @@
Important notices about updates will be here! Important notices about updates will be here!
1.7 - Added antiflood (flag 5). Fixed security flaw. Renamed flag 3 1.9 - Added flag antihammer. Groups with antihammer enabled will not be
("antisquig Strict" -> "antisquig++"). Added /alist for governors to list affected by global bans. However, users who are hammer'd from an anti-
administrators. Back to single-governor groups as originally intended. Auto- hammer group will also be banned locally. Bot will now also attempt to kick
matic migration through 1.8. via bot API before using tg. Added autobanning after (default) 3 autokicks.
Threshold onfigurable with antiflood. Autokick counters reset within twenty-
four hours. Merged antisquig action into generic.
1.8 - Group descriptions will be updated automatically. Fixed markdown
stuff. Removed /kickme.
1.8.1 - /rule <i> will return that numbered rule, if it exists.
1.8.2 - Will now attempt to unban users kicked from supergroups. Other small
changes.
1.8.3 - Migrated to new plugin standard. Added /ahelp command to /desc.
]]-- ]]--
@ -43,7 +36,8 @@ function administration:init()
self.database.administration = { self.database.administration = {
admins = {}, admins = {},
groups = {}, groups = {},
activity = {} activity = {},
autokick_timer = os.date('%d')
} }
end end
@ -52,18 +46,6 @@ function administration:init()
flood = {} flood = {}
} }
-- Migration code: Remove this in v1.9.
-- Groups have single governors now.
for _,group in pairs(self.database.administration.groups) do
if group.govs then
for gov, _ in pairs(group.govs) do
group.governor = gov
break
end
end
group.govs = nil
end
drua.PORT = self.config.cli_port or 4567 drua.PORT = self.config.cli_port or 4567
administration.init_command(self) administration.init_command(self)
@ -108,6 +90,13 @@ administration.flags = {
enabled = 'Users will now be removed automatically for excessive messages. Use /antiflood to configure limits.', enabled = 'Users will now be removed automatically for excessive messages. Use /antiflood to configure limits.',
disabled = 'Users will no longer be removed automatically for excessive messages.', disabled = 'Users will no longer be removed automatically for excessive messages.',
kicked = 'You were automatically kicked from GROUPNAME for flooding.' kicked = 'You were automatically kicked from GROUPNAME for flooding.'
},
[6] = {
name = 'antihammer',
desc = 'Removes the ban on globally-banned users. Note that users hammered in this group will also be banned locally.',
short = 'This group does not acknowledge global bans.',
enabled = 'This group will no longer remove users for being globally banned.',
disabled = 'This group will now remove users for being globally banned.'
} }
} }
@ -135,9 +124,7 @@ administration.ranks = {
function administration:get_rank(target, chat) function administration:get_rank(target, chat)
target = tostring(target) target = tostring(target)
if chat then
chat = tostring(chat) chat = tostring(chat)
end
if tonumber(target) == self.config.admin or tonumber(target) == self.info.id then if tonumber(target) == self.config.admin or tonumber(target) == self.info.id then
return 5 return 5
@ -157,9 +144,16 @@ function administration:get_rank(target, chat)
end end
end end
-- I wrote a more succint statement, but I want to be able to make sense of
-- it. Basically, blacklisted users get 0, except when the group has flag 6
-- enabled.
if self.database.blacklist[target] then if self.database.blacklist[target] then
if chat and self.database.administration.groups[chat] and self.database.administration.groups[chat].flags[6] then
return 1
else
return 0 return 0
end end
end
return 1 return 1
@ -181,7 +175,7 @@ function administration:mod_format(id)
local name = utilities.build_name(user.first_name, user.last_name) local name = utilities.build_name(user.first_name, user.last_name)
name = utilities.markdown_escape(name) name = utilities.markdown_escape(name)
local output = '' .. name .. ' `[' .. id .. ']`\n' local output = '' .. name .. ' `[' .. id .. ']`\n'
return output return outputbb
end end
function administration:get_desc(chat_id) function administration:get_desc(chat_id)
@ -242,36 +236,17 @@ function administration:update_desc(chat)
drua.channel_set_about(chat, desc) drua.channel_set_about(chat, desc)
end end
function administration:kick_user(chat, target, reason)
if not bindings.kickChatMember(self, chat, target) then
drua.kick_user(chat, target)
end
utilities.handle_exception(self, target..' kicked from '..chat, reason)
end
function administration.init_command(self_) function administration.init_command(self_)
administration.commands = { administration.commands = {
{ -- antisquig { -- generic, mostly autokicks
triggers = {
'[\216-\219][\128-\191]', -- arabic
'', -- rtl
'', -- other rtl
},
privilege = 0,
interior = true,
action = function(self, msg, group)
if administration.get_rank(self, msg.from.id, msg.chat.id) > 1 then
return true
end
if not group.flags[2] then
return true
end
drua.kick_user(msg.chat.id, msg.from.id)
if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
end
local output = administration.flags[2].kicked:gsub('GROUPNAME', msg.chat.title)
bindings.sendMessage(self, msg.from.id, output)
end
},
{ -- generic
triggers = { '' }, triggers = { '' },
privilege = 0, privilege = 0,
@ -281,30 +256,44 @@ function administration.init_command(self_)
local rank = administration.get_rank(self, msg.from.id, msg.chat.id) local rank = administration.get_rank(self, msg.from.id, msg.chat.id)
-- banned local user = {
if rank == 0 then do_kick = false,
drua.kick_user(msg.chat.id, msg.from.id) do_ban = false
bindings.sendMessage(self, msg.from.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.') }
return
end
if rank < 2 then if rank < 2 then
-- antisquig Strict -- banned
if group.flags[3] == true then if rank == 0 then
if msg.from.name:match('[\216-\219][\128-\191]') or msg.from.name:match('') or msg.from.name:match('') then user.do_kick = true
drua.kick_user(msg.chat.id, msg.from.id) user.reason = 'banned'
if msg.chat.type == 'supergroup' then user.output = 'Sorry, you are banned from ' .. msg.chat.title .. '.'
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
end end
local output = administration.flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
bindings.sendMessage(self, msg.from.id, output) -- antisquig
return if group.flags[2] and (
msg.text:match('[\216-\219][\128-\191]')
or msg.text:match('')
or msg.text:match('')
) then
user.do_kick = true
user.reason = 'antisquig'
user.output = administration.flags[2].kicked:gsub('GROUPNAME', msg.chat.title)
end end
-- antisquig++
if group.flags[3] and (
msg.from.name:match('[\216-\219][\128-\191]')
or msg.from.name:match('')
or msg.from.name:match('')
) then
user.do_kick = true
user.reason = 'antisquig++'
user.output = administration.flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
end end
-- antiflood -- antiflood
if group.flags[5] == true then if group.flags[5] then
if not group.antiflood then if not group.antiflood then
group.antiflood = JSON.decode(JSON.encode(administration.antiflood)) group.antiflood = JSON.decode(JSON.encode(administration.antiflood))
end end
@ -314,73 +303,77 @@ function administration.init_command(self_)
if not self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] then if not self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = 0 self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = 0
end end
local user_flood = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str]
if msg.sticker then -- Thanks Brazil for discarding switches. if msg.sticker then -- Thanks Brazil for discarding switches.
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.sticker user_flood = user_flood + group.antiflood.sticker
elseif msg.photo then elseif msg.photo then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.photo user_flood = user_flood + group.antiflood.photo
elseif msg.document then elseif msg.document then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.document user_flood = user_flood + group.antiflood.document
elseif msg.audio then elseif msg.audio then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.audio user_flood = user_flood + group.antiflood.audio
elseif msg.contact then elseif msg.contact then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.contact user_flood = user_flood + group.antiflood.contact
elseif msg.video then elseif msg.video then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.video user_flood = user_flood + group.antiflood.video
elseif msg.location then elseif msg.location then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.location user_flood = user_flood + group.antiflood.location
elseif msg.voice then elseif msg.voice then
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.voice user_flood = user_flood + group.antiflood.voice
else else
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] + group.antiflood.text user_flood = user_flood + group.antiflood.text
end end
if self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] > 99 then if user_flood > 99 then
drua.kick_user(msg.chat.id, msg.from.id) user.do_kick = true
if msg.chat.type == 'supergroup' then user.reason = 'antiflood'
bindings.unbanChatMember(self, msg.chat.id, msg.from.id) user.output = administration.flags[5].kicked:gsub('GROUPNAME', msg.chat.title)
end user_flood = nil
local output = administration.flags[5].kicked:gsub('GROUPNAME', msg.chat.title)
bindings.sendMessage(self, msg.from.id, output)
self.admin_temp.flood[msg.chat.id_str][msg.from.id_str] = nil
return
end end
end end
end end
local new_user = user
if msg.new_chat_participant then if msg.new_chat_participant then
msg.new_chat_participant.name = utilities.build_name(msg.new_chat_participant.first_name, msg.new_chat_participant.last_name) -- We'll make a new table for the new guy, unless he's also
-- the original guy.
if msg.new_chat_participant.id ~= msg.from.id then
new_user = {
do_kick = false
}
end
-- I hate typing this out.
local newguy = msg.new_chat_participant
if administration.get_rank(self, msg.new_chat_participant.id, msg.chat.id) < 2 then
-- banned -- banned
if administration.get_rank(self, msg.new_chat_participant.id, msg.chat.id) == 0 then if administration.get_rank(self, newguy.id, msg.chat.id) == 0 then
drua.kick_user(msg.chat.id, msg.new_chat_participant.id) new_user.do_kick = true
bindings.sendMessage(self, msg.new_chat_participant.id, 'Sorry, you are banned from ' .. msg.chat.title .. '.') new_user.reason = 'banned'
return new_user.output = 'Sorry, you are banned from ' .. msg.chat.title .. '.'
end end
-- antisquig Strict -- antisquig++
if group.flags[3] == true then if group.flags[3] and (
if msg.new_chat_participant.name:match('[\216-\219][\128-\191]') or msg.new_chat_participant.name:match('') or msg.new_chat_participant.name:match('') then newguy.name:match('[\216-\219][\128-\191]')
drua.kick_user(msg.chat.id, msg.new_chat_participant.id) or newguy.name:match('')
if msg.chat.type == 'supergroup' then or newguy.name:match('')
bindings.unbanChatMember(self, msg.chat.id, msg.from.id) ) then
end new_user.do_kick = true
local output = administration.flags[3].kicked:gsub('GROUPNAME', msg.chat.title) new_user.reason = 'antisquig++'
bindings.sendMessage(self, msg.new_chat_participant.id, output) new_user.output = administration.flags[3].kicked:gsub('GROUPNAME', msg.chat.title)
return
end
end end
-- antibot -- antibot
if msg.new_chat_participant.username and msg.new_chat_participant.username:match('bot$') then if newguy.username and newguy.username:match('bot$') and group.flags[4] and rank < 2 then
if rank < 2 and group.flags[4] == true then new_user.do_kick = true
drua.kick_user(msg.chat.id, msg.new_chat_participant.id) new_user.reason = 'antibot'
return
end end
else
local output = administration.get_desc(self, msg.chat.id)
bindings.sendMessage(self, msg.new_chat_participant.id, output, true, nil, true)
return
end end
elseif msg.new_chat_title then elseif msg.new_chat_title then
@ -393,7 +386,6 @@ function administration.init_command(self_)
administration.update_desc(self, msg.chat.id) administration.update_desc(self, msg.chat.id)
end end
end end
return
elseif msg.new_chat_photo then elseif msg.new_chat_photo then
@ -406,7 +398,6 @@ function administration.init_command(self_)
else else
group.photo = drua.get_photo(msg.chat.id) group.photo = drua.get_photo(msg.chat.id)
end end
return
elseif msg.delete_chat_photo then elseif msg.delete_chat_photo then
@ -419,7 +410,60 @@ function administration.init_command(self_)
else else
group.photo = nil group.photo = nil
end end
return
end
if new_user ~= user then
if new_user.do_ban then
administration.kick_user(self, msg.chat.id, msg.new_chat_participant.id, new_user.reason)
if new_user.output then
bindings.sendMessage(self, msg.new_chat_participant.id, new_user.output)
end
group.bans[msg.new_chat_participant.id_str] = true
elseif new_user.do_kick then
administration.kick_user(self, msg.chat.id, msg.new_chat_participant.id, new_user.reason)
if new_user.output then
bindings.sendMessage(self, msg.new_chat_participant.id, new_user.output)
end
if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
end
end
end
if group.flags[5] and user.do_kick then
if group.autokicks[msg.from.id_str] then
group.autokicks[msg.from.id_str] = group.autokicks[msg.from.id_str] + 1
else
group.autokicks[msg.from.id_str] = 1
end
if group.autokicks[msg.from.id_str] >= group.autoban then
group.autokicks[msg.from.id_str] = 0
user.do_ban = true
user.reason = 'antiflood autoban'
user.output = 'You have been banned for being autokicked too many times.'
end
end
if user.do_ban then
administration.kick_user(self, msg.chat.id, msg.from.id, user.reason)
if user.output then
bindings.sendMessage(self, msg.from.id, user.output)
end
group.bans[msg.from.id_str] = true
elseif user.do_kick then
administration.kick_user(self, msg.chat.id, msg.from.id, user.reason)
if user.output then
bindings.sendMessage(self, msg.from.id, user.output)
end
if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
end
end
if msg.new_chat_participant and not (new_user.do_kick or new_user.do_ban) then
local output = administration.get_desc(self, msg.chat.id)
bindings.sendMessage(self, msg.new_chat_participant.id, output, true, nil, true)
end end
-- Last active time for group listing. -- Last active time for group listing.
@ -437,7 +481,7 @@ function administration.init_command(self_)
end end
}, },
{ -- groups { -- /groups
triggers = utilities.triggers(self_.info.username):t('groups').table, triggers = utilities.triggers(self_.info.username):t('groups').table,
command = 'groups', command = 'groups',
@ -465,7 +509,7 @@ function administration.init_command(self_)
end end
}, },
{ -- ahelp { -- /ahelp
triggers = utilities.triggers(self_.info.username):t('ahelp').table, triggers = utilities.triggers(self_.info.username):t('ahelp').table,
command = 'ahelp', command = 'ahelp',
@ -490,7 +534,7 @@ function administration.init_command(self_)
end end
}, },
{ -- alist { -- /alist
triggers = utilities.triggers(self_.info.username):t('ops'):t('oplist').table, triggers = utilities.triggers(self_.info.username):t('ops'):t('oplist').table,
command = 'ops', command = 'ops',
@ -519,7 +563,7 @@ function administration.init_command(self_)
}, },
{ -- desc { -- /desc
triggers = utilities.triggers(self_.info.username):t('desc'):t('description').table, triggers = utilities.triggers(self_.info.username):t('desc'):t('description').table,
command = 'description', command = 'description',
@ -538,7 +582,7 @@ function administration.init_command(self_)
end end
}, },
{ -- rules { -- /rules
triggers = utilities.triggers(self_.info.username):t('rules?', true).table, triggers = utilities.triggers(self_.info.username):t('rules?', true).table,
command = 'rules', command = 'rules',
@ -565,7 +609,7 @@ function administration.init_command(self_)
end end
}, },
{ -- motd { -- /motd
triggers = utilities.triggers(self_.info.username):t('motd').table, triggers = utilities.triggers(self_.info.username):t('motd').table,
command = 'motd', command = 'motd',
@ -581,7 +625,7 @@ function administration.init_command(self_)
end end
}, },
{ -- link { -- /link
triggers = utilities.triggers(self_.info.username):t('link').table, triggers = utilities.triggers(self_.info.username):t('link').table,
command = 'link', command = 'link',
@ -597,7 +641,7 @@ function administration.init_command(self_)
end end
}, },
{ -- kickme { -- /kickme
triggers = utilities.triggers(self_.info.username):t('leave'):t('kickme').table, triggers = utilities.triggers(self_.info.username):t('leave'):t('kickme').table,
command = 'kickme', command = 'kickme',
@ -609,14 +653,14 @@ function administration.init_command(self_)
bindings.sendReply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.') bindings.sendReply(self, msg, 'I can\'t let you do that, '..msg.from.name..'.')
return return
end end
drua.kick_user(msg.chat.id, msg.from.id) administration.kick_user(self, msg.chat.id, msg.from.id, 'kickme')
if msg.chat.type == 'supergroup' then if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, msg.chat.id, msg.from.id) bindings.unbanChatMember(self, msg.chat.id, msg.from.id)
end end
end end
}, },
{ -- kick { -- /kick
triggers = utilities.triggers(self_.info.username):t('kick', true).table, triggers = utilities.triggers(self_.info.username):t('kick', true).table,
command = 'kick <user>', command = 'kick <user>',
@ -632,7 +676,7 @@ function administration.init_command(self_)
bindings.sendReply(self, msg, target.name .. ' is too privileged to be kicked.') bindings.sendReply(self, msg, target.name .. ' is too privileged to be kicked.')
return return
end end
drua.kick_user(msg.chat.id, target.id) administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. msg.from.id)
if msg.chat.type == 'supergroup' then if msg.chat.type == 'supergroup' then
bindings.unbanChatMember(self, msg.chat.id, target.id) bindings.unbanChatMember(self, msg.chat.id, target.id)
end end
@ -640,7 +684,7 @@ function administration.init_command(self_)
end end
}, },
{ -- ban { -- /ban
triggers = utilities.triggers(self_.info.username):t('ban', true):t('unban', true).table, triggers = utilities.triggers(self_.info.username):t('ban', true):t('unban', true).table,
command = 'ban <user>', command = 'ban <user>',
@ -665,13 +709,13 @@ function administration.init_command(self_)
bindings.sendReply(self, msg, target.name .. ' has been unbanned.') bindings.sendReply(self, msg, target.name .. ' has been unbanned.')
else else
group.bans[target.id_str] = true group.bans[target.id_str] = true
drua.kick_user(msg.chat.id, target.id) administration.kick_user(self, msg.chat.id, target.id, ' banned by '..msg.from.id)
bindings.sendReply(self, msg, target.name .. ' has been banned.') bindings.sendReply(self, msg, target.name .. ' has been banned.')
end end
end end
}, },
{ -- changerule { -- /changerule
triggers = utilities.triggers(self_.info.username):t('changerule', true).table, triggers = utilities.triggers(self_.info.username):t('changerule', true).table,
command = 'changerule <i> <rule>', command = 'changerule <i> <rule>',
@ -721,7 +765,7 @@ function administration.init_command(self_)
end end
}, },
{ -- setrules { -- /setrules
triggers = utilities.triggers(self_.info.username):t('setrules', true).table, triggers = utilities.triggers(self_.info.username):t('setrules', true).table,
command = 'setrules <rules>', command = 'setrules <rules>',
@ -751,7 +795,7 @@ function administration.init_command(self_)
end end
}, },
{ -- setmotd { -- /setmotd
triggers = utilities.triggers(self_.info.username):t('setmotd', true).table, triggers = utilities.triggers(self_.info.username):t('setmotd', true).table,
command = 'setmotd <motd>', command = 'setmotd <motd>',
@ -783,7 +827,7 @@ function administration.init_command(self_)
end end
}, },
{ -- setlink { -- /setlink
triggers = utilities.triggers(self_.info.username):t('setlink', true).table, triggers = utilities.triggers(self_.info.username):t('setlink', true).table,
command = 'setlink <link>', command = 'setlink <link>',
@ -806,7 +850,7 @@ function administration.init_command(self_)
end end
}, },
{ -- alist { -- /alist
triggers = utilities.triggers(self_.info.username):t('alist').table, triggers = utilities.triggers(self_.info.username):t('alist').table,
command = 'alist', command = 'alist',
@ -823,7 +867,7 @@ function administration.init_command(self_)
end end
}, },
{ -- flags { -- /flags
triggers = utilities.triggers(self_.info.username):t('flags?', true).table, triggers = utilities.triggers(self_.info.username):t('flags?', true).table,
command = 'flag <i>', command = 'flag <i>',
@ -856,7 +900,7 @@ function administration.init_command(self_)
end end
}, },
{ -- antiflood { -- /antiflood
triggers = utilities.triggers(self_.info.username):t('antiflood', true).table, triggers = utilities.triggers(self_.info.username):t('antiflood', true).table,
command = 'antiflood <type> <i>', command = 'antiflood <type> <i>',
@ -875,10 +919,13 @@ function administration.init_command(self_)
local output local output
if input then if input then
local key, val = input:match('(%a+) (%d+)') local key, val = input:match('(%a+) (%d+)')
if not group.antiflood[key] or not tonumber(val) then if not key or not val or not tonumber(val) then
output = 'Not a valid message type or number.' output = 'Not a valid message type or number.'
elseif key == 'autoban' then
group.autoban = tonumber(val)
output = 'Users will now be autobanned after *' .. val .. '* autokicks.'
else else
group.antiflood[key] = val group.antiflood[key] = tonumber(val)
output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.' output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.'
end end
else else
@ -886,12 +933,13 @@ function administration.init_command(self_)
for k,v in pairs(group.antiflood) do for k,v in pairs(group.antiflood) do
output = output .. '*'..k..':* `'..v..'`\n' output = output .. '*'..k..':* `'..v..'`\n'
end end
output = output .. '\nUsers will be banned automatically after *' .. group.autoban .. '* autokicks. Configure this with the *autoban* keyword.'
end end
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true) bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
end end
}, },
{ -- mod { -- /mod
triggers = utilities.triggers(self_.info.username):t('mod', true):t('demod', true).table, triggers = utilities.triggers(self_.info.username):t('mod', true):t('demod', true).table,
command = 'mod <user>', command = 'mod <user>',
@ -924,7 +972,7 @@ function administration.init_command(self_)
end end
}, },
{ -- gov { -- /gov
triggers = utilities.triggers(self_.info.username):t('gov', true):t('degov', true).table, triggers = utilities.triggers(self_.info.username):t('gov', true):t('degov', true).table,
command = 'gov <user>', command = 'gov <user>',
@ -962,14 +1010,14 @@ function administration.init_command(self_)
end end
}, },
{ -- hammer { -- /hammer
triggers = utilities.triggers(self_.info.username):t('hammer', true):t('unhammer', true).table, triggers = utilities.triggers(self_.info.username):t('hammer', true):t('unhammer', true).table,
command = 'hammer <user>', command = 'hammer <user>',
privilege = 4, privilege = 4,
interior = false, interior = false,
action = function(self, msg) action = function(self, msg, group)
local target = administration.get_target(self, msg) local target = administration.get_target(self, msg)
if target.err then if target.err then
bindings.sendReply(self, msg, target.err) bindings.sendReply(self, msg, target.err)
@ -983,16 +1031,24 @@ function administration.init_command(self_)
self.database.blacklist[target.id_str] = nil self.database.blacklist[target.id_str] = nil
bindings.sendReply(self, msg, target.name .. ' has been globally unbanned.') bindings.sendReply(self, msg, target.name .. ' has been globally unbanned.')
else else
administration.kick_user(self, msg.chat.id, target.id, 'hammered by '..msg.from.id)
self.database.blacklist[target.id_str] = true self.database.blacklist[target.id_str] = true
for k,_ in pairs(self.database.administration.groups) do --for k,v in pairs(self.database.administration.groups) do
drua.kick_user(k, target.id) --if not v.flags[6] then
--administration.kick_user(self, k, target.id)
--end
--end
local output = target.name .. ' has been globally banned.'
if group.flags[6] == true then
group.bans[target.id_str] = true
output = target.name .. ' has been globally and locally banned.'
end end
bindings.sendReply(self, msg, target.name .. ' has been globally banned.') bindings.sendReply(self, msg, output)
end end
end end
}, },
{ -- admin { -- /admin
triggers = utilities.triggers(self_.info.username):t('admin', true):t('deadmin', true).table, triggers = utilities.triggers(self_.info.username):t('admin', true):t('deadmin', true).table,
command = 'admin <user>', command = 'admin <user>',
@ -1022,7 +1078,7 @@ function administration.init_command(self_)
end end
}, },
{ -- gadd { -- /gadd
triggers = utilities.triggers(self_.info.username):t('gadd').table, triggers = utilities.triggers(self_.info.username):t('gadd').table,
command = 'gadd', command = 'gadd',
@ -1044,10 +1100,12 @@ function administration.init_command(self_)
name = msg.chat.title, name = msg.chat.title,
link = drua.export_link(msg.chat.id), link = drua.export_link(msg.chat.id),
photo = drua.get_photo(msg.chat.id), photo = drua.get_photo(msg.chat.id),
founded = os.time() founded = os.time(),
autokicks = {},
autoban = 3
} }
administration.update_desc(self, msg.chat.id) administration.update_desc(self, msg.chat.id)
for i,_ in ipairs(administration.flags) do for i = 1, #administration.flags do
self.database.administration.groups[msg.chat.id_str].flags[i] = false self.database.administration.groups[msg.chat.id_str].flags[i] = false
end end
table.insert(self.database.administration.activity, msg.chat.id_str) table.insert(self.database.administration.activity, msg.chat.id_str)
@ -1055,7 +1113,7 @@ function administration.init_command(self_)
end end
}, },
{ -- grem { -- /grem
triggers = utilities.triggers(self_.info.username):t('grem', true):t('gremove', true).table, triggers = utilities.triggers(self_.info.username):t('grem', true):t('gremove', true).table,
command = 'gremove \\[chat]', command = 'gremove \\[chat]',
@ -1085,7 +1143,7 @@ function administration.init_command(self_)
end end
}, },
{ -- glist { -- /glist
triggers = utilities.triggers(self_.info.username):t('glist', false).table, triggers = utilities.triggers(self_.info.username):t('glist', false).table,
command = 'glist', command = 'glist',
@ -1113,7 +1171,7 @@ function administration.init_command(self_)
end end
}, },
{ -- broadcast { -- /broadcast
triggers = utilities.triggers(self_.info.username):t('broadcast', true).table, triggers = utilities.triggers(self_.info.username):t('broadcast', true).table,
command = 'broadcast <message>', command = 'broadcast <message>',
@ -1176,6 +1234,12 @@ end
function administration:cron() function administration:cron()
self.admin_temp.flood = {} self.admin_temp.flood = {}
if os.date('%d') ~= self.database.administration.autokick_timer then
self.database.administration.autokick_timer = os.date('%d')
for _,v in pairs(self.database.administration.groups) do
v.autokicks = {}
end
end
end end
administration.command = 'groups' administration.command = 'groups'

View File

@ -19,11 +19,17 @@ function luarun:action(msg)
return return
end end
local output = loadstring('local bindings = require(\'bindings\'); local utilities = require(\'utilities\'); return function (self, msg) '..input..' end')()(self, msg) local output = loadstring( [[
local bindings = require('bindings')
local utilities = require('utilities')
local JSON = require('dkjson')
local URL = require('socket.url')
local HTTP = require('socket.http')
local HTTPS = require('ssl.https')
return function (self, msg) ]] .. input .. [[ end
]] )()(self, msg)
if output == nil then if output == nil then
output = 'Done!' output = 'Done!'
elseif type(output) == 'table' then
output = 'Done! Table returned.'
else else
output = '```\n' .. tostring(output) .. '\n```' output = '```\n' .. tostring(output) .. '\n```'
end end

View File

@ -131,7 +131,9 @@ local puns = {
"Horses are very stable animals.", "Horses are very stable animals.",
"Banks don't crash, they just lose their balance.", "Banks don't crash, they just lose their balance.",
"The career of a skier can go downhill very fast.", "The career of a skier can go downhill very fast.",
"In democracy, it's your vote that counts. In feudalism, it's your count that votes." "In democracy, it's your vote that counts. In feudalism, it's your count that votes.",
"A sea lion is nothing but an ionized seal.",
"The vegetables from my garden aren't that great. I guess you could say they're mediokra."
} }
function pun:action(msg) function pun:action(msg)

View File

@ -94,7 +94,9 @@ local slaps = {
'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.',
'VICTIM died of hospital gangrene.',
'VICTIM got a house call from Doctor VICTOR.'
} }
function slap:action(msg) function slap:action(msg)