Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
199
Issues
199
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
cfb630ed
Commit
cfb630ed
authored
Feb 15, 2021
by
mathieui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
muctab: use more coroutines in affiliation/role code
parent
0221081b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
47 deletions
+43
-47
poezio/tabs/muctab.py
poezio/tabs/muctab.py
+43
-47
No files found.
poezio/tabs/muctab.py
View file @
cfb630ed
...
...
@@ -231,7 +231,7 @@ class MucTab(ChatTab):
muc
.
leave_groupchat
(
self
.
core
.
xmpp
,
self
.
jid
.
bare
,
self
.
own_nick
,
message
)
def
change_affiliation
(
async
def
change_affiliation
(
self
,
nick_or_jid
:
Union
[
str
,
JID
],
affiliation
:
str
,
...
...
@@ -266,10 +266,9 @@ class MucTab(ChatTab):
)
return
async
def
do_set_affiliation
(
room
:
JID
,
jid
:
JID
,
nick
:
Optional
[
str
],
affiliation
:
str
,
reason
:
str
):
try
:
await
self
.
core
.
xmpp
[
'xep_0045'
].
set_affiliation
(
room
,
self
.
jid
.
bare
,
nick
=
nick
,
jid
=
jid
,
affiliation
=
affiliation
,
...
...
@@ -285,11 +284,7 @@ class MucTab(ChatTab):
"Warning"
,
)
asyncio
.
ensure_future
(
do_set_affiliation
(
self
.
jid
.
bare
,
jid
,
nick
,
affiliation
,
reason
)
)
def
change_role
(
self
,
nick
:
str
,
role
:
str
,
reason
:
str
=
''
)
->
None
:
async
def
change_role
(
self
,
nick
:
str
,
role
:
str
,
reason
:
str
=
''
)
->
None
:
"""
Change the role of a nick
"""
...
...
@@ -308,16 +303,19 @@ class MucTab(ChatTab):
self
.
core
.
information
(
'Invalid nick'
,
'Info'
)
return
async
def
do_set_role
(
room
:
JID
,
nick
:
str
,
role
:
str
,
reason
:
str
):
try
:
await
self
.
core
.
xmpp
[
'xep_0045'
].
set_role
(
room
,
nick
,
role
,
reason
=
reason
)
await
self
.
core
.
xmpp
[
'xep_0045'
].
set_role
(
self
.
jid
.
bare
,
nick
,
role
=
role
,
reason
=
reason
)
self
.
core
.
information
(
f
'Role of
{
nick
}
changed to
{
role
}
successfully.'
'Info'
)
except
(
IqError
,
IqTimeout
)
as
e
:
self
.
core
.
information
(
"Could not set role '%s' for '%s': %s"
%
(
role
,
nick
,
e
),
"Warning"
)
asyncio
.
ensure_future
(
do_set_role
(
self
.
jid
.
bare
,
nick
,
role
,
reason
))
@
refresh_wrapper
.
conditional
def
print_info
(
self
,
nick
:
str
)
->
bool
:
"""Print information about a user"""
...
...
@@ -1623,7 +1621,7 @@ class MucTab(ChatTab):
self
.
input
.
refresh
()
@
command_args_parser
.
quoted
(
1
,
1
)
def
command_kick
(
self
,
args
:
List
[
str
])
->
None
:
async
def
command_kick
(
self
,
args
:
List
[
str
])
->
None
:
"""
/kick <nick> [reason]
"""
...
...
@@ -1635,10 +1633,10 @@ class MucTab(ChatTab):
else
:
reason
=
''
nick
=
args
[
0
]
self
.
change_role
(
nick
,
'none'
,
reason
)
await
self
.
change_role
(
nick
,
'none'
,
reason
)
@
command_args_parser
.
quoted
(
1
,
1
)
def
command_ban
(
self
,
args
:
List
[
str
])
->
None
:
async
def
command_ban
(
self
,
args
:
List
[
str
])
->
None
:
"""
/ban <nick> [reason]
"""
...
...
@@ -1647,29 +1645,27 @@ class MucTab(ChatTab):
return
nick
=
args
[
0
]
msg
=
args
[
1
]
if
len
(
args
)
==
2
else
''
self
.
change_affiliation
(
nick
,
'outcast'
,
msg
)
await
self
.
change_affiliation
(
nick
,
'outcast'
,
msg
)
@
command_args_parser
.
quoted
(
2
,
1
,
[
''
])
def
command_role
(
self
,
args
:
List
[
str
])
->
None
:
async
def
command_role
(
self
,
args
:
List
[
str
])
->
None
:
"""
/role <nick> <role> [reason]
Changes the role of a user
roles can be: none, visitor, participant, moderator
"""
def
callback
(
iq
:
Iq
)
->
None
:
if
iq
[
'type'
]
==
'error'
:
self
.
core
.
room_error
(
iq
,
self
.
jid
.
bare
)
if
args
is
None
:
self
.
core
.
command
.
help
(
'role'
)
return
nick
,
role
,
reason
=
args
[
0
],
args
[
1
].
lower
(),
args
[
2
]
self
.
change_role
(
nick
,
role
,
reason
)
try
:
await
self
.
change_role
(
nick
,
role
,
reason
)
except
IqError
as
iq
:
self
.
core
.
room_error
(
iq
,
self
.
jid
.
bare
)
@
command_args_parser
.
quoted
(
0
,
2
)
def
command_affiliation
(
self
,
args
:
List
[
str
])
->
None
:
async
def
command_affiliation
(
self
,
args
:
List
[
str
])
->
None
:
"""
/affiliation [<nick or jid> <affiliation>]
Changes the affiliation of a user
...
...
@@ -1683,7 +1679,7 @@ class MucTab(ChatTab):
# List affiliations
if
not
args
:
a
syncio
.
ensure_future
(
self
.
get_users_affiliations
(
room
)
)
a
wait
self
.
get_users_affiliations
(
room
)
return
None
if
len
(
args
)
!=
2
:
...
...
@@ -1692,7 +1688,7 @@ class MucTab(ChatTab):
nick
,
affiliation
=
args
[
0
],
args
[
1
].
lower
()
# Set affiliation
self
.
change_affiliation
(
nick
,
affiliation
)
await
self
.
change_affiliation
(
nick
,
affiliation
)
async
def
get_users_affiliations
(
self
,
jid
:
JID
)
->
None
:
owners
,
admins
,
members
,
outcasts
=
await
asyncio
.
gather
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment