~stefanor/ibid/pandoc-man-511899

« back to all changes in this revision

Viewing changes to ibid/plugins/fun.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:
12
12
from ibid.config import IntOption, ListOption
13
13
from ibid.utils import human_join
14
14
 
15
 
help = {}
 
15
features = {}
16
16
 
17
 
help['nickometer'] = u'Calculates how lame a nick is.'
 
17
features['nickometer'] = {
 
18
    'description': u'Calculates how lame a nick is.',
 
19
    'categories': ('fun', 'calculate',),
 
20
}
18
21
class Nickometer(Processor):
19
 
    u"""nickometer [<nick>] [with reasons]"""
20
 
    feature = 'nickometer'
 
22
    usage = u'nickometer [<nick>] [with reasons]'
 
23
    feature = ('nickometer',)
21
24
 
22
25
    @match(r'^(?:nick|lame)-?o-?meter(?:(?:\s+for)?\s+(.+?))?(\s+with\s+reasons)?$')
23
26
    def handle_nickometer(self, event, nick, wreasons):
36
39
                reasons = ((u'A good, traditional nick', 0),)
37
40
            event.addresponse(u'Because: %s', u', '.join(['%s (%s)' % reason for reason in reasons]))
38
41
 
39
 
help['choose'] = u'Choose one of the given options.'
 
42
features['choose'] = {
 
43
    'description': u'Choose one of the given options.',
 
44
    'categories': ('fun', 'decide',),
 
45
}
40
46
class Choose(Processor):
41
 
    u"""choose <choice> or <choice>..."""
42
 
    feature = 'choose'
 
47
    usage = u'choose <choice> or <choice>...'
 
48
    feature = ('choose',)
43
49
 
44
50
    choose_re = re.compile(r'(?:\s*,\s*(?:or\s+)?)|(?:\s+or\s+)', re.I)
45
51
 
47
53
    def choose(self, event, choices):
48
54
        event.addresponse(u'I choose %s', choice(self.choose_re.split(choices)))
49
55
 
50
 
help['coffee'] = u"Times coffee brewing and reserves cups for people"
 
56
features['coffee'] = {
 
57
    'description': u'Times coffee brewing and reserves cups for people',
 
58
    'categories': ('fun', 'monitor',),
 
59
}
51
60
class Coffee(Processor):
52
 
    u"""coffee (on|please)"""
53
 
    feature = 'coffee'
 
61
    usage = u'coffee (on|please)'
 
62
    feature = ('coffee',)
54
63
 
55
64
    pots = {}
56
65
 
98
107
            self.pots[(event.source, event.channel)].append(event.sender['nick'])
99
108
            event.addresponse(True)
100
109
 
101
 
help['insult'] = u"Slings verbal abuse at someone"
 
110
features['insult'] = {
 
111
    'description': u'Slings verbal abuse at someone',
 
112
    'categories': ('fun',),
 
113
}
102
114
class Insult(Processor):
103
 
    u"""
104
 
    (flame | insult) <person>
105
 
    (swear | cuss | explete) [at <person>]
106
 
    """
107
 
    feature = 'insult'
 
115
    usage = u"""(flame | insult) <person>
 
116
    (swear | cuss | explete) [at <person>]"""
 
117
    feature = ('insult',)
108
118
 
109
119
    adjectives = ListOption('adjectives', 'List of adjectives', (
110
120
        u'acidic', u'antique', u'artless', u'base-court', u'bat-fowling',