Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F626084
demote.lua
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
demote.lua
View Options
--[[
mattata v2.0 - Demote Plugin
]]
local
plugin
=
{}
plugin
.
name
=
'demote'
plugin
.
category
=
'admin'
plugin
.
description
=
'Remove moderator status from a user'
plugin
.
commands
=
{
'demote'
}
plugin
.
help
=
'/demote [user] - Removes moderator status from a user.'
plugin
.
group_only
=
true
plugin
.
admin_only
=
true
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
tools
=
require
(
'telegram-bot-lua.tools'
)
local
permissions
=
require
(
'src.core.permissions'
)
local
user_id
if
message
.
reply
and
message
.
reply
.
from
then
user_id
=
message
.
reply
.
from
.
id
elseif
message
.
args
then
user_id
=
message
.
args
:
match
(
'^@?(%S+)'
)
if
tonumber
(
user_id
)
==
nil
then
user_id
=
ctx
.
redis
.
get
(
'username:'
..
user_id
:
lower
())
end
end
user_id
=
tonumber
(
user_id
)
if
not
user_id
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Please specify the user to demote, either by replying to their message or providing a username/ID.'
)
end
if
not
permissions
.
is_group_mod
(
ctx
.
db
,
message
.
chat
.
id
,
user_id
)
then
return
api
.
send_message
(
message
.
chat
.
id
,
'That user is not a moderator.'
)
end
ctx
.
db
.
execute
(
"UPDATE chat_members SET role = 'member' WHERE chat_id = $1 AND user_id = $2"
,
{
message
.
chat
.
id
,
user_id
}
)
pcall
(
function
()
ctx
.
db
.
insert
(
'admin_actions'
,
{
chat_id
=
message
.
chat
.
id
,
admin_id
=
message
.
from
.
id
,
target_id
=
user_id
,
action
=
'demote'
})
end
)
local
admin_name
=
tools
.
escape_html
(
message
.
from
.
first_name
)
local
target_info
=
api
.
get_chat
(
user_id
)
local
target_name
=
target_info
and
target_info
.
result
and
tools
.
escape_html
(
target_info
.
result
.
first_name
)
or
tostring
(
user_id
)
api
.
send_message
(
message
.
chat
.
id
,
string.format
(
'<a href="tg://user?id=%d">%s</a> has demoted <a href="tg://user?id=%d">%s</a>.'
,
message
.
from
.
id
,
admin_name
,
user_id
,
target_name
),
'html'
)
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/html
Expires
Sun, Nov 15, 12:18 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
131777
Default Alt Text
demote.lua (1 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline