Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F625523
import.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
import.lua
View Options
--[[
Copyright 2020 Matthew Hesketh <matthew@matthewhesketh.com>
This code is licensed under the MIT. See LICENSE for details.
]]
local
import
=
{}
local
mattata
=
require
(
'mattata'
)
local
redis
=
require
(
'libs.redis'
)
function
import
:
init
()
import
.
commands
=
mattata
.
commands
(
self
.
info
.
username
):
command
(
'import'
).
table
import
.
help
=
'/import - Import administrative settings & toggled plugins from another mattata-administrated group.'
end
function
import
.
on_message
(
_
,
message
,
_
,
language
)
if
message
.
chat
.
type
~=
'supergroup'
then
return
mattata
.
send_reply
(
message
,
language
.
errors
.
supergroup
)
elseif
not
mattata
.
is_group_admin
(
message
.
chat
.
id
,
message
.
from
.
id
)
then
return
mattata
.
send_reply
(
message
,
language
.
errors
.
admin
)
end
local
input
=
mattata
.
input
(
message
.
text
)
if
not
input
then
return
mattata
.
send_reply
(
message
,
import
.
help
)
end
input
=
mattata
.
get_chat
(
input
)
if
not
input
then
return
mattata
.
send_reply
(
message
,
language
[
'import'
][
'1'
])
elseif
input
.
result
.
type
~=
'supergroup'
then
return
mattata
.
send_reply
(
message
,
language
[
'import'
][
'2'
])
end
local
current
=
redis
:
hgetall
(
'chat:'
..
message
.
chat
.
id
..
':settings'
)
local
settings
=
redis
:
hgetall
(
'chat:'
..
input
.
result
.
id
..
':settings'
)
for
k
,
_
in
pairs
(
current
)
do
if
k
~=
'use administration'
then
redis
:
hdel
(
'chat:'
..
message
.
chat
.
id
..
':settings'
,
k
)
end
end
for
k
,
v
in
pairs
(
settings
)
do
redis
:
hset
(
'chat:'
..
message
.
chat
.
id
..
':settings'
,
k
,
v
)
end
current
=
redis
:
smembers
(
'disabled_plugins:'
..
message
.
chat
.
id
)
local
plugins
=
redis
:
smembers
(
'disabled_plugins:'
..
input
.
result
.
id
)
for
_
,
v
in
pairs
(
current
)
do
redis
:
srem
(
'disabled_plugins:'
..
message
.
chat
.
id
,
v
)
end
for
_
,
v
in
pairs
(
plugins
)
do
redis
:
sadd
(
'disabled_plugins:'
..
message
.
chat
.
id
,
v
)
end
local
output
=
string.format
(
language
[
'import'
][
'3'
],
input
.
result
.
title
,
message
.
chat
.
title
)
return
mattata
.
send_message
(
message
.
chat
.
id
,
output
)
end
return
import
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 11:34 PM (10 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
132782
Default Alt Text
import.lua (2 KB)
Attached To
Mode
R69 mattata
Attached
Detach File
Event Timeline