~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/plugs/all.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# gozerplugs/plugs/all.py
 
2
#
 
3
#
 
4
 
 
5
""" allow commands for all users. """
 
6
 
 
7
__gendoclast__ = ['all-del', ]
 
8
 
 
9
# gozerbot imports
 
10
from gozerbot.commands import cmnds
 
11
from gozerbot.aliases import aliasget
 
12
from gozerbot.examples import examples
 
13
from gozerbot.plughelp import plughelp
 
14
from gozerbot.tests import tests
 
15
 
 
16
plughelp.add('all', 'allow commands to be executed by all users')
 
17
 
 
18
def handle_alladd(bot, ievent):
 
19
 
 
20
    """ add a command to the allow all list. """
 
21
 
 
22
    if not ievent.rest:
 
23
        ievent.missing('<command>')
 
24
        return
 
25
 
 
26
    target = aliasget(ievent.rest) or ievent.rest
 
27
 
 
28
    if not 'OPER' in cmnds.perms(target):
 
29
        if target in bot.state['allowed']:
 
30
            ievent.reply('%s is already allowed' % target)
 
31
            return
 
32
        bot.state['allowed'].append(target)
 
33
        bot.state.save()
 
34
        ievent.reply('%s command is now allowed for all clients' % target)
 
35
    else:
 
36
        ievent.reply('sorry')
 
37
 
 
38
cmnds.add('all-add', handle_alladd, 'OPER')
 
39
examples.add('all-add', 'add command to be allowed by all users', 'all-add version')
 
40
tests.add('all-add version', 'version').add('all-del version')
 
41
 
 
42
def handle_alldel(bot, ievent):
 
43
 
 
44
    """ remove a command from the all allowed list. """
 
45
 
 
46
    if not ievent.rest:
 
47
        ievent.missing('<command>')
 
48
        return
 
49
 
 
50
    target = aliasget(ievent.rest) or ievent.rest
 
51
 
 
52
    if target in bot.state['allowed']:
 
53
        bot.state['allowed'].remove(target)
 
54
        ievent.reply('%s command is removed from allowed list' % target)
 
55
    else:
 
56
        ievent.reply('%s command is not in allowed list' % target)
 
57
 
 
58
cmnds.add('all-del', handle_alldel, 'OPER')
 
59
examples.add('all-del', 'remove command from the allowed list', 'all-del version')
 
60
tests.add('all-add version').add('all-del version', 'version')
 
61
 
 
62
def handle_alllist(bot, ievent):
 
63
 
 
64
    """ show the all allowed list. """
 
65
 
 
66
    ievent.reply('commands allowed: ', bot.state['allowed'], dot=True)
 
67
 
 
68
cmnds.add('all-list', handle_alllist, 'USER')
 
69
examples.add('all-list', 'list commands allowed by all users', 'all-list')
 
70
tests.add('all-add version').add('all-list', 'version').add('all-del version')