2013-04-12 21:34:11 +00:00
|
|
|
"""
|
|
|
|
This plugin adds several convenient aliases, to shorten
|
|
|
|
roles/affiliation management.
|
|
|
|
|
|
|
|
Aliases defined
|
|
|
|
---------------
|
|
|
|
|
|
|
|
All those commands take a nick or a JID as a parameter.
|
|
|
|
|
|
|
|
For roles
|
|
|
|
~~~~~~~~~
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
:sorted:
|
|
|
|
|
|
|
|
/visitor
|
|
|
|
/mute
|
|
|
|
Set the role to ``visitor``
|
|
|
|
|
|
|
|
/participant
|
|
|
|
Set the role to ``participant``
|
|
|
|
|
|
|
|
/moderator
|
|
|
|
/op
|
|
|
|
Set the role to ``moderator``
|
|
|
|
|
|
|
|
|
|
|
|
For affiliations
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
:sorted:
|
|
|
|
|
|
|
|
/admin
|
|
|
|
Set the affiliation to ``admin``
|
|
|
|
|
|
|
|
/member
|
|
|
|
/voice
|
|
|
|
Set the affiliation to ``member``
|
|
|
|
|
|
|
|
/noaffiliation
|
|
|
|
Set the affiliation to ``none``
|
|
|
|
|
|
|
|
/owner
|
|
|
|
Set the affiliation to ``owner``
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio.tabs import MucTab
|
2016-08-21 13:27:53 +00:00
|
|
|
from poezio.core.structs import Completion
|
2012-05-05 00:08:35 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2012-05-05 00:08:35 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
"""
|
|
|
|
Adds several convenient aliases to /affiliation and /role:
|
|
|
|
/visitor
|
|
|
|
/participant
|
|
|
|
/moderator == /op
|
|
|
|
/member == /voice
|
|
|
|
/owner
|
|
|
|
/admin
|
|
|
|
/noaffiliation
|
|
|
|
"""
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2012-05-05 00:08:35 +00:00
|
|
|
def init(self):
|
2018-08-15 11:13:17 +00:00
|
|
|
for role in ('visitor', 'participant', 'moderator'):
|
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
role,
|
|
|
|
self.role(role),
|
|
|
|
help='Set the role of a nick to %s' % role,
|
|
|
|
usage='<nick>',
|
|
|
|
short='Set the role to %s' % role,
|
|
|
|
completion=self.complete_nick)
|
2012-05-05 00:08:35 +00:00
|
|
|
|
2013-03-01 18:25:31 +00:00
|
|
|
for aff in ('member', 'owner', 'admin'):
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
aff,
|
|
|
|
self.affiliation(aff),
|
|
|
|
usage='<nick>',
|
|
|
|
help='Set the affiliation of a nick to %s' % aff,
|
|
|
|
short='Set the affiliation to %s' % aff,
|
|
|
|
completion=self.complete_nick)
|
|
|
|
|
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
'noaffiliation',
|
|
|
|
self.affiliation('none'),
|
|
|
|
usage='<nick>',
|
|
|
|
help='Set the affiliation of a nick to none.',
|
|
|
|
short='Set the affiliation to none.',
|
|
|
|
completion=self.complete_nick)
|
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
'voice',
|
|
|
|
self.affiliation('member'),
|
|
|
|
usage='<nick>',
|
|
|
|
help='Set the affiliation of a nick to member.',
|
|
|
|
short='Set the affiliation to member.',
|
|
|
|
completion=self.complete_nick)
|
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
'op',
|
|
|
|
self.role('moderator'),
|
|
|
|
usage='<nick>',
|
|
|
|
help='Set the role of a nick to moderator.',
|
|
|
|
short='Set the role to moderator.',
|
|
|
|
completion=self.complete_nick)
|
|
|
|
self.api.add_tab_command(
|
|
|
|
MucTab,
|
|
|
|
'mute',
|
|
|
|
self.role('visitor'),
|
|
|
|
usage='<nick>',
|
|
|
|
help='Set the role of a nick to visitor.',
|
|
|
|
short='Set the role to visitor.',
|
|
|
|
completion=self.complete_nick)
|
2012-05-05 00:08:35 +00:00
|
|
|
|
|
|
|
def role(self, role):
|
2021-02-16 19:16:31 +00:00
|
|
|
async def inner(args):
|
|
|
|
await self.api.current_tab().command_role(args + ' ' + role)
|
|
|
|
return inner
|
2012-05-05 00:08:35 +00:00
|
|
|
|
|
|
|
def affiliation(self, affiliation):
|
2021-02-16 19:16:31 +00:00
|
|
|
async def inner(args):
|
|
|
|
await self.api.current_tab().command_affiliation(args + ' ' + affiliation)
|
|
|
|
return inner
|
2012-05-05 00:08:35 +00:00
|
|
|
|
|
|
|
def complete_nick(self, the_input):
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2012-05-05 00:08:35 +00:00
|
|
|
compare_users = lambda x: x.last_talked
|
|
|
|
word_list = [user.nick for user in sorted(tab.users, key=compare_users, reverse=True)\
|
|
|
|
if user.nick != tab.own_nick]
|
2016-08-21 13:27:53 +00:00
|
|
|
return Completion(the_input.auto_completion, word_list, '')
|