def do_rebuild_all(): """ Rebuild all the message HTML blobs in the database. """ with utils.get_postgres() as conn, conn.cursor() as cur: cur.execute("SELECT id, time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname FROM log") rows = list(cur) for i, (key, time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname) in enumerate(rows): if i % 100 == 0: print("\r%d/%d" % (i, len(rows)), end='') specialuser = set(specialuser) if specialuser else set() emoteset = set(emoteset) if emoteset else set() html = yield from build_message_html(time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname) with utils.get_postgres() as conn, conn.cursor() as cur: cur.execute("UPDATE log SET messagehtml=%s WHERE id=%s", ( html, key, )) print("\r%d/%d" % (len(rows), len(rows)))
def do_clear_chat_log(time, nick): """ Mark a user's earlier posts as "deleted" in the chat log, for when a user is banned/timed out. """ with utils.get_postgres() as conn, conn.cursor() as cur: cur.execute("SELECT id, time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname FROM log WHERE source=%s AND time>=%s", ( nick, time - PURGE_PERIOD, )) rows = list(cur) for i, (key, time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname) in enumerate(rows): specialuser = set(specialuser) if specialuser else set() emoteset = set(emoteset) if emoteset else set() specialuser.add("cleared") html = yield from build_message_html(time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname) with utils.get_postgres() as conn, conn.cursor() as cur: cur.execute("UPDATE log SET specialuser=%s, messagehtml=%s WHERE id=%s", ( list(specialuser), html, key, ))
def do_log_chat(time, event, metadata): """ Add a new message to the chat log. """ # Don't log server commands like .timeout message = event.arguments[0] if message[0] in "./" and message[1:4].lower() != "me ": return source = irc.client.NickMask(event.source).nick html = yield from build_message_html( time, source, event.target, event.arguments[0], metadata.get("specialuser", []), metadata.get("usercolor"), metadata.get("emoteset", []), metadata.get("emotes"), metadata.get("display-name"), ) with utils.get_postgres() as conn, conn.cursor() as cur: cur.execute( "INSERT INTO log (time, source, target, message, specialuser, usercolor, emoteset, emotes, displayname, messagehtml) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ( time, source, event.target, event.arguments[0], list(metadata.get("specialuser", [])), metadata.get("usercolor"), list(metadata.get("emoteset", [])), metadata.get("emotes"), metadata.get("display-name"), html, ), )