mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25: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,4 +1,4 @@
|
|||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { AutomodPluginType, ConfigSchema } from "./types";
|
||||
import { RunAutomodOnJoinEvt } from "./events/RunAutomodOnJoinEvt";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
|
@ -147,7 +147,7 @@ const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = options => {
|
|||
return options;
|
||||
};
|
||||
|
||||
export const AutomodPlugin = zeppelinPlugin<AutomodPluginType>()("automod", {
|
||||
export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod", {
|
||||
showInDocs: true,
|
||||
info: pluginInfo,
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { command } from "knub";
|
||||
import { guildCommand, GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { setAntiraidLevel } from "../functions/setAntiraidLevel";
|
||||
import { sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
||||
export const AntiraidClearCmd = command<AutomodPluginType>()({
|
||||
export const AntiraidClearCmd = guildCommand<AutomodPluginType>()({
|
||||
trigger: ["antiraid clear", "antiraid reset", "antiraid none", "antiraid off"],
|
||||
permission: "can_set_antiraid",
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { command } from "knub";
|
||||
import { guildCommand, GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { setAntiraidLevel } from "../functions/setAntiraidLevel";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
|
||||
export const SetAntiraidCmd = command<AutomodPluginType>()({
|
||||
export const SetAntiraidCmd = guildCommand<AutomodPluginType>()({
|
||||
trigger: "antiraid",
|
||||
permission: "can_set_antiraid",
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { command } from "knub";
|
||||
import { guildCommand, GuildPluginData } from "knub";
|
||||
import { AutomodPluginType } from "../types";
|
||||
import { setAntiraidLevel } from "../functions/setAntiraidLevel";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
|
||||
export const ViewAntiraidCmd = command<AutomodPluginType>()({
|
||||
export const ViewAntiraidCmd = guildCommand<AutomodPluginType>()({
|
||||
trigger: "antiraid",
|
||||
permission: "can_view_antiraid",
|
||||
|
||||
async run({ pluginData, message, args }) {
|
||||
async run({ pluginData, message }) {
|
||||
if (pluginData.state.cachedAntiraidLevel) {
|
||||
message.channel.createMessage(`Anti-raid is set to **${pluginData.state.cachedAntiraidLevel}**`);
|
||||
} else {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { eventListener } from "knub";
|
||||
import { guildEventListener } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import { RecentActionType } from "../constants";
|
||||
|
||||
export const RunAutomodOnJoinEvt = eventListener<AutomodPluginType>()(
|
||||
export const RunAutomodOnJoinEvt = guildEventListener<AutomodPluginType>()(
|
||||
"guildMemberAdd",
|
||||
({ pluginData, args: { member } }) => {
|
||||
const context: AutomodContext = {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { eventListener } from "knub";
|
||||
import { guildEventListener } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { RecentActionType } from "../constants";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import isEqual from "lodash.isequal";
|
||||
import diff from "lodash.difference";
|
||||
|
||||
export const RunAutomodOnMemberUpdate = eventListener<AutomodPluginType>()(
|
||||
export const RunAutomodOnMemberUpdate = guildEventListener<AutomodPluginType>()(
|
||||
"guildMemberUpdate",
|
||||
({ pluginData, args: { member, oldMember } }) => {
|
||||
if (!oldMember) return;
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import { addRecentActionsFromMessage } from "../functions/addRecentActionsFromMessage";
|
||||
import moment from "moment-timezone";
|
||||
import { clearRecentActionsForMessage } from "../functions/clearRecentActionsForMessage";
|
||||
|
||||
export function runAutomodOnMessage(pluginData: PluginData<AutomodPluginType>, message: SavedMessage, isEdit: boolean) {
|
||||
export function runAutomodOnMessage(
|
||||
pluginData: GuildPluginData<AutomodPluginType>,
|
||||
message: SavedMessage,
|
||||
isEdit: boolean,
|
||||
) {
|
||||
const user = pluginData.client.users.get(message.user_id);
|
||||
const member = pluginData.guild.members.get(message.user_id);
|
||||
|
||||
|
|
|
@ -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,
|
||||
) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { Awaitable } from "knub/dist/utils";
|
||||
import * as t from "io-ts";
|
||||
import { AutomodContext, AutomodPluginType } from "./types";
|
||||
|
@ -15,14 +15,14 @@ export interface AutomodTriggerMatchResult<TExtra extends any = unknown> {
|
|||
|
||||
type AutomodTriggerMatchFn<TConfigType, TMatchResultExtra> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
pluginData: GuildPluginData<AutomodPluginType>;
|
||||
context: AutomodContext;
|
||||
triggerConfig: TConfigType;
|
||||
}) => Awaitable<null | AutomodTriggerMatchResult<TMatchResultExtra>>;
|
||||
|
||||
type AutomodTriggerRenderMatchInformationFn<TConfigType, TMatchResultExtra> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
pluginData: GuildPluginData<AutomodPluginType>;
|
||||
contexts: AutomodContext[];
|
||||
triggerConfig: TConfigType;
|
||||
matchResult: AutomodTriggerMatchResult<TMatchResultExtra>;
|
||||
|
@ -54,7 +54,7 @@ export function automodTrigger(...args) {
|
|||
|
||||
type AutomodActionApplyFn<TConfigType> = (meta: {
|
||||
ruleName: string;
|
||||
pluginData: PluginData<AutomodPluginType>;
|
||||
pluginData: GuildPluginData<AutomodPluginType>;
|
||||
contexts: AutomodContext[];
|
||||
actionConfig: TConfigType;
|
||||
matchResult: AutomodTriggerMatchResult;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ZeppelinPluginBlueprint } from "../ZeppelinPluginBlueprint";
|
||||
import { ZeppelinGuildPluginBlueprint } from "../ZeppelinPluginBlueprint";
|
||||
import { trimPluginDescription } from "../../utils";
|
||||
|
||||
export const pluginInfo: ZeppelinPluginBlueprint["info"] = {
|
||||
export const pluginInfo: ZeppelinGuildPluginBlueprint["info"] = {
|
||||
prettyName: "Automod",
|
||||
description: trimPluginDescription(`
|
||||
Allows specifying automated actions in response to triggers. Example use cases include word filtering and spam prevention.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue