11import {
2- APIButtonComponent ,
32 APIMessage ,
43 APIMessageApplicationCommandGuildInteraction ,
5- ButtonStyle ,
6- ComponentType ,
7- InteractionResponseType ,
8- MessageFlags ,
94} from "discord-api-types/v9" ;
105import { FastifyInstance } from "fastify" ;
116
12- import { embedPink } from "../../../constants" ;
137import {
148 InteractionOrRequestFinalStatus ,
159 UnexpectedFailure ,
1610} from "../../../errors" ;
17- import { getMessageActionsPossible } from "../../../lib/messages/checks" ;
1811import { GuildSession } from "../../../lib/session" ;
19- import { addTipToEmbed } from "../../../lib/tips" ;
2012import { InternalInteractionType } from "../../interaction" ;
13+ import { actionsLogic } from "../../shared/actions" ;
2114import { InteractionReturnData } from "../../types" ;
2215
23- export default async function handleActionMessageCommand (
16+ export default function handleActionMessageCommand (
2417 internalInteraction : InternalInteractionType < APIMessageApplicationCommandGuildInteraction > ,
2518 session : GuildSession ,
2619 instance : FastifyInstance
@@ -39,62 +32,10 @@ export default async function handleActionMessageCommand(
3932 "Message not found in resolved data"
4033 ) ;
4134 }
42- // The result does not need to be checked if it is not possible it will throw
43- const possibleActions = await getMessageActionsPossible ( {
35+ return actionsLogic ( {
36+ interaction ,
4437 message,
45- instance,
46- guildId : interaction . guild_id ,
4738 session,
39+ instance,
4840 } ) ;
49-
50- const components : APIButtonComponent [ ] = [ ] ;
51- if ( possibleActions . edit ) {
52- components . push ( {
53- type : ComponentType . Button ,
54- custom_id : `edit:${ message . id } ` ,
55- label : "Edit" ,
56- style : ButtonStyle . Success ,
57- } ) ;
58- }
59- if ( possibleActions . delete ) {
60- components . push ( {
61- type : ComponentType . Button ,
62- custom_id : `delete:${ message . id } ` ,
63- label : "Delete" ,
64- style : ButtonStyle . Danger ,
65- } ) ;
66- }
67- components . push ( {
68- type : ComponentType . Button ,
69- custom_id : `report:${ message . id } ` ,
70- label : "Report" ,
71- style : ButtonStyle . Danger ,
72- } ) ;
73-
74- const messageLink = `https://discord.com/channels/${ interaction . guild_id } /${ message . channel_id } /${ message . id } ` ;
75-
76- return {
77- type : InteractionResponseType . ChannelMessageWithSource ,
78- data : {
79- flags : MessageFlags . Ephemeral ,
80- embeds : [
81- addTipToEmbed ( {
82- title : "Message Actions" ,
83- color : embedPink ,
84- description :
85- `Click on the below buttons to edit, delete, or report [this message](${ messageLink } )` +
86- `\nIf the action is not available, you may be missing the required permissions for that action.` ,
87-
88- timestamp : new Date ( ) . toISOString ( ) ,
89- url : messageLink ,
90- } ) ,
91- ] ,
92- components : [
93- {
94- type : ComponentType . ActionRow ,
95- components,
96- } ,
97- ] ,
98- } ,
99- } ;
10041}
0 commit comments