Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F623758
antispam.lua
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
antispam.lua
View Options
--[[
mattata v2.0 - Antispam Plugin
]]
local
plugin
=
{}
plugin
.
name
=
'antispam'
plugin
.
category
=
'admin'
plugin
.
description
=
'Configure antispam settings'
plugin
.
commands
=
{
'antispam'
}
plugin
.
help
=
'/antispam [text|sticker|photo|video|document|forward] <limit> - Set per-type message limits.'
plugin
.
group_only
=
true
plugin
.
admin_only
=
true
local
VALID_TYPES
=
{
text
=
true
,
sticker
=
true
,
photo
=
true
,
video
=
true
,
document
=
true
,
forward
=
true
,
audio
=
true
,
voice
=
true
,
gif
=
true
}
function
plugin
.
on_message
(
api
,
message
,
ctx
)
if
not
message
.
args
then
-- show current antispam settings
local
settings
=
ctx
.
db
.
call
(
'sp_get_chat_settings_like'
,
{
message
.
chat
.
id
,
'antispam_%'
})
local
output
=
'<b>Antispam settings:</b>
\n\n
'
if
settings
and
#
settings
>
0
then
for
_
,
row
in
ipairs
(
settings
)
do
local
msg_type
=
row
.
key
:
gsub
(
'antispam_'
,
''
)
output
=
output
..
string.format
(
'- %s: %s message(s) per 5 seconds
\n
'
,
msg_type
,
row
.
value
)
end
else
output
=
output
..
'No custom limits set. Default limits apply.
\n
'
end
output
=
output
..
'
\n
Usage: <code>/antispam <type> <limit></code>
\n
Types: text, sticker, photo, video, document, forward, audio, voice, gif
\n
'
output
=
output
..
'<code>/antispam <type> off</code> - Remove limit'
return
api
.
send_message
(
message
.
chat
.
id
,
output
,
{
parse_mode
=
'html'
})
end
local
msg_type
,
limit
=
message
.
args
:
lower
():
match
(
'^(%S+)%s+(.+)$'
)
if
not
msg_type
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Usage: /antispam <type> <limit|off>'
)
end
if
not
VALID_TYPES
[
msg_type
]
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Invalid type. Valid types: text, sticker, photo, video, document, forward, audio, voice, gif'
)
end
local
setting_key
=
'antispam_'
..
msg_type
if
limit
==
'off'
or
limit
==
'disable'
or
limit
==
'0'
then
ctx
.
db
.
call
(
'sp_delete_chat_setting'
,
{
message
.
chat
.
id
,
setting_key
})
return
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Antispam limit for <b>%s</b> has been removed.'
,
msg_type
),
{
parse_mode
=
'html'
})
end
limit
=
tonumber
(
limit
)
if
not
limit
or
limit
<
1
or
limit
>
100
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Limit must be a number between 1 and 100.'
)
end
ctx
.
db
.
call
(
'sp_upsert_chat_setting'
,
{
message
.
chat
.
id
,
setting_key
,
tostring
(
limit
)
})
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Antispam limit for <b>%s</b> set to <b>%d</b> message(s) per 5 seconds.'
,
msg_type
,
limit
),
{
parse_mode
=
'html'
})
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 9:35 PM (18 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
131500
Default Alt Text
antispam.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline