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

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/plugs/code.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
# plugs/code.py
 
2
#
 
3
#
 
4
 
 
5
""" code related commands. """
 
6
 
 
7
__copyright__ = 'this file is in the public domain'
 
8
 
 
9
# gozerbot imports
 
10
from gozerbot.redispatcher import rebefore, reafter
 
11
from gozerbot.commands import cmnds
 
12
from gozerbot.examples import examples
 
13
from gozerbot.utils.exception import exceptionlist
 
14
from gozerbot.plugins import plugins
 
15
from gozerbot.aliases import aliasset
 
16
from gozerbot.plughelp import plughelp
 
17
from gozerbot.tests import tests
 
18
 
 
19
plughelp.add('code', 'the code plugin provides code related commands')
 
20
 
 
21
def handle_showexceptions(bot, ievent):
 
22
 
 
23
    """ show exception list. """
 
24
 
 
25
    try:
 
26
        printto = ievent.args[0]
 
27
    except IndexError:
 
28
        printto = ievent.channel
 
29
    cp = list(exceptionlist)
 
30
    for exception in cp:
 
31
        bot.say(printto, exception, groupchat=False)
 
32
    if not exceptionlist:
 
33
        ievent.reply('no exceptions yet !')
 
34
 
 
35
cmnds.add('code-exceptions' , handle_showexceptions, 'OPER')
 
36
examples.add('code-exceptions', 'show exception list', '1) code-exceptions 2) code-exceptions bthate@gmail.com')
 
37
aliasset('exceptions', 'code-exceptions')
 
38
tests.add('code-exceptions')
 
39
 
 
40
def handle_funcnames(bot, ievent):
 
41
 
 
42
    """ show function names of a plugin. """
 
43
 
 
44
    try:
 
45
        plugname = ievent.args[0]
 
46
    except IndexError:
 
47
        ievent.missing('<plugname>')
 
48
        return
 
49
 
 
50
    if not plugins.exist(plugname):
 
51
        ievent.reply('no %s plugin exists' % plugname)
 
52
        return
 
53
 
 
54
    funcnames = []
 
55
    funcnames = rebefore.getfuncnames(plugname)
 
56
    funcnames += cmnds.getfuncnames(plugname)
 
57
    funcnames += reafter.getfuncnames(plugname)
 
58
 
 
59
    if funcnames:
 
60
        ievent.reply(funcnames, dot=True)
 
61
    else:
 
62
        ievent.reply("can't find funcnames for %s plugin" % plugname)
 
63
        
 
64
cmnds.add('code-funcnames', handle_funcnames, 'OPER')
 
65
examples.add('code-funcnames', 'show function names of a plugin', 'code-funcnames birthday')
 
66
aliasset('funcnames', 'code-funcnames')
 
67
tests.add('code-funcnames core', 'handle_version')