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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# plugs/away.py
2
 
#
3
 
4
 
 
5
 
""" keep away messages """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
from gozerbot.generic import rlog
10
 
from gozerbot.commands import cmnds
11
 
from gozerbot.examples import examples
12
 
from gozerbot.callbacks import callbacks
13
 
from gozerbot.users import users
14
 
from gozerbot.plugins import plugins
15
 
from gozerbot.datadir import datadir
16
 
from gozerbot.persist import Persist
17
 
from gozerbot.plughelp import plughelp
18
 
import time, os
19
 
 
20
 
plughelp.add('away', "keep notice of who's away")
21
 
 
22
 
lasttime = []
23
 
 
24
 
# use datadir/away as pickle file
25
 
awaydict = Persist(datadir + os.sep + 'away')
26
 
 
27
 
# see if data attribute is set otherwise init it
28
 
if not awaydict.data:
29
 
    awaydict.data = {}
30
 
if not awaydict.data.has_key('enable'):
31
 
    awaydict.data['enable'] = 0
32
 
    awaydict.save()
33
 
 
34
 
def init():
35
 
    """ init plugin """
36
 
    if not awaydict.data['enable']:
37
 
        rlog(0, 'away', 'away is disabled')
38
 
        return 1
39
 
    else:
40
 
        rlog(0, 'away', 'away is enabled')
41
 
    callbacks.add('PRIVMSG', doaway, awaytest)
42
 
    callbacks.add('PRIVMSG', doback, backtest)
43
 
    return 1
44
 
 
45
 
def awaytest(bot, ievent):
46
 
    """ test if away callback should be called """
47
 
    if (len(ievent.txt) > 1 and ievent.txt[-1] == '\001' and \
48
 
ievent.txt[-2] == '&' ) or ievent.txt.strip() == '&':
49
 
        return 1
50
 
        
51
 
def doaway(bot, ievent):
52
 
    """ away callback """
53
 
    if not users.allowed(ievent.userhost, 'USER'):
54
 
        return
55
 
    # use username of user giving the command
56
 
    name = users.getname(ievent.userhost)
57
 
    if not name:
58
 
        return
59
 
    if awaydict.data.has_key((name, bot.name, ievent.channel)):
60
 
        return
61
 
    ievent.reply("ltrs %s" % ievent.nick)
62
 
    # add away data to entry indexed by username, botname and channel
63
 
    awaydict.data[(name, bot.name, ievent.channel)] = time.time()
64
 
    awaydict.save()
65
 
 
66
 
def backtest(bot, ievent):
67
 
    """ test if we should say hello """
68
 
    if 'back' == ievent.txt.strip() or 're' == ievent.txt.strip():
69
 
        return 1
70
 
    
71
 
def doback(bot, ievent):
72
 
    """ say hello """
73
 
    if not users.allowed(ievent.userhost, 'USER'):
74
 
        return
75
 
    # reset away entry 
76
 
    name = users.getname(ievent.userhost)
77
 
    if not name:
78
 
        return
79
 
    if not awaydict.data.has_key((name, bot.name, ievent.channel)):
80
 
        return
81
 
    ievent.reply("welcome back %s" % ievent.nick)
82
 
    try:
83
 
        del awaydict.data[(name, bot.name, ievent.channel)]
84
 
        awaydict.save()
85
 
    except KeyError:
86
 
        pass
87
 
 
88
 
def handle_awayenable(bot, ievent):
89
 
    """ away-enable .. enable away """
90
 
    awaydict.data['enable'] = 1
91
 
    awaydict.save()
92
 
    plugins.reload('gozerplugs.plugs', 'away')
93
 
    ievent.reply('away enabled')
94
 
 
95
 
cmnds.add('away-enable', handle_awayenable, 'OPER')
96
 
examples.add('away-enable' , 'enable the away plugin', 'away-enable')
97
 
 
98
 
def handle_awaydisable(bot, ievent):
99
 
    """ away-disable .. disable away """
100
 
    awaydict.data['enable'] = 0
101
 
    awaydict.save()
102
 
    plugins.reload('gozerplugs.plugs', 'away')
103
 
    ievent.reply('away disabled')
104
 
 
105
 
cmnds.add('away-disable', handle_awaydisable, 'OPER')
106
 
examples.add('away-disable', 'disable the away plugin', 'away-disable')