Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F622106
joinfed.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
joinfed.lua
View Options
--[[
mattata v2.0 - Federation: joinfed
Joins the current chat to a federation. Requires group admin.
]]
local
tools
=
require
(
'telegram-bot-lua.tools'
)
local
plugin
=
{}
plugin
.
name
=
'joinfed'
plugin
.
category
=
'admin'
plugin
.
description
=
'Join this chat to a federation.'
plugin
.
commands
=
{
'joinfed'
}
plugin
.
help
=
'/joinfed <federation_id> - Join this chat to the specified federation.'
plugin
.
group_only
=
true
plugin
.
admin_only
=
true
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
fed_id
=
message
.
args
if
not
fed_id
or
fed_id
==
''
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Please specify the federation ID.
\n
Usage: <code>/joinfed <federation_id></code>'
,
{
parse_mode
=
'html'
}
)
end
fed_id
=
fed_id
:
match
(
'^(%S+)'
)
local
chat_id
=
message
.
chat
.
id
local
existing
=
ctx
.
db
.
call
(
'sp_get_chat_federation_joined'
,
{
chat_id
})
if
existing
and
#
existing
>
0
then
return
api
.
send_message
(
chat_id
,
string.format
(
'This chat is already part of the federation <b>%s</b>.
\n
Use /leavefed to leave it first.'
,
tools
.
escape_html
(
existing
[
1
].
name
)
),
{
parse_mode
=
'html'
}
)
end
local
fed
=
ctx
.
db
.
call
(
'sp_get_federation_basic'
,
{
fed_id
})
if
not
fed
or
#
fed
==
0
then
return
api
.
send_message
(
chat_id
,
'Federation not found. Please check the ID and try again.'
,
{
parse_mode
=
'html'
}
)
end
fed
=
fed
[
1
]
local
result
=
ctx
.
db
.
call
(
'sp_join_federation'
,
{
fed
.
id
,
chat_id
,
message
.
from
.
id
})
if
not
result
then
return
api
.
send_message
(
chat_id
,
'Failed to join the federation. Please try again later.'
,
{
parse_mode
=
'html'
}
)
end
return
api
.
send_message
(
chat_id
,
string.format
(
'This chat has joined the federation <b>%s</b>.'
,
tools
.
escape_html
(
fed
.
name
)
),
{
parse_mode
=
'html'
}
)
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 7:50 PM (10 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
132126
Default Alt Text
joinfed.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline