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

« back to all changes in this revision

Viewing changes to build/lib/gplugs/grab.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/grab.py
 
2
 
 
3
""" quotes grab plugin """
 
4
 
 
5
__copyright__ = 'this file is in the public domain'
 
6
__depend__ = ['quote', ]
 
7
 
 
8
from gozerbot.config import config
 
9
from gozerbot.commands import cmnds
 
10
from gozerbot.examples import examples
 
11
from gozerbot.aliases import aliases
 
12
from gozerbot.plughelp import plughelp
 
13
if config.get('db_driver') == "olddb": from gplugs.olddb.quote import quotes
 
14
else: from gplugs.alchemy.quote import quotes
 
15
from gozerbot.tests import tests
 
16
 
 
17
plughelp.add('grab', 'grab the last quote of an user')
 
18
 
 
19
def handle_quotegrab(bot, ievent):
 
20
    """ grab the last last from the given user """
 
21
    try:
 
22
        from gplugs.seen import seen
 
23
        assert(seen)
 
24
    except (ImportError, AssertionError, NameError):
 
25
        ievent.reply("seen plugin not enabled")
 
26
        return
 
27
    if not quotes:
 
28
        ievent.reply('quotes plugin not enabled')
 
29
        return
 
30
    if not ievent.args:
 
31
        ievent.reply('missing <user> argument')
 
32
        return
 
33
    nick = ievent.args[0].lower()
 
34
    if not seen.data.has_key(nick):
 
35
        ievent.reply('nothing said by %s recently' % nick)
 
36
        return
 
37
    idnr = quotes.add(nick, ievent.userhost, seen.data[nick]['text'])
 
38
    ievent.reply('grabbed %s from %s' % (idnr, nick))
 
39
 
 
40
cmnds.add('quote-grab', handle_quotegrab, ['USER', 'QUOTEADD'], allowqueue=False)
 
41
examples.add('quote-grab', 'quote-grab <user> .. add quote', 'quote-grab mekker')
 
42
aliases.data['grab'] = 'quote-grab'
 
43
tests.add('quote-grab')