Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F623125
unfilter.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
unfilter.lua
View Options
--[[
mattata v2.0 - Unfilter Plugin
]]
local
plugin
=
{}
plugin
.
name
=
'unfilter'
plugin
.
category
=
'admin'
plugin
.
description
=
'Remove a content filter from the group'
plugin
.
commands
=
{
'unfilter'
,
'delfilter'
}
plugin
.
help
=
'/unfilter <pattern> - Removes a filter. Alias: /delfilter'
plugin
.
group_only
=
true
plugin
.
admin_only
=
true
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
tools
=
require
(
'telegram-bot-lua.tools'
)
if
not
message
.
args
then
-- List existing filters
local
filters
=
ctx
.
db
.
execute
(
'SELECT pattern, action FROM filters WHERE chat_id = $1 ORDER BY created_at'
,
{
message
.
chat
.
id
}
)
if
not
filters
or
#
filters
==
0
then
return
api
.
send_message
(
message
.
chat
.
id
,
'There are no filters set for this group.'
)
end
local
output
=
'<b>Active filters:</b>
\n\n
'
for
i
,
f
in
ipairs
(
filters
)
do
output
=
output
..
string.format
(
'%d. <code>%s</code> [%s]
\n
'
,
i
,
tools
.
escape_html
(
f
.
pattern
),
f
.
action
)
end
output
=
output
..
'
\n
Use /unfilter <pattern> to remove a filter.'
return
api
.
send_message
(
message
.
chat
.
id
,
output
,
'html'
)
end
local
pattern
=
message
.
args
:
match
(
'^%s*(.-)%s*$'
)
local
result
=
ctx
.
db
.
execute
(
'DELETE FROM filters WHERE chat_id = $1 AND pattern = $2'
,
{
message
.
chat
.
id
,
pattern
}
)
-- pgmoon returns the number of affected rows in the result
if
result
and
result
.
affected_rows
and
tonumber
(
result
.
affected_rows
)
>
0
then
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Filter <code>%s</code> has been removed.'
,
tools
.
escape_html
(
pattern
)
),
'html'
)
else
-- Try by index number
local
index
=
tonumber
(
pattern
)
if
index
then
local
filters
=
ctx
.
db
.
execute
(
'SELECT id, pattern FROM filters WHERE chat_id = $1 ORDER BY created_at'
,
{
message
.
chat
.
id
}
)
if
filters
and
filters
[
index
]
then
ctx
.
db
.
execute
(
'DELETE FROM filters WHERE id = $1'
,
{
filters
[
index
].
id
})
return
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'Filter <code>%s</code> has been removed.'
,
tools
.
escape_html
(
filters
[
index
].
pattern
)
),
'html'
)
end
end
api
.
send_message
(
message
.
chat
.
id
,
'That filter doesn
\'
t exist. Use /unfilter without arguments to see all filters.'
)
end
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 8:54 PM (16 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
136540
Default Alt Text
unfilter.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline