~stefanor/ibid/pandoc-man-511899

« back to all changes in this revision

Viewing changes to ibid/plugins/identity.py

2nd phase of plugin regorganisation:
* New 2-level feature categorisation system:
  Processor -> 1+ features
  feature -> 1+ categories
* Revamped help.
  Word stemming in category and feature search
  Usage is now a Processor attribute rather than docstring.
https://code.launchpad.net/~ibid-core/ibid/feature-discovery-399667/+merge/19785

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
from ibid.utils import human_join
15
15
from ibid.auth import hash
16
16
 
17
 
help = {}
 
17
features = {}
18
18
identify_cache = {}
19
19
 
20
20
log = logging.getLogger('plugins.identity')
21
21
 
22
 
help['accounts'] = u'An account represents a person. ' \
23
 
        'An account has one or more identities, which is a user on a specific source.'
 
22
features['accounts'] = {
 
23
    'description': u'Manage users accounts with the bot. An account represents '
 
24
                   u'a person. An account has one or more identities, which is '
 
25
                   u'a user on a specific source.',
 
26
    'categories': ('admin', 'account',),
 
27
}
24
28
class Accounts(Processor):
25
 
    u"""create account [<name>]
 
29
    usage = u"""create account [<name>]
26
30
    delete (my account|account <name>)
27
31
    rename (my account|account <name>) to <name>"""
28
 
    feature = 'accounts'
 
32
    feature = ('accounts',)
29
33
 
30
34
    @match(r'^create\s+account(?:\s+(.+))?$')
31
35
    def new_account(self, event, username):
140
144
chars = [x for x in string.letters + string.digits if x not in '01lOIB86G']
141
145
 
142
146
class Identities(Processor):
143
 
    u"""(I am|<username> is) <identity> on <source>
 
147
    usage = u"""(I am|<username> is) <identity> on <source>
144
148
    remove identity <identity> on <source> [from <username>]"""
145
 
    feature = 'accounts'
 
149
    feature = ('accounts',)
146
150
    priority = -10
147
151
 
148
152
    def __init__(self, name):
314
318
                    account.username, event.account, event.identity, event.sender['connection'])
315
319
 
316
320
class Attributes(Processor):
317
 
    u"""set (my|<account>) <name> to <value>"""
318
 
    feature = 'accounts'
 
321
    usage = u'set (my|<account>) <name> to <value>'
 
322
    feature = ('accounts',)
319
323
 
320
324
    @match(r"^set\s+(my|.+?)(?:\'s)?\s+(.+)\s+to\s+(.+)$")
321
325
    def attribute(self, event, username, name, value):
348
352
                event.identity, event.sender['connection'])
349
353
 
350
354
class Describe(Processor):
351
 
    u"""who (am I|is <username>)"""
352
 
    feature = "accounts"
 
355
    usage = u'who (am I|is <username>)'
 
356
    feature = ('accounts',)
353
357
 
354
358
    @match(r'^who\s+(?:is|am)\s+(I|.+?)$')
355
359
    def describe(self, event, username):
374
378
            'identities': human_join(u'%s on %s' % (identity.identity, identity.source) for identity in account.identities),
375
379
        })
376
380
 
377
 
help['summon'] = u"Get the attention of a person via different source"
 
381
features['summon'] = {
 
382
    'description': u'Get the attention of a person via different source',
 
383
    'categories': ('message',),
 
384
}
378
385
class Summon(Processor):
379
 
    u"summon <person> [via <source>]"
380
 
    feature = 'summon'
 
386
    usage = u'summon <person> [via <source>]'
 
387
    feature = ('summon',)
381
388
    permission = u'summon'
382
389
 
383
390
    default_source = Option('default_source',
495
502
 
496
503
actions = {'revoke': 'Revoked', 'grant': 'Granted', 'remove': 'Removed'}
497
504
 
498
 
help['auth'] = u'Adds and removes authentication credentials and permissions'
 
505
features['auth'] = {
 
506
    'description': u'Adds and removes authentication credentials and '
 
507
                   u'permissions',
 
508
    'categories': ('admin', 'account',),
 
509
}
499
510
class AddAuth(Processor):
500
 
    u"""authenticate <account> [on source] using <method> [<credential>]"""
501
 
    feature = 'auth'
 
511
    usage = u'authenticate <account> [on source] using <method> [<credential>]'
 
512
    feature = ('auth',)
502
513
 
503
514
    @match(r'^authenticate\s+(.+?)(?:\s+on\s+(.+))?\s+using\s+(\S+)\s+(.+)$')
504
515
    def handler(self, event, user, source, method, credential):
543
554
 
544
555
permission_values = {'no': '-', 'yes': '+', 'auth': ''}
545
556
class Permissions(Processor):
546
 
    u"""(grant|revoke|remove) <permission> (to|from|on) <username> [when authed]
 
557
    usage = u"""(grant|revoke|remove) <permission> (to|from|on) <username> [when authed]
547
558
    permissions [for <username>]
548
559
    list permissions"""
549
 
    feature = 'auth'
 
560
    feature = ('auth',)
550
561
 
551
562
    permission = u'admin'
552
563
 
631
642
        event.addresponse(u'Permissions: %s', human_join(sorted(permissions)) or u'none')
632
643
 
633
644
class Auth(Processor):
634
 
    u"""auth <credential>"""
635
 
    feature = 'auth'
 
645
    usage = u'auth <credential>'
 
646
    feature = ('auth',)
636
647
 
637
648
    @match(r'^auth(?:\s+(.+))?$')
638
649
    def handler(self, event, password):