mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-12 21:05:02 +00:00
Update to new Knub 30 beta. Code clean-up.
This commit is contained in:
parent
5d579446c5
commit
2f470dc37a
299 changed files with 1075 additions and 1004 deletions
|
@ -1,9 +1,9 @@
|
|||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { RECENT_ACTION_EXPIRY_TIME, RecentActionType } from "../constants";
|
||||
import { getEmojiInString, getRoleMentions, getUrlsInString, getUserMentions } from "../../../utils";
|
||||
|
||||
export function addRecentActionsFromMessage(pluginData: PluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
export function addRecentActionsFromMessage(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
const globalIdentifier = context.message.user_id;
|
||||
const perChannelIdentifier = `${context.message.channel_id}-${context.message.user_id}`;
|
||||
const expiresAt = Date.now() + RECENT_ACTION_EXPIRY_TIME;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { AutomodContext, AutomodPluginType, TRule } from "../types";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodTriggerMatchResult } from "../helpers";
|
||||
import { convertDelayStringToMS } from "../../../utils";
|
||||
|
||||
export function checkAndUpdateCooldown(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
rule: TRule,
|
||||
context: AutomodContext,
|
||||
) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RECENT_NICKNAME_CHANGE_EXPIRY_TIME, RECENT_SPAM_EXPIRY_TIME } from "../constants";
|
||||
|
||||
export function clearOldRecentNicknameChanges(pluginData: PluginData<AutomodPluginType>) {
|
||||
export function clearOldRecentNicknameChanges(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
for (const [userId, { timestamp }] of pluginData.state.recentNicknameChanges) {
|
||||
if (timestamp + RECENT_NICKNAME_CHANGE_EXPIRY_TIME <= now) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RECENT_ACTION_EXPIRY_TIME } from "../constants";
|
||||
|
||||
export function clearOldRecentActions(pluginData: PluginData<AutomodPluginType>) {
|
||||
export function clearOldRecentActions(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(info => {
|
||||
return info.context.timestamp + RECENT_ACTION_EXPIRY_TIME > now;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RECENT_SPAM_EXPIRY_TIME } from "../constants";
|
||||
|
||||
export function clearOldRecentSpam(pluginData: PluginData<AutomodPluginType>) {
|
||||
export function clearOldRecentSpam(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const now = Date.now();
|
||||
pluginData.state.recentSpam = pluginData.state.recentSpam.filter(spam => {
|
||||
return spam.timestamp + RECENT_SPAM_EXPIRY_TIME > now;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { RECENT_ACTION_EXPIRY_TIME, RecentActionType } from "../constants";
|
||||
import { getEmojiInString, getRoleMentions, getUrlsInString, getUserMentions } from "../../../utils";
|
||||
|
||||
export function clearRecentActionsForMessage(pluginData: PluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
export function clearRecentActionsForMessage(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
const globalIdentifier = context.message.user_id;
|
||||
const perChannelIdentifier = `${context.message.channel_id}-${context.message.user_id}`;
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RecentActionType } from "../constants";
|
||||
|
||||
export function findRecentSpam(pluginData: PluginData<AutomodPluginType>, type: RecentActionType, identifier?: string) {
|
||||
export function findRecentSpam(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
type: RecentActionType,
|
||||
identifier?: string,
|
||||
) {
|
||||
return pluginData.state.recentSpam.find(spam => {
|
||||
return spam.type === type && (!identifier || spam.identifiers.includes(identifier));
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import moment from "moment-timezone";
|
||||
|
@ -6,7 +6,7 @@ import { getMatchingRecentActions } from "./getMatchingRecentActions";
|
|||
import { RecentActionType } from "../constants";
|
||||
|
||||
export function getMatchingMessageRecentActions(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
message: SavedMessage,
|
||||
type: RecentActionType,
|
||||
identifier: string,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { RecentActionType } from "../constants";
|
||||
|
||||
export function getMatchingRecentActions(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
type: RecentActionType,
|
||||
identifier: string | null,
|
||||
since: number,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { MatchableTextType } from "./matchMultipleTextTypesOnMessage";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { messageSummary, verboseChannelMention } from "../../../utils";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { User } from "eris";
|
||||
|
||||
export function getTextMatchPartialSummary(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
type: MatchableTextType,
|
||||
context: AutomodContext,
|
||||
) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { MINUTES } from "../../../utils";
|
||||
|
||||
const IGNORED_ROLE_CHANGE_LIFETIME = 5 * MINUTES;
|
||||
|
||||
function cleanupIgnoredRoleChanges(pluginData: PluginData<AutomodPluginType>) {
|
||||
function cleanupIgnoredRoleChanges(pluginData: GuildPluginData<AutomodPluginType>) {
|
||||
const cutoff = Date.now() - IGNORED_ROLE_CHANGE_LIFETIME;
|
||||
for (const ignoredChange of pluginData.state.ignoredRoleChanges.values()) {
|
||||
if (ignoredChange.timestamp < cutoff) {
|
||||
|
@ -13,7 +13,7 @@ function cleanupIgnoredRoleChanges(pluginData: PluginData<AutomodPluginType>) {
|
|||
}
|
||||
}
|
||||
|
||||
export function ignoreRoleChange(pluginData: PluginData<AutomodPluginType>, memberId: string, roleId: string) {
|
||||
export function ignoreRoleChange(pluginData: GuildPluginData<AutomodPluginType>, memberId: string, roleId: string) {
|
||||
pluginData.state.ignoredRoleChanges.add({
|
||||
memberId,
|
||||
roleId,
|
||||
|
@ -26,7 +26,11 @@ export function ignoreRoleChange(pluginData: PluginData<AutomodPluginType>, memb
|
|||
/**
|
||||
* @return Whether the role change should be ignored
|
||||
*/
|
||||
export function consumeIgnoredRoleChange(pluginData: PluginData<AutomodPluginType>, memberId: string, roleId: string) {
|
||||
export function consumeIgnoredRoleChange(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
memberId: string,
|
||||
roleId: string,
|
||||
) {
|
||||
for (const ignoredChange of pluginData.state.ignoredRoleChanges.values()) {
|
||||
if (ignoredChange.memberId === memberId && ignoredChange.roleId === roleId) {
|
||||
pluginData.state.ignoredRoleChanges.delete(ignoredChange);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { resolveMember } from "../../../utils";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
|
||||
type TextTriggerWithMultipleMatchTypes = {
|
||||
|
@ -20,7 +20,7 @@ type YieldedContent = [MatchableTextType, string];
|
|||
* Generator function that allows iterating through matchable pieces of text of a SavedMessage
|
||||
*/
|
||||
export async function* matchMultipleTextTypesOnMessage(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
trigger: TextTriggerWithMultipleMatchTypes,
|
||||
msg: SavedMessage,
|
||||
): AsyncIterableIterator<YieldedContent> {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { TextChannel } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
|
||||
export function resolveActionContactMethods(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
actionConfig: {
|
||||
notify?: string;
|
||||
notifyChannel?: string;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { availableTriggers } from "../triggers/availableTriggers";
|
||||
import { availableActions } from "../actions/availableActions";
|
||||
|
@ -6,7 +6,7 @@ import { AutomodTriggerMatchResult } from "../helpers";
|
|||
import { CleanAction } from "../actions/clean";
|
||||
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
|
||||
|
||||
export async function runAutomod(pluginData: PluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
||||
const user = context.user || (userId && pluginData.client.users.get(userId));
|
||||
const member = context.member || (userId && pluginData.guild.members.get(userId));
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { User } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
|
||||
export async function setAntiraidLevel(
|
||||
pluginData: PluginData<AutomodPluginType>,
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
newLevel: string | null,
|
||||
user?: User,
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue