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

« back to all changes in this revision

Viewing changes to build/lib/gozerplugs/plugs/timer.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:
1
 
# plugs/timer.py
2
 
#
3
 
#
4
 
 
5
 
""" do a timing of a command """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
from gozerbot.commands import cmnds
10
 
from gozerbot.examples import examples
11
 
from gozerbot.plugins import plugins
12
 
from gozerbot.plughelp import plughelp
13
 
import time
14
 
 
15
 
plughelp.add('timer', 'do a timing of a command')
16
 
 
17
 
def handle_timer(bot, ievent):
18
 
    """ do a timing of a command """
19
 
    if not ievent.rest:
20
 
        ievent.reply('<cmnd>')
21
 
        return
22
 
    ievent.txt = ievent.rest
23
 
    starttime = time.time()
24
 
    result = plugins.cmnd(bot, ievent, 60)
25
 
    stoptime = time.time()
26
 
    if not result:
27
 
        ievent.reply('no result for %s' % ievent.rest)
28
 
        return
29
 
    result.insert(0, "%s seconds ==>" % str(stoptime-starttime))
30
 
    ievent.reply(result)
31
 
 
32
 
cmnds.add('timer', handle_timer, ['USER', 'WEB'], allowqueue=False)
33
 
examples.add('timer', 'time a command', 'timer b http')