Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F620956
feds.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
feds.lua
View Options
--[[
mattata v2.0 - Federation: feds / fedinfo
Shows info about a specific federation by ID, or the federation
the current chat belongs to.
]]
local
tools
=
require
(
'telegram-bot-lua.tools'
)
local
plugin
=
{}
plugin
.
name
=
'feds'
plugin
.
category
=
'admin'
plugin
.
description
=
'Show federation info.'
plugin
.
commands
=
{
'feds'
,
'fedinfo'
}
plugin
.
help
=
'/feds [federation_id] - Show info about a federation.
\n
/fedinfo [federation_id] - Alias for /feds.'
plugin
.
group_only
=
false
plugin
.
admin_only
=
false
local
function
get_chat_federation
(
db
,
chat_id
)
local
result
=
db
.
call
(
'sp_get_chat_federation'
,
{
chat_id
})
if
result
and
#
result
>
0
then
return
result
[
1
]
end
return
nil
end
function
plugin
.
on_message
(
api
,
message
,
ctx
)
local
fed_id
=
message
.
args
and
message
.
args
:
match
(
'^(%S+)'
)
local
fed
if
fed_id
and
fed_id
~=
''
then
local
result
=
ctx
.
db
.
call
(
'sp_get_federation'
,
{
fed_id
})
if
not
result
or
#
result
==
0
then
return
api
.
send_message
(
message
.
chat
.
id
,
'Federation not found. Please check the ID and try again.'
,
'html'
)
end
fed
=
result
[
1
]
elseif
ctx
.
is_group
then
fed
=
get_chat_federation
(
ctx
.
db
,
message
.
chat
.
id
)
if
not
fed
then
return
api
.
send_message
(
message
.
chat
.
id
,
'This chat is not part of any federation. Provide a federation ID to look up.
\n
Usage: <code>/feds <federation_id></code>'
,
'html'
)
end
local
full
=
ctx
.
db
.
call
(
'sp_get_federation'
,
{
fed
.
id
})
if
full
and
#
full
>
0
then
fed
.
created_at
=
full
[
1
].
created_at
end
else
return
api
.
send_message
(
message
.
chat
.
id
,
'Please specify a federation ID.
\n
Usage: <code>/feds <federation_id></code>'
,
'html'
)
end
local
counts
=
ctx
.
db
.
call
(
'sp_get_federation_counts'
,
{
fed
.
id
})
local
counts_row
=
(
counts
and
counts
[
1
])
or
{}
local
admins
=
tonumber
(
counts_row
.
admin_count
)
or
0
local
chats
=
tonumber
(
counts_row
.
chat_count
)
or
0
local
bans
=
tonumber
(
counts_row
.
ban_count
)
or
0
local
output
=
string.format
(
'<b>Federation Info</b>
\n\n
Name: <b>%s</b>
\n
ID: <code>%s</code>
\n
Owner: <code>%s</code>
\n
Admins: %d
\n
Chats: %d
\n
Bans: %d'
,
tools
.
escape_html
(
fed
.
name
),
tools
.
escape_html
(
fed
.
id
),
fed
.
owner_id
,
admins
,
chats
,
bans
)
if
fed
.
created_at
then
output
=
output
..
string.format
(
'
\n
Created: %s'
,
tools
.
escape_html
(
tostring
(
fed
.
created_at
)))
end
return
api
.
send_message
(
message
.
chat
.
id
,
output
,
'html'
)
end
return
plugin
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 6:37 PM (17 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
129843
Default Alt Text
feds.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline