mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
Automod work
This commit is contained in:
parent
4b33322127
commit
c23f37d991
32 changed files with 1099 additions and 5 deletions
|
@ -0,0 +1,28 @@
|
|||
import { PluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import moment from "moment-timezone";
|
||||
import { getMatchingRecentActions } from "./getMatchingRecentActions";
|
||||
import { RecentActionType } from "../constants";
|
||||
|
||||
export function getMatchingMessageRecentActions(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
message: SavedMessage,
|
||||
type: RecentActionType,
|
||||
count: number,
|
||||
within: number,
|
||||
perChannel: boolean,
|
||||
) {
|
||||
const since = moment.utc(message.posted_at).valueOf() - within;
|
||||
const to = moment.utc(message.posted_at).valueOf();
|
||||
const identifier = perChannel ? `${message.channel_id}-${message.user_id}` : message.user_id;
|
||||
const recentActions = getMatchingRecentActions(pluginData, type, identifier, since, to);
|
||||
const totalCount = recentActions.reduce((total, action) => total + action.count, 0);
|
||||
|
||||
if (totalCount >= count) {
|
||||
return {
|
||||
identifier,
|
||||
recentActions,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue