@@ -11,6 +11,44 @@ namespace Asterion.Modules
11
11
public class EntryInteractionModule ( ILocalizationService localizationService , IDataService dataService )
12
12
: AsterionInteractionModuleBase ( localizationService )
13
13
{
14
+ public static Embed CreateModrinthEntryEmbed ( ModrinthEntry entry , ReleaseType releaseFilter )
15
+ {
16
+ return new EmbedBuilder ( )
17
+ . WithTitle ( "Modrinth Entry Information" )
18
+ . WithDescription ( "Here is the information about the Modrinth entry:" )
19
+ . AddField ( "📂 Project ID" , $ "`{ entry . ProjectId } `", false )
20
+ . AddField ( "📢 Custom Update Channel" ,
21
+ entry . CustomUpdateChannel . HasValue ? MentionUtils . MentionChannel ( entry . CustomUpdateChannel . Value ) : "None" ,
22
+ true )
23
+ . AddField ( "📜 Custom Ping Role" ,
24
+ entry . CustomPingRole . HasValue ? MentionUtils . MentionRole ( entry . CustomPingRole . Value ) : "None" ,
25
+ false )
26
+ . AddField ( "🔖 Release Filter" , releaseFilter . ToString ( ) , true )
27
+ . AddField ( "🕒 Created" , TimestampTag . FromDateTime ( entry . Created ) . ToString ( ) , true )
28
+ . WithColor ( Color . Blue )
29
+ . WithCurrentTimestamp ( )
30
+ . Build ( ) ;
31
+ }
32
+
33
+ private static MessageComponent CreateReleaseFilterComponent ( string projectId , ReleaseType releaseFilter )
34
+ {
35
+ var selectMenu = new SelectMenuBuilder ( )
36
+ . WithCustomId ( $ "release_filter:{ projectId } ")
37
+ . WithPlaceholder ( "Select release type(s)" )
38
+ . WithMinValues ( 1 )
39
+ . WithMaxValues ( 3 )
40
+ . AddOption ( "Alpha" , ( ( int ) ReleaseType . Alpha ) . ToString ( ) , "Include Alpha releases" ,
41
+ isDefault : releaseFilter . HasFlag ( ReleaseType . Alpha ) )
42
+ . AddOption ( "Beta" , ( ( int ) ReleaseType . Beta ) . ToString ( ) , "Include Beta releases" ,
43
+ isDefault : releaseFilter . HasFlag ( ReleaseType . Beta ) )
44
+ . AddOption ( "Release" , ( ( int ) ReleaseType . Release ) . ToString ( ) , "Include Release" ,
45
+ isDefault : releaseFilter . HasFlag ( ReleaseType . Release ) ) ;
46
+
47
+ return new ComponentBuilder ( )
48
+ . WithSelectMenu ( selectMenu )
49
+ . Build ( ) ;
50
+ }
51
+
14
52
// Interaction command to display the entry info and provide a dropdown
15
53
[ SlashCommand ( "entry" , "Displays entry information and allows selection of release type filters." ) ]
16
54
public async Task ShowEntryAsync ( [ Summary ( "project_id" ) ] [ Autocomplete ( typeof ( SubscribedIdAutocompletionHandler ) ) ] string projectId )
@@ -26,73 +64,62 @@ public async Task ShowEntryAsync([Summary("project_id")] [Autocomplete(typeof(Su
26
64
}
27
65
28
66
// Create embed with entry details
29
- var embed = new EmbedBuilder ( )
30
- . WithTitle ( "Modrinth Entry Information" )
31
- . AddField ( "Project ID" , entry . ProjectId )
32
- . AddField ( "Array ID" , entry . ArrayId )
33
- . AddField ( "Custom Update Channel" , entry . CustomUpdateChannel ? . ToString ( ) ?? "None" )
34
- . AddField ( "Custom Ping Role" , entry . CustomPingRole ? . ToString ( ) ?? "None" )
35
- . AddField ( "Release Filter" , entry . ReleaseFilter . ToString ( ) )
36
- . AddField ( "Created" , TimestampTag . FromDateTime ( entry . Created ) )
37
- . WithColor ( Color . Blue )
38
- . Build ( ) ;
67
+ var embed = CreateModrinthEntryEmbed ( entry , entry . ReleaseFilter ) ;
39
68
40
- // Create a SelectMenu for ReleaseType filter
41
- var selectMenu = new SelectMenuBuilder ( )
42
- . WithCustomId ( $ "release_filter:{ entry . EntryId } ") // Unique ID to handle interactions
43
- . WithPlaceholder ( "Select release type(s)" )
44
- . WithMinValues ( 1 )
45
- . WithMaxValues ( 3 )
46
- . AddOption ( "Alpha" , ( ( int ) ReleaseType . Alpha ) . ToString ( ) , "Include Alpha releases" ,
47
- isDefault : entry . ReleaseFilter . HasFlag ( ReleaseType . Alpha ) )
48
- . AddOption ( "Beta" , ( ( int ) ReleaseType . Beta ) . ToString ( ) , "Include Beta releases" ,
49
- isDefault : entry . ReleaseFilter . HasFlag ( ReleaseType . Beta ) )
50
- . AddOption ( "Release" , ( ( int ) ReleaseType . Release ) . ToString ( ) , "Include Release" ,
51
- isDefault : entry . ReleaseFilter . HasFlag ( ReleaseType . Release ) ) ;
52
69
53
- var component = new ComponentBuilder ( )
54
- . WithSelectMenu ( selectMenu )
55
- . Build ( ) ;
70
+ // Create a SelectMenu for ReleaseType filter
71
+ var component = CreateReleaseFilterComponent ( projectId , entry . ReleaseFilter ) ;
56
72
57
73
// Send the embed with the dropdown menu
58
74
await FollowupAsync ( embed : embed , components : component ) ;
59
75
}
60
76
61
- // Handle the dropdown interaction
62
77
[ ComponentInteraction ( "release_filter:*" ) ]
63
- public async Task HandleReleaseFilterSelectionAsync ( string entryId , string [ ] selectedValues )
78
+ public async Task HandleReleaseFilterSelectionAsync ( string projectId , string [ ] selectedValues )
64
79
{
65
- // Parse the entry ID
66
- // if (!ulong.TryParse(entryId, out var parsedEntryId))
67
- // {
68
- // await RespondAsync("Invalid entry ID.");
69
- // return;
70
- // }
71
- //
72
- // // Retrieve the entry
73
- // var entry = await _modrinthEntryService.GetEntryByIdAsync(parsedEntryId);
74
- // if (entry == null)
75
- // {
76
- // await RespondAsync("Entry not found.");
77
- // return;
78
- // }
79
- //
80
- // // Convert selectedValues back into the ReleaseType enum
81
- // ReleaseType? newReleaseFilter = null;
82
- // foreach (var value in selectedValues)
83
- // {
84
- // if (int.TryParse(value, out var releaseTypeValue))
85
- // {
86
- // newReleaseFilter |= (ReleaseType)releaseTypeValue;
87
- // }
88
- // }
89
- //
90
- // // Update the entry with the new filter (handle updating it in your data source here)
91
- // entry.ReleaseFilter = newReleaseFilter;
92
- // await _modrinthEntryService.UpdateEntryAsync(entry); // Update via your custom connector
93
- //
94
- // // Respond with the updated information
95
- // await RespondAsync($"Release filter updated to: {entry.ReleaseFilter}");
80
+ // Defer the interaction to avoid timeout issues
81
+ await DeferAsync ( ephemeral : true ) ;
82
+
83
+ // Retrieve the entry using projectId
84
+ var entry = await dataService . GetModrinthEntryAsync ( Context . Guild . Id , projectId ) ;
85
+ if ( entry == null )
86
+ {
87
+ await FollowupAsync ( "Entry not found." , ephemeral : true ) ;
88
+ return ;
89
+ }
90
+
91
+ // Convert selectedValues back into the ReleaseType enum
92
+ ReleaseType newReleaseFilter = 0 ;
93
+ foreach ( var value in selectedValues )
94
+ {
95
+ if ( int . TryParse ( value , out var releaseTypeValue ) )
96
+ {
97
+ newReleaseFilter |= ( ReleaseType ) releaseTypeValue ;
98
+ }
99
+ }
100
+
101
+ if ( newReleaseFilter == 0 )
102
+ {
103
+ await FollowupAsync ( "Please select at least one release type." , ephemeral : true ) ;
104
+ return ;
105
+ }
106
+
107
+ // Update the release filter in the database
108
+ await dataService . SetReleaseFilterAsync ( entry . EntryId , newReleaseFilter ) ;
109
+
110
+ // Use the static method to generate the updated embed
111
+ var updatedEmbed = CreateModrinthEntryEmbed ( entry , newReleaseFilter ) ;
112
+
113
+ // Update the original message with the new embed
114
+ await ModifyOriginalResponseAsync ( msg => {
115
+ msg . Embed = updatedEmbed ;
116
+ msg . Components = CreateReleaseFilterComponent ( projectId , newReleaseFilter ) ;
117
+ } ) ;
118
+
119
+ // Optionally, acknowledge the selection change in a temporary message
120
+ await FollowupAsync ( "Release filter updated successfully!" , ephemeral : true ) ;
96
121
}
122
+
123
+
97
124
}
98
125
}
0 commit comments