/usr/share/pyshared/gplugs/seen.py is in gozerbot 0.99.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | # Description: tracks when a nick is last seen
# Author: Wijnand 'tehmaze' Modderman
# Website: http://tehmaze.com
# License: BSD
from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.utils.log import rlog
from gozerbot.commands import cmnds
from gozerbot.datadir import datadir
from gozerbot.persist.pdod import Pdod
from gozerbot.persist.persistconfig import PersistConfig
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.tests import tests
import os, time
plughelp.add('seen', 'remember what people said for the last time')
cfg = PersistConfig()
cfg.define('tz', '+0100')
class Seen(Pdod):
def __init__(self):
self.datadir = datadir + os.sep + 'plugs' + os.sep + 'seen'
Pdod.__init__(self, os.path.join(self.datadir, 'seen.data'))
def handle_seen(self, bot, ievent):
if not ievent.args:
ievent.missing('<nick>')
return
nick = ievent.args[0].lower()
if not self.data.has_key(nick):
alts = [x for x in self.data.keys() if nick in x]
if alts:
alts.sort()
if len(alts) > 10:
nums = len(alts) - 10
alts = ', '.join(alts[:10]) + ' + %d others' % nums
else:
alts = ', '.join(alts)
ievent.reply('no logs for %s, however, I remember seeing: %s' % (nick, alts))
else:
ievent.reply('no logs for %s' % nick)
else:
text = self.data[nick]['text'] and ': %s' % self.data[nick]['text'] or ''
try:
ievent.reply('%s was last seen on %s at %s, %s%s' % (nick, self.data[nick]['server'],
time.strftime('%a, %d %b %Y %H:%M:%S '+ str(cfg.get('tz')), time.localtime(self.data[nick]['time'])),
self.data[nick]['what'], text))
except KeyError:
ievent.reply('%s was last seen at %s, %s%s' % (nick,
time.strftime('%a, %d %b %Y %H:%M:%S '+ str(cfg.get('tz')), time.localtime(self.data[nick]['time'])),
self.data[nick]['what'], text))
def privmsgcb(self, bot, ievent):
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': ievent.origtxt,
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'saying',
}
def joincb(self, bot, ievent):
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': '',
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'joining %s' % ievent.channel,
}
def partcb(self, bot, ievent):
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': ievent.txt,
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'parting %s' % ievent.channel,
}
def quitcb(self, bot, ievent):
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': ievent.txt,
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'quitting',
}
def xmppcb(self, bot, ievent):
if ievent.type == 'unavailable':
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': ievent.userhost,
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'saindo da sala %s' % ievent.channel,
}
else:
self.data[ievent.nick.lower()] = {
'time': time.time(),
'text': ievent.userhost,
'bot': bot.name,
'server': bot.server,
'channel': ievent.channel,
'what': 'entrando na sala %s' % ievent.channel,
}
def size(self):
return len(self.data.keys())
seen = None
def init():
global seen
seen = Seen()
callbacks.add('PRIVMSG', seen.privmsgcb)
callbacks.add('JOIN', seen.joincb)
callbacks.add('PART', seen.partcb)
callbacks.add('QUIT', seen.quitcb)
callbacks.add('Presence', seen.xmppcb)
cmnds.add('seen', seen.handle_seen, ['USER', 'CLOUD'])
tests.add('seen exec')
examples.add('seen', 'show last spoken txt of <nikc>', 'seen dunker')
return 1
def shutdown():
global seen
if seen:
seen.save()
del seen
def size():
global seen
return seen.size()
|