11import { escapeMarkdown } from "#common/discord/markdown.ts" ;
2+ import type { Nullable } from "#common/general.ts" ;
23import { moduleLogger } from "#common/logger/index.ts" ;
34import { OptionType } from "#plugin/core/public/command.ts" ;
45import { defineCommand } from "#plugin/core/public/extensionPoints.ts" ;
@@ -11,6 +12,7 @@ import {
1112import { autocompleteTags } from "#plugin/tags/helper/autocompletion.ts" ;
1213import { tagsConfigStore } from "#plugin/tags/index.ts" ;
1314import { onTagEdited } from "#plugin/tags/public/extensionPoints.ts" ;
15+ import type { Tag } from "#plugin/tags/public/tag.ts" ;
1416import { updateTag } from "#plugin/tags/storage/tags.ts" ;
1517
1618const logger = moduleLogger ( ) ;
@@ -52,14 +54,16 @@ export default defineCommand({
5254 ( permissions ) => permissions . tagEdit ,
5355 ) ,
5456 async run ( ctx , args ) {
57+ const changes = {
58+ name : args . newName ,
59+ content : args . content ,
60+ } ;
61+
5562 const oldTag = await updateTag (
5663 ctx . squirrelCtx . db ,
5764 ctx . guild . id ,
5865 args . name ,
59- {
60- name : args . newName ?? undefined ,
61- content : args . content ?? undefined ,
62- } ,
66+ changes ,
6367 ) ;
6468
6569 if ( oldTag === null ) {
@@ -69,13 +73,14 @@ export default defineCommand({
6973 return ;
7074 }
7175
72- const newTag = {
73- name : args . newName ?? oldTag . name ,
74- content : args . content ?? oldTag . content ,
75- } ;
76+ // check after we know the tag exists
77+ if ( args . newName === null && args . content === null ) {
78+ await ctx . respond ( `${ icons . error } No changes specified!` ) ;
79+ return ;
80+ }
7681
7782 onTagEdited
78- . fire ( ctx . squirrelCtx , ctx . guild , ctx . member , oldTag , newTag )
83+ . fire ( ctx . squirrelCtx , ctx . guild , ctx . member , oldTag , changes )
7984 . catch ( ( error ) => logger . error ?.( "Error in onTagDeleted" , error ) ) ;
8085
8186 await ctx . respond (
0 commit comments