minetestbot-modules/seen.py

72 lines
2.0 KiB
Python
Raw Normal View History

2013-01-12 08:24:17 -08:00
#!/usr/bin/env python
"""
seen.py - Phenny Seen Module
Copyright 2008, Sean B. Palmer, inamidst.com
2013-10-22 11:35:33 -07:00
Modified by sfan5 2013
2013-01-12 08:24:17 -08:00
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import time
from tools import deprecated
2013-10-22 11:35:33 -07:00
import sqlite3
def opendb():
db = sqlite3.connect("seen.sqlite")
c = db.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS seen (nick text, channel text, time int)''')
c.close()
return db
2013-01-12 08:24:17 -08:00
def seen(phenny, input):
2013-10-22 11:35:33 -07:00
""".seen <nick> - Reports when <nick> was last seen."""
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
nick = input.group(2)
if not nick:
return phenny.reply("Need a nickname to search for...")
nick = nick.lower()
print("[LOG]: %s queried Seen Result for %s" % (input.nick,nick))
db = opendb()
c = db.cursor()
c.execute("SELECT channel, time FROM seen WHERE nick = ?", (nick,))
r = c.fetchone()
c.close()
db.close()
if r:
channel, t = r[0], r[1]
t = time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime(t))
msg = "%s was last seen at %s on %s" % (nick, t, channel)
phenny.reply(msg)
else:
phenny.reply("Sorry, I haven't seen %s around." % nick)
2013-01-12 08:24:17 -08:00
seen.rule = (['seen'], r'(\S+)')
2013-10-22 11:35:33 -07:00
def note(phenny, input):
db = opendb()
if input.sender.startswith('#'):
c = db.cursor()
c.execute("SELECT * FROM seen WHERE nick = ?", (input.nick.lower(),))
if c.fetchone() != None:
d = (input.sender, int(time.time()), input.nick.lower())
c.execute('UPDATE seen SET channel = ?, time = ? WHERE nick = ?', d)
else:
d = (input.nick.lower(), input.sender, int(time.time()))
c.execute('INSERT INTO seen VALUES (?,?,?)', d)
db.commit()
c.close()
db.close()
note.rule = r'.*'
note.priority = 'low'
2013-01-12 08:24:17 -08:00
if __name__ == '__main__':
print __doc__.strip()