Seen: per-channel (or privmsg speaker, i suppose) seen data
now mean words in one channel aren't leaked via !seen in another
This commit is contained in:
parent
fe305f4388
commit
476bd92010
@ -51,16 +51,40 @@ class Seen(Module):
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
if version < 2:
|
||||
db = self.get_db()
|
||||
try:
|
||||
version = 2
|
||||
db.execute('''DROP TABLE seen_nicks''')
|
||||
db.execute('''
|
||||
CREATE TABLE seen_nicks (
|
||||
nick TEXT NOT NULL,
|
||||
location TEXT NOT NULL,
|
||||
host TEXT NOT NULL,
|
||||
time TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
what TEXT NOT NULL
|
||||
)''')
|
||||
db.execute('''
|
||||
CREATE UNIQUE INDEX seen_nicks_nick_and_location_index
|
||||
ON seen_nicks (nick, location)''')
|
||||
db.commit()
|
||||
self.db_register_module_version(self.__class__.__name__, version)
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
def do(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||
"""Track pubmsg/privmsg events, and if asked, report on someone."""
|
||||
|
||||
where = event.target()
|
||||
|
||||
# whatever it is, store it
|
||||
try:
|
||||
db = self.get_db()
|
||||
cur = db.cursor()
|
||||
statement = 'REPLACE INTO seen_nicks (nick, host, what) VALUES (?, ?, ?)'
|
||||
cur.execute(statement, (nick, userhost, what.decode('utf-8', 'replace')))
|
||||
statement = 'REPLACE INTO seen_nicks (nick, location, host, what) VALUES (?, ?, ?, ?)'
|
||||
cur.execute(statement, (nick, where, userhost, what.decode('utf-8', 'replace')))
|
||||
db.commit()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
@ -72,12 +96,12 @@ class Seen(Module):
|
||||
nick = match.group(1)
|
||||
try:
|
||||
db = self.get_db()
|
||||
query = 'SELECT * FROM seen_nicks WHERE nick = ?'
|
||||
cursor = db.execute(query, (nick,))
|
||||
query = 'SELECT * FROM seen_nicks WHERE nick = ? AND location = ?'
|
||||
cursor = db.execute(query, (nick,where))
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
seentime = datetime.strptime(result['time'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=tzutc())
|
||||
replystr = 'last saw {0:s} at {1:s} saying \'{2:s}\''.format(result['nick'], seentime.astimezone(tzlocal()).strftime('%Y/%m/%d %H:%M:%S %Z'), result['what'].encode('utf-8', 'ignore'))
|
||||
replystr = 'last saw {0:s} in {3:s} at {1:s} saying \'{2:s}\''.format(result['nick'], seentime.astimezone(tzlocal()).strftime('%Y/%m/%d %H:%M:%S %Z'), result['what'].encode('utf-8', 'ignore'), result['location'].encode('utf-8', 'ignore'))
|
||||
return self.reply(connection, event, replystr)
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
|
Loading…
Reference in New Issue
Block a user