Alerts
diff --git a/lib/actions.ts b/lib/actions.ts
index ebf97ae..f04b233 100644
--- a/lib/actions.ts
+++ b/lib/actions.ts
@@ -16,6 +16,7 @@ import { publishMessage, sendChatMessage } from "./redis";
import { ulid } from "ulid";
import {
AccountInfo,
+ AccountStrike,
Bot,
File,
Member,
@@ -41,6 +42,35 @@ export async function sendAlert(userId: string, content: string) {
});
}
+export async function createStrike(
+ userId: string,
+ givenReason: string,
+ additionalContext: string
+) {
+ const strike: AccountStrike & { moderator_id: string } = {
+ _id: ulid(),
+ user_id: userId,
+ moderator_id: "01EX2NCWQ0CHS3QJF0FEQS1GR4", // TODO
+ reason: additionalContext
+ ? givenReason + " - " + additionalContext
+ : givenReason,
+ };
+
+ await mongo()
+ .db("revolt")
+ .collection<{ _id: string }>("safety_strikes")
+ .insertOne(strike);
+ await sendAlert(
+ userId,
+ `You have received an account strike, for one or more reasons:
+- ${givenReason}
+
+Further violations will result in suspension or a permanent ban depending on severity, please abide by the [Acceptable Usage Policy](https://revolt.chat/aup).`
+ );
+
+ return strike;
+}
+
export async function updateReportNotes(reportId: string, notes: string) {
return await mongo()
.db("revolt")
diff --git a/lib/db.ts b/lib/db.ts
index ce0e80c..a495d8a 100644
--- a/lib/db.ts
+++ b/lib/db.ts
@@ -274,7 +274,14 @@ export async function fetchStrikesByUser(userId: string) {
return await mongo()
.db("revolt")
.collection
("safety_strikes")
- .find({ user_id: userId })
+ .find(
+ { user_id: userId },
+ {
+ sort: {
+ _id: -1,
+ },
+ }
+ )
.toArray();
}