5
""" keep away messages """
7
__copyright__ = 'this file is in the public domain'
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
20
plughelp.add('away', "keep notice of who's away")
24
# use datadir/away as pickle file
25
awaydict = Persist(datadir + os.sep + 'away')
27
# see if data attribute is set otherwise init it
30
if not awaydict.data.has_key('enable'):
31
awaydict.data['enable'] = 0
36
if not awaydict.data['enable']:
37
rlog(0, 'away', 'away is disabled')
40
rlog(0, 'away', 'away is enabled')
41
callbacks.add('PRIVMSG', doaway, awaytest)
42
callbacks.add('PRIVMSG', doback, backtest)
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() == '&':
51
def doaway(bot, ievent):
53
if not users.allowed(ievent.userhost, 'USER'):
55
# use username of user giving the command
56
name = users.getname(ievent.userhost)
59
if awaydict.data.has_key((name, bot.name, ievent.channel)):
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()
66
def backtest(bot, ievent):
67
""" test if we should say hello """
68
if 'back' == ievent.txt.strip() or 're' == ievent.txt.strip():
71
def doback(bot, ievent):
73
if not users.allowed(ievent.userhost, 'USER'):
76
name = users.getname(ievent.userhost)
79
if not awaydict.data.has_key((name, bot.name, ievent.channel)):
81
ievent.reply("welcome back %s" % ievent.nick)
83
del awaydict.data[(name, bot.name, ievent.channel)]
88
def handle_awayenable(bot, ievent):
89
""" away-enable .. enable away """
90
awaydict.data['enable'] = 1
92
plugins.reload('gozerplugs.plugs', 'away')
93
ievent.reply('away enabled')
95
cmnds.add('away-enable', handle_awayenable, 'OPER')
96
examples.add('away-enable' , 'enable the away plugin', 'away-enable')
98
def handle_awaydisable(bot, ievent):
99
""" away-disable .. disable away """
100
awaydict.data['enable'] = 0
102
plugins.reload('gozerplugs.plugs', 'away')
103
ievent.reply('away disabled')
105
cmnds.add('away-disable', handle_awaydisable, 'OPER')
106
examples.add('away-disable', 'disable the away plugin', 'away-disable')