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.persist import PlugPersist
17
from gozerbot.plughelp import plughelp
18
from gozerbot.tests import tests
21
plughelp.add('away', "keep notice of who's away")
25
# use datadir/away as pickle file
26
awaydict = PlugPersist('away.data')
28
# see if data attribute is set otherwise init it
31
if not awaydict.data.has_key('enable'):
32
awaydict.data['enable'] = 0
37
if not awaydict.data['enable']:
38
rlog(0, 'away', 'away is disabled')
41
rlog(0, 'away', 'away is enabled')
42
callbacks.add('PRIVMSG', doaway, awaytest)
43
callbacks.add('PRIVMSG', doback, backtest)
46
def awaytest(bot, ievent):
47
""" test if away callback should be called """
48
if (len(ievent.txt) > 1 and ievent.txt[-1] == '\001' and \
49
ievent.txt[-2] == '&' ) or ievent.txt.strip() == '&':
52
def doaway(bot, ievent):
54
if not users.allowed(ievent.userhost, 'USER'):
56
# use username of user giving the command
57
name = users.getname(ievent.userhost)
60
if awaydict.data.has_key((name, bot.name, ievent.channel)):
62
ievent.reply("ltrs %s" % ievent.nick)
63
# add away data to entry indexed by username, botname and channel
64
awaydict.data[(name, bot.name, ievent.channel)] = time.time()
67
def backtest(bot, ievent):
68
""" test if we should say hello """
69
if 'back' == ievent.txt.strip() or 're' == ievent.txt.strip():
72
def doback(bot, ievent):
74
if not users.allowed(ievent.userhost, 'USER'):
77
name = users.getname(ievent.userhost)
80
if not awaydict.data.has_key((name, bot.name, ievent.channel)):
82
ievent.reply("welcome back %s" % ievent.nick)
84
del awaydict.data[(name, bot.name, ievent.channel)]
89
def handle_awayenable(bot, ievent):
90
""" away-enable .. enable away """
91
awaydict.data['enable'] = 1
93
plugins.reload('gplugs', 'away')
94
ievent.reply('away enabled')
96
cmnds.add('away-enable', handle_awayenable, 'OPER', threaded=True)
97
examples.add('away-enable' , 'enable the away plugin', 'away-enable')
99
def handle_awaydisable(bot, ievent):
100
""" away-disable .. disable away """
101
awaydict.data['enable'] = 0
103
plugins.reload('gplugs', 'away')
104
ievent.reply('away disabled')
106
cmnds.add('away-disable', handle_awaydisable, 'OPER')
107
examples.add('away-disable', 'disable the away plugin', 'away-disable')
108
tests.add('away-enable --chan #dunkbots', 'enabled').fakein(':dunker!mekker@127.0.0.1 PRIVMSG #dunkbots :&').fakein(':dunker!mekker@127.0.0.1 PRIVMSG #dunkbots :re').add('away-disable --chan #dunkbots', 'disabled')