summaryrefslogtreecommitdiff
path: root/plugins/admin.py
blob: cb9ee37b81e5205d8cdb214e08150bb2633d645d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from plugin import BasePlugin
from tabs import MucTab

class Plugin(BasePlugin):
    """
    Adds several convenient aliases to /affiliation and /role:
        /visitor
        /participant
        /moderator == /op
        /member == /voice
        /owner
        /admin
        /noaffiliation
    """
    def init(self):
        for role in ['visitor', 'participant' , 'moderator']:
            self.add_tab_command(MucTab, role, self.role(role),
                    '/%s <nick>\n%s: Set the role of a nick to %s.' %
                        (role, role.capitalize(), role), self.complete_nick)

        for aff in ['member', 'owner', 'admin']:
            self.add_tab_command(MucTab, aff, self.affiliation(aff),
                    '/%s <nick>\n%s: set the affiliation of a nick to %s' %
                        (aff, aff.capitalize(), aff), self.complete_nick)

        self.add_tab_command(MucTab, 'noaffiliation', self.affiliation('none'),
                    '/noaffiliation <nick>\nNoAffiliation: set the affiliation of a nick to none.',
                    self.complete_nick)
        self.add_tab_command(MucTab, 'voice', self.affiliation('member'),
                    '/voice <nick>\nVoice: set the affiliation of a nick to member.',
                    self.complete_nick)
        self.add_tab_command(MucTab, 'op', self.role('moderator'),
                    '/op <nick>\nOp: set the role of a nick to moderator.',
                    self.complete_nick)
        self.add_tab_command(MucTab, 'mute', self.role('visitor'),
                    '/mute <nick>\nMute: set the role of a nick to visitor.',
                    self.complete_nick)

    def role(self, role):
        return lambda args: self.core.current_tab().command_role(args+' '+role)

    def affiliation(self, affiliation):
        return lambda args: self.core.current_tab().command_affiliation(
                                    args+' '+affiliation)

    def complete_nick(self, the_input):
        tab = self.core.current_tab()
        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]
        return the_input.auto_completion(word_list, '')