This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ⚡ Validation improvements * ✨ Add update history work
- Loading branch information
Jasper Mayone
authored
Jul 5, 2022
1 parent
9d7eb01
commit 50cc301
Showing
14 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { model, Schema } from "mongoose"; | ||
|
||
import { History } from "../../interfaces/database/History"; | ||
|
||
export const HistorySchema = new Schema({ | ||
serverId: String, | ||
userId: String, | ||
bans: Number, | ||
kicks: Number, | ||
mutes: Number, | ||
unmutes: Number, | ||
warns: Number, | ||
}); | ||
|
||
export default model<History>("history", HistorySchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Joke { | ||
id: string; | ||
joke: string; | ||
dateUploaded: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Quote { | ||
id: string; | ||
quote: string; | ||
author: string; | ||
dateUploaded: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type ModerationActions = "ban" | "kick" | "mute" | "unmute" | "warn"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Document } from "mongoose"; | ||
|
||
export interface History extends Document { | ||
serverId: string; | ||
userId: string; | ||
bans: number; | ||
kicks: number; | ||
mutes: number; | ||
unmutes: number; | ||
warns: number; | ||
} | ||
|
||
export const testHistory: Omit<History, keyof Document> = { | ||
serverId: "123", | ||
userId: "123", | ||
bans: 0, | ||
kicks: 0, | ||
mutes: 0, | ||
unmutes: 0, | ||
warns: 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import HistoryModel from "../../../database/models/HistoryModel"; | ||
import { ModerationActions } from "../../../interfaces/commands/moderation/ModerationActions"; | ||
import { Heptagram } from "../../../interfaces/Heptagram"; | ||
import { heptagramErrorHandler } from "../../../modules/heptagramErrorHandler"; | ||
|
||
/** | ||
* Saves a count of the user's moderation actions. | ||
* | ||
* @param {Heptagram} Heptagram Heptagram's Discord instance. | ||
* @param {ModerationActions} action The action taken against the user. | ||
* @param {string} userId The ID of the user being moderated. | ||
* @param {string} guildId The ID of the guild the moderation occurred in. | ||
*/ | ||
export const updateHistory = async ( | ||
Heptagram: Heptagram, | ||
action: ModerationActions, | ||
userId: string, | ||
guildId: string | ||
) => { | ||
try { | ||
const userRecord = | ||
(await HistoryModel.findOne({ | ||
serverId: guildId, | ||
userId: userId, | ||
})) || | ||
(await HistoryModel.create({ | ||
serverId: guildId, | ||
userId: userId, | ||
bans: 0, | ||
kicks: 0, | ||
mutes: 0, | ||
unmutes: 0, | ||
warns: 0, | ||
})); | ||
|
||
switch (action) { | ||
case "kick": | ||
userRecord.kicks++; | ||
break; | ||
case "ban": | ||
userRecord.bans++; | ||
break; | ||
case "mute": | ||
userRecord.mutes++; | ||
break; | ||
case "unmute": | ||
userRecord.unmutes++; | ||
break; | ||
case "warn": | ||
userRecord.warns++; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
await userRecord.save(); | ||
} catch (err) { | ||
await heptagramErrorHandler( | ||
Heptagram, | ||
"update moderation history", | ||
err, | ||
guildId | ||
); | ||
} | ||
}; |