3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 18:25:03 +00:00
zeppelin/backend/src/plugins/Automod/functions/getMatchingMessageRecentActions.ts
metal 59bf98f928
remove unused imports & add prettier plugin
Signed-off-by: GitHub <noreply@github.com>
2023-03-20 20:13:30 +00:00

32 lines
1.1 KiB
TypeScript

import { GuildPluginData } from "knub";
import moment from "moment-timezone";
import { SavedMessage } from "../../../data/entities/SavedMessage";
import { startProfiling } from "../../../utils/easyProfiler";
import { RecentActionType } from "../constants";
import { AutomodPluginType } from "../types";
import { getMatchingRecentActions } from "./getMatchingRecentActions";
export function getMatchingMessageRecentActions(
pluginData: GuildPluginData<AutomodPluginType>,
message: SavedMessage,
type: RecentActionType,
identifier: string,
count: number,
within: number,
) {
const stopProfiling = startProfiling(
pluginData.getKnubInstance().profiler,
"automod:fns:getMatchingMessageRecentActions",
);
const since = moment.utc(message.posted_at).valueOf() - within;
const to = moment.utc(message.posted_at).valueOf();
const recentActions = getMatchingRecentActions(pluginData, type, identifier, since, to);
const totalCount = recentActions.reduce((total, action) => total + action.count, 0);
stopProfiling();
if (totalCount >= count) {
return {
recentActions,
};
}
}