11import { SlashCommandBuilder } from "discord.js" ;
22
33import type { SlashCommand } from "../models" ;
4- import { GameInfoService } from "../services/game-info.service" ;
54import { TemplateService } from "../services/template.service" ;
6- import { fetchGanData } from "../utils/fetch-gan-data" ;
7- import { logError } from "../utils/logger" ;
5+ import { runGanCommand } from "./shared/run-gan-command" ;
86
97const ganSlashCommand : SlashCommand = {
108 data : new SlashCommandBuilder ( )
@@ -17,49 +15,20 @@ const ganSlashCommand: SlashCommand = {
1715 . setRequired ( true ) ,
1816 ) ,
1917
20- legacyName : "gan" , // For migration mapping - using the most common alias
18+ legacyName : "gan" , // For migration mapping - using the most common alias.
2119
2220 async execute ( interaction , _client ) {
23- await interaction . deferReply ( ) ;
24-
25- const gameInput = interaction . options . getString ( "game-id" , true ) ;
26-
27- // Extract game ID from argument.
28- const gameId = GameInfoService . extractGameId ( gameInput ) ;
29- if ( ! gameId ) {
30- await interaction . editReply (
31- "Invalid game ID or URL format. Please provide a game ID number or a RetroAchievements game URL." ,
32- ) ;
33-
34- return ;
35- }
36-
37- try {
38- const ganData = await fetchGanData ( gameId ) ;
39- if ( ! ganData ) {
40- await interaction . editReply (
41- `Unable to get info from the game ID \`${ gameId } \`... :frowning:` ,
42- ) ;
43-
44- return ;
45- }
46-
47- const template = TemplateService . generateGanTemplate (
48- ganData . gameInfo ,
49- ganData . achievementSetDate ,
50- ganData . youtubeLink ,
51- ganData . gameId ,
52- ) ;
53-
54- await interaction . editReply ( {
55- content : `Here's your achievement-news post template:\n${ template } ` ,
56- } ) ;
57- } catch ( error ) {
58- logError ( "Error in gan slash command:" , { error } ) ;
59- await interaction . editReply (
60- `Unable to get info from the game ID \`${ gameId } \`... :frowning:` ,
61- ) ;
62- }
21+ await runGanCommand ( interaction , {
22+ commandName : "gan" ,
23+ render : ( ganData ) => ( {
24+ content : `Here's your achievement-news post template:\n${ TemplateService . generateGanTemplate (
25+ ganData . gameInfo ,
26+ ganData . achievementSetDate ,
27+ ganData . youtubeLink ,
28+ ganData . gameId ,
29+ ) } `,
30+ } ) ,
31+ } ) ;
6332 } ,
6433} ;
6534
0 commit comments