~ubuntu-branches/ubuntu/precise/gozerbot/precise

« back to all changes in this revision

Viewing changes to debian/gozerbot/usr/lib/python2.5/site-packages/gozerplugs/plugs/core.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2008-06-02 19:26:39 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080602192639-3rn65nx4q1sgd6sy
Tags: 0.8.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
#
4
4
 
5
 
""" core bot commands """
6
 
 
7
5
__copyright__ = 'this file is in the public domain'
 
6
__gendocskip__ = ['userhostcache', ]
8
7
 
9
8
from gozerbot.generic import getwho, die, reboot, elapsedstring, \
10
 
reboot_stateful, gethgrev, getsvnrev
 
9
reboot_stateful, getversion
 
10
from gozerbot.exit import globalshutdown
11
11
from gozerbot.commands import cmnds
12
12
from gozerbot.examples import examples
13
13
from gozerbot.callbacks import callbacks
22
22
from gozerbot.partyline import partyline
23
23
from gozerbot.plughelp import plughelp
24
24
from gozerbot.eventhandler import mainhandler
 
25
from sets import Set
25
26
import time, threading, sys, re
26
27
 
27
28
plughelp.add('core', 'core commands for the bot')
32
33
plugins.whatperms())
33
34
 
34
35
cmnds.add('whatperms', handle_whatperms, ['USER', 'OPER', 'ANON'])
 
36
examples.add('whatperms', 'show what permissions are available', 'whatperms')
35
37
 
36
38
def handle_encoding(bot, ievent):
37
39
    """ show default encoding """
57
59
def handle_list(bot, ievent):
58
60
    """ list [<plugin>] .. list loaded plugins or list commands provided by \
59
61
        plugin """
60
 
    plugslist = plugins.list()
61
62
    try:
62
63
        what = ievent.args[0]
63
64
    except:
64
65
        # no arguments given .. show plugins
65
 
        result = []
66
 
        for i in plugslist:
67
 
            result.append(i.split('.')[-1])
68
 
        result.sort()
69
 
        ievent.reply('we have the following plugins: ', result)
 
66
        ievent.reply('\002loaded plugins:\002 ', plugins.list())
70
67
        return
71
68
    # show commands of <what> plugin
72
69
    result = []
92
89
 
93
90
def handle_available(bot, ievent):
94
91
    """ available .. show what plugins are available """
95
 
    ievent.reply('available plugins: ', plugins.available())
 
92
    l = Set(plugins.list())
 
93
    ondisk = Set(plugins.available())
 
94
    diff = list(ondisk - l)    
 
95
    diff.sort()
 
96
    ievent.reply('\002available plugins:\002 (reload to enable): ', diff)
96
97
 
97
98
cmnds.add('available', handle_available, ['USER', 'WEB', 'ANON'])
98
 
examples.add('available', 'show what plugins are available', 'available')
 
99
examples.add('available', 'show what plugins are available but not loaded \
 
100
(see the list command for loaded plugins)', 'available')
99
101
aliasset('avail', ' available')
100
102
aliasset('plugins', 'available')
101
103
 
102
104
def doquit(bot, ievent):
103
105
    """ quit .. quit the bot """
104
 
    global backupstop
105
 
    try:
106
 
        backupstop = 1
107
 
        fleet.exitall()
108
 
        plugins.exit()
109
 
    finally:
110
 
        die()
 
106
    globalshutdown()
111
107
 
112
108
cmnds.add('quit', doquit, 'OPER')
113
109
examples.add('quit', 'quit the bot', 'quit')
117
113
 
118
114
def handle_reboot(bot, ievent):
119
115
    """ reboot .. reboot the bot """
 
116
    ievent.reply('rebooting')
120
117
    global backupstop
121
118
    stateful = True
122
119
    if ievent.rest == 'cold':
123
120
        stateful = False
124
 
    ievent.reply('doing reboot')
125
 
    partyline.say_broadcast('rebooting')
126
121
    time.sleep(2)
127
122
    try: 
128
123
        backupstop = 1
147
142
plugins')
148
143
        return
149
144
    if not plugins.plugs.has_key(plugin):
150
 
        ievent.reply('no %s plugin is loaded .. see the list command for \
151
 
available plugins' % plugin)
 
145
        ievent.reply('no %s plugin is loaded .. see the available command for \
 
146
available plugins (reload to enable)' % plugin)
152
147
        return
153
148
    result = []
154
149
    for i, j in cmnds.iteritems():
291
286
    ievent.reply('whois command send')
292
287
 
293
288
cmnds.add('intro', handle_intro, 'OPER')
294
 
examples.add('intro', 'intro <nick>', 'intro dunker')
 
289
examples.add('intro', 'do a whois of <nick> to sync userhost into the \
 
290
userhost cache', 'intro dunker')
295
291
 
296
292
def handle_loglevel(bot, ievent):
297
293
    """ loglevel <level> .. get or set loglevel .. the lower the more the \
310
306
cmnds.add('loglevel', handle_loglevel,'OPER')
311
307
examples.add('loglevel', 'get/set current loglevel .. the lower the loglevel \
312
308
the more the bot logs', '1) loglevel 2) \
313
 
loglevel 0')
 
309
loglevel 100')
314
310
 
315
311
def handle_partylist(bot, ievent):
316
312
    """ partylist .. show users on partylist """
351
347
    ievent.reply("threads running: ", result)
352
348
 
353
349
cmnds.add('running', handle_running, ['USER', 'OPER', 'ANON'])
354
 
examples.add('running', 'show from which files threads are running', 'running')
 
350
examples.add('running', 'show running threads', 'running')
355
351
 
356
352
def handle_save(bot, ievent):
357
353
    """ save .. save data to disk """
358
 
    ievent.reply('saving ..')
 
354
    ievent.reply('saving')
359
355
    plugins.save()
360
356
    fleet.save()
361
357
    config.save()
366
362
 
367
363
def handle_version(bot, ievent):
368
364
    """ version .. show bot's version """
369
 
    version = config['version']
370
 
    rev = gethgrev()
371
 
    if rev:
372
 
        version += " HG revision %s" % rev
373
 
    else:
374
 
        rev = getsvnrev()
375
 
        if rev:
376
 
            version += " SVN revision %s" % rev
377
 
    ievent.reply(version)
 
365
    ievent.reply(getversion())
378
366
 
379
367
cmnds.add('version', handle_version, ['USER', 'WEB', 'JCOLL', 'ANON'])
380
368
examples.add('version', 'show version of the bot', 'version')
403
391
    try:
404
392
        what = ievent.args[0]
405
393
    except IndexError:
406
 
        ievent.reply('help <cmnd> or help <plugin> .. see the !available \
407
 
command for a list of available plugins')
 
394
        ievent.reply('help <cmnd> or help <plugin> .. see the !list \
 
395
command for a list of available plugins or see !available command for a list \
 
396
of plugins to be reloaded')
408
397
        return
409
398
    phelp = plughelp.get(what)
410
399
    cmndresult = []
591
580
            ievent.reply(what)
592
581
        return      
593
582
    if size:
594
 
        bot.output(ievent.printto, "%s (+%s)" % (what, size))
 
583
        bot.output(ievent.printto, "%s \002(+%s)\002" % (what, size))
595
584
    else:
596
585
        ievent.reply(what)
597
586
 
598
587
cmnds.add('more', handle_more, ['USER', 'ANON'])
599
 
examples.add('more', 'return txt from output cache', 'more')
 
588
examples.add('more', 'return txt from output cache', '1) more 2) more test')