mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-24 00:34:10 +00:00
Added some functions
This commit is contained in:
parent
69ff24fc99
commit
a8eeba8831
|
@ -1,8 +1,35 @@
|
||||||
from src.configloader import settings
|
from src.configloader import settings
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger("rcgcdw.message_redaction")
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
def create_schema():
|
def create_schema(cursor: sqlite3.Cursor):
|
||||||
|
logger.info("Creating database schema...")
|
||||||
|
cursor.executescript(
|
||||||
|
"""BEGIN TRANSACTION;
|
||||||
|
CREATE TABLE IF NOT EXISTS "messages" (
|
||||||
|
"message_id" TEXT,
|
||||||
|
"content" INTEGER
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS "event" (
|
||||||
|
"pageid" INTEGER,
|
||||||
|
"revid" INTEGER,
|
||||||
|
"logid" INTEGER,
|
||||||
|
"msg_id" TEXT NOT NULL,
|
||||||
|
FOREIGN KEY("msg_id") REFERENCES "messages"("message_id") ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
COMMIT;""")
|
||||||
|
logger.info("Database schema has been recreated.")
|
||||||
|
|
||||||
def create_connection():
|
def create_connection():
|
||||||
|
db_connection = sqlite3.connect(settings['auto_suppression'].get("db_location", ':memory:'))
|
||||||
|
db_cursor = db_connection.cursor()
|
||||||
|
return db_connection, db_cursor
|
||||||
|
|
||||||
|
def check_tables(cursor: sqlite3.Cursor):
|
||||||
|
rep = cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='messages';")
|
||||||
|
if not rep.fetchone():
|
||||||
|
create_schema(cursor)
|
||||||
|
|
||||||
|
def add_entry(pageid, revid, logid, message):
|
||||||
|
|
|
@ -397,10 +397,10 @@ def essential_info(change, changed_categories):
|
||||||
parsed_comment = _("~~hidden~~")
|
parsed_comment = _("~~hidden~~")
|
||||||
if not parsed_comment:
|
if not parsed_comment:
|
||||||
parsed_comment = None
|
parsed_comment = None
|
||||||
|
if "userhidden" in change:
|
||||||
|
change["user"] = _("hidden")
|
||||||
if change["type"] in ["edit", "new"]:
|
if change["type"] in ["edit", "new"]:
|
||||||
logger.debug("List of categories in essential_info: {}".format(changed_categories))
|
logger.debug("List of categories in essential_info: {}".format(changed_categories))
|
||||||
if "userhidden" in change:
|
|
||||||
change["user"] = _("hidden")
|
|
||||||
identification_string = change["type"]
|
identification_string = change["type"]
|
||||||
if change.get("ns", -1) in settings.get("ignored_namespaces", ()):
|
if change.get("ns", -1) in settings.get("ignored_namespaces", ()):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue