def handler(self, **args): """Report when someone was last seen.""" import database from alias import whois result = "" nick = " ".join(args["text"].split()[2:]) safenick = escape_quotes(nick.lower()) line = database.doSQL("SELECT nick, time, message, type " + \ "FROM seen WHERE nick = '" + safenick + \ "'") if (len(line) == 0): seentime = 0 joiner = "However, " result += "I don't think I've ever seen " + nick + ".\n" else: seentime = int(line[0][1]) joiner = "Also, " result += makeseenline("", line) realnick = escape_quotes(whois(nick)) line = database.doSQL("SELECT seen.nick, seen.time, seen.message, seen.type FROM seen, alias WHERE seen.time > " + str(seentime) + " AND seen.nick = alias.nick AND alias.realnick = '" + realnick + "' ORDER BY seen.time DESC LIMIT 1") if (len(line) > 0): result += makeseenline(joiner, line) from irclib import Event return Event("privmsg", "", self.return_to_sender(args), [ result ])
def handler(self, **args): """Report when someone was last seen.""" import database from alias import whois result = "" nick = " ".join(args["text"].split()[2:]) safenick = escape_quotes(nick.lower()) line = database.doSQL("SELECT nick, time, message, type " + \ "FROM seen WHERE nick = '" + safenick + \ "'") if (len(line) == 0): seentime = 0 joiner = "However, " result += "I don't think I've ever seen " + nick + ".\n" else: seentime = int(line[0][1]) joiner = "Also, " result += makeseenline("", line) realnick = escape_quotes(whois(nick)) line = database.doSQL( "SELECT seen.nick, seen.time, seen.message, seen.type FROM seen, alias WHERE seen.time > " + str(seentime) + " AND seen.nick = alias.nick AND alias.realnick = '" + realnick + "' ORDER BY seen.time DESC LIMIT 1") if (len(line) > 0): result += makeseenline(joiner, line) from irclib import Event return Event("privmsg", "", self.return_to_sender(args), [result])
def add_seen(hostmask, type, message): from irclib import nm_to_n from alias import whois import database, time message = escape_quotes(message) nick = escape_quotes(nm_to_n(hostmask)).lower() whois(nick) if len(database.doSQL("SELECT * FROM seen " + \ "WHERE nick = '" + nick + "'")) == 0: database.doSQL("INSERT INTO seen " + \ "(nick, hostmask, time, message, type)" + \ "VALUES('" + nick + "', '" + hostmask + \ "', " + str(int(time.time())) + ", '" + \ message + "', '" + type + "')") else: database.doSQL("UPDATE seen " + \ "SET hostmask = '" + hostmask + "', time = '" + \ str(int(time.time())) + "', message = '" + \ message + "', type = '" + type + "' " + \ "WHERE nick = '" + nick + "'")