mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Allow automatic tag invoke deletion (#131)
This commit is contained in:
parent
1c24910a20
commit
460fb2f29b
3 changed files with 33 additions and 1 deletions
|
@ -19,6 +19,7 @@ import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
||||||
import { mapToPublicFn } from "../../pluginUtils";
|
import { mapToPublicFn } from "../../pluginUtils";
|
||||||
import { renderTagBody } from "./util/renderTagBody";
|
import { renderTagBody } from "./util/renderTagBody";
|
||||||
import { findTagByName } from "./util/findTagByName";
|
import { findTagByName } from "./util/findTagByName";
|
||||||
|
import { StrictValidationError } from "src/validatorUtils";
|
||||||
|
|
||||||
const defaultOptions: PluginOptions<TagsPluginType> = {
|
const defaultOptions: PluginOptions<TagsPluginType> = {
|
||||||
config: {
|
config: {
|
||||||
|
@ -29,6 +30,7 @@ const defaultOptions: PluginOptions<TagsPluginType> = {
|
||||||
global_tag_cooldown: null,
|
global_tag_cooldown: null,
|
||||||
user_cooldown: null,
|
user_cooldown: null,
|
||||||
global_cooldown: null,
|
global_cooldown: null,
|
||||||
|
auto_delete_command: false,
|
||||||
|
|
||||||
categories: {},
|
categories: {},
|
||||||
|
|
||||||
|
@ -71,6 +73,28 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()("tags", {
|
||||||
findTagByName: mapToPublicFn(findTagByName),
|
findTagByName: mapToPublicFn(findTagByName),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
configPreprocessor(options) {
|
||||||
|
if (options.config.delete_with_command && options.config.auto_delete_command) {
|
||||||
|
throw new StrictValidationError([
|
||||||
|
`Cannot have both (global) delete_with_command and global_delete_invoke enabled`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check each category for conflicting options
|
||||||
|
if (options.config?.categories) {
|
||||||
|
for (const [name, opts] of Object.entries(options.config.categories)) {
|
||||||
|
const cat = options.config.categories[name];
|
||||||
|
if (cat.delete_with_command && cat.auto_delete_command) {
|
||||||
|
throw new StrictValidationError([
|
||||||
|
`Cannot have both (category specific) delete_with_command and category_delete_invoke enabled at <categories/${name}>`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
},
|
||||||
|
|
||||||
onLoad(pluginData) {
|
onLoad(pluginData) {
|
||||||
const { state, guild } = pluginData;
|
const { state, guild } = pluginData;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const TagCategory = t.type({
|
||||||
user_category_cooldown: tNullable(t.union([t.string, t.number])), // Per user, per tag category
|
user_category_cooldown: tNullable(t.union([t.string, t.number])), // Per user, per tag category
|
||||||
global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag
|
global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag
|
||||||
global_category_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per category
|
global_category_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per category
|
||||||
|
auto_delete_command: tNullable(t.boolean), // Any tag, per tag category
|
||||||
|
|
||||||
tags: t.record(t.string, Tag),
|
tags: t.record(t.string, Tag),
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ export const ConfigSchema = t.type({
|
||||||
global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag
|
global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag
|
||||||
user_cooldown: tNullable(t.union([t.string, t.number])), // Per user
|
user_cooldown: tNullable(t.union([t.string, t.number])), // Per user
|
||||||
global_cooldown: tNullable(t.union([t.string, t.number])), // Any tag use
|
global_cooldown: tNullable(t.union([t.string, t.number])), // Any tag use
|
||||||
|
auto_delete_command: t.boolean, // Any tag
|
||||||
|
|
||||||
categories: t.record(t.string, TagCategory),
|
categories: t.record(t.string, TagCategory),
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { TagsPluginType } from "../types";
|
import { TagsPluginType } from "../types";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { convertDelayStringToMS, resolveMember, tStrictMessageContent } from "../../../utils";
|
import { convertDelayStringToMS, noop, resolveMember, tStrictMessageContent } from "../../../utils";
|
||||||
import { validate } from "../../../validatorUtils";
|
import { validate } from "../../../validatorUtils";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { TextChannel } from "eris";
|
import { TextChannel } from "eris";
|
||||||
|
@ -108,4 +108,10 @@ export async function onMessageCreate(pluginData: GuildPluginData<TagsPluginType
|
||||||
await pluginData.state.tags.addResponse(msg.id, responseMsg.id);
|
await pluginData.state.tags.addResponse(msg.id, responseMsg.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteInvoke = tagResult.category?.category_delete_invoke ?? config.global_delete_invoke;
|
||||||
|
if (!deleteWithCommand && deleteInvoke) {
|
||||||
|
// Try deleting the invoking message, ignore errors silently
|
||||||
|
pluginData.client.deleteMessage(msg.channel_id, msg.id).catch(noop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue