Skip to content

Commit

Permalink
Modlog: Support logging to a SQLite database (#7513)
Browse files Browse the repository at this point in the history
* Modlog: Support logging to a SQLite database

Co-authored-by: Christopher Monsanto <chris@monsan.to>
  • Loading branch information
AnnikaCodes and monsanto committed Oct 30, 2020
1 parent af31d62 commit 2f130e8
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .eslintrc-no-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
{
"files": [
"./config/*.ts", "./data/**/*.ts", "./lib/*.ts", "./server/**/*.ts", "./sim/**/*.ts",
"./tools/set-import/*.ts", "./tools/modlog/*.ts", "./translations/**/*.ts"
"./tools/set-import/*.ts", "./tools/modlog/*.ts", "./translations/**/*.ts"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ npm-debug.log
package-lock.json
/tools/set-import/sets
databases/*.db*

*.o
*.o.dSYM
# Typescript build artifacts
.*-dist/
tools/set-import/importer.js
Expand Down
23 changes: 23 additions & 0 deletions databases/schemas/modlog.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE modlog (
modlog_id INTEGER NOT NULL PRIMARY KEY,
-- UNIX timestamp
timestamp INTEGER NOT NULL,
--- roomid OR global-roomid
roomid TEXT NOT NULL,
action TEXT NOT NULL,
visual_roomid TEXT,
action_taker_userid TEXT,
userid TEXT,
autoconfirmed_userid TEXT,
ip TEXT,
note TEXT
);

CREATE TABLE alts (
modlog_id INTEGER NOT NULL,
userid TEXT NOT NULL,
PRIMARY KEY (modlog_id, userid),
FOREIGN KEY (modlog_id) REFERENCES modlog(modlog_id)
) WITHOUT ROWID;

PRAGMA journal_mode=WAL;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"version": "0.11.3",
"main": ".sim-dist/index.js",
"dependencies": {
"@types/better-sqlite3": "^5.4.0",
"better-sqlite3": "^7.1.0",
"probe-image-size": "^5.0.0",
"sockjs": "0.3.20",
"sucrase": "^3.15.0"
Expand Down
6 changes: 5 additions & 1 deletion server/chat-commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,11 @@ export const commands: ChatCommands = {
if (manager.filename.startsWith(FS('.server-dist/modlog').path)) void manager.destroy();
}

Rooms.Modlog = require('../modlog').modlog;
const {Modlog} = require('../modlog');
Rooms.Modlog = new Modlog(
Rooms.MODLOG_PATH || 'logs/modlog',
Rooms.MODLOG_DB_PATH || `${__dirname}/../../databases/modlog.db`
);
this.sendReply("Modlog has been hot-patched.");
Rooms.Modlog.streams = streams;
Rooms.Modlog.sharedStreams = sharedStreams;
Expand Down

0 comments on commit 2f130e8

Please sign in to comment.