44import net .dv8tion .jda .api .JDA ;
55import net .dv8tion .jda .api .entities .Guild ;
66import net .dv8tion .jda .api .entities .User ;
7+ import net .dv8tion .jda .api .exceptions .ErrorResponseException ;
78import net .javadiscord .javabot .api .exception .InternalServerException ;
89import net .javadiscord .javabot .api .exception .InvalidEntityIdException ;
910import net .javadiscord .javabot .api .routes .CaffeineCache ;
1516import net .javadiscord .javabot .systems .moderation .warn .dao .WarnRepository ;
1617import net .javadiscord .javabot .systems .qotw .QOTWPointsService ;
1718import net .javadiscord .javabot .systems .qotw .model .QOTWAccount ;
18- import net .javadiscord .javabot .systems .user_preferences .UserPreferenceService ;
19- import net .javadiscord .javabot .systems .user_preferences .model .Preference ;
20- import net .javadiscord .javabot .systems .user_preferences .model .UserPreference ;
2119import net .javadiscord .javabot .util .Pair ;
2220import org .springframework .beans .factory .annotation .Autowired ;
2321import org .springframework .dao .DataAccessException ;
3028import java .sql .Connection ;
3129import java .sql .SQLException ;
3230import java .time .LocalDateTime ;
33- import java .util .Arrays ;
34- import java .util .List ;
3531import java .util .concurrent .TimeUnit ;
3632
3733import javax .sql .DataSource ;
4339public class UserProfileController extends CaffeineCache <Pair <Long , Long >, UserProfileData > {
4440 private final JDA jda ;
4541 private final QOTWPointsService qotwPointsService ;
46- private final UserPreferenceService preferenceService ;
4742 private final DataSource dataSource ;
4843 private final BotConfig botConfig ;
4944 private final HelpExperienceService helpExperienceService ;
@@ -54,21 +49,19 @@ public class UserProfileController extends CaffeineCache<Pair<Long, Long>, UserP
5449 *
5550 * @param jda The {@link Autowired} {@link JDA} instance to use.
5651 * @param qotwPointsService The {@link QOTWPointsService}
57- * @param preferenceService The {@link UserPreferenceService}
5852 * @param botConfig The main configuration of the bot
5953 * @param dataSource A factory for connections to the main database
6054 * @param helpExperienceService Service object that handles Help Experience Transactions.
6155 * @param warnRepository DAO for interacting with the set of {@link Warn} objects.
6256 */
6357 @ Autowired
64- public UserProfileController (final JDA jda , QOTWPointsService qotwPointsService , UserPreferenceService preferenceService , BotConfig botConfig , DataSource dataSource , HelpExperienceService helpExperienceService , WarnRepository warnRepository ) {
58+ public UserProfileController (final JDA jda , QOTWPointsService qotwPointsService , BotConfig botConfig , DataSource dataSource , HelpExperienceService helpExperienceService , WarnRepository warnRepository ) {
6559 super (Caffeine .newBuilder ()
6660 .expireAfterWrite (10 , TimeUnit .MINUTES )
6761 .build ()
6862 );
6963 this .jda = jda ;
7064 this .qotwPointsService = qotwPointsService ;
71- this .preferenceService = preferenceService ;
7265 this .dataSource = dataSource ;
7366 this .botConfig = botConfig ;
7467 this .helpExperienceService = helpExperienceService ;
@@ -91,9 +84,11 @@ public ResponseEntity<UserProfileData> getUserProfile(
9184 if (guild == null ) {
9285 throw new InvalidEntityIdException (Guild .class , "You've provided an invalid guild id!" );
9386 }
94- User user = jda .retrieveUserById (userId ).complete ();
95- if (user == null ) {
96- throw new InvalidEntityIdException (User .class , "You've provided an invalid user id!" );
87+ User user ;
88+ try {
89+ user = jda .retrieveUserById (userId ).complete ();
90+ }catch (ErrorResponseException e ) {
91+ throw new InvalidEntityIdException (User .class , "Cannot fetch user: " + e .getMeaning ());
9792 }
9893 try (Connection con = dataSource .getConnection ()) {
9994 // Check Cache
@@ -110,9 +105,6 @@ public ResponseEntity<UserProfileData> getUserProfile(
110105 // Help Account
111106 HelpAccount helpAccount = helpExperienceService .getOrCreateAccount (user .getIdLong ());
112107 data .setHelpAccount (HelpAccountData .of (botConfig , helpAccount , guild ));
113- // User Preferences
114- List <UserPreference > preferences = Arrays .stream (Preference .values ()).map (p -> preferenceService .getOrCreate (user .getIdLong (), p )).toList ();
115- data .setPreferences (preferences );
116108 // User Warns
117109 LocalDateTime cutoff = LocalDateTime .now ().minusDays (botConfig .get (guild ).getModerationConfig ().getWarnTimeoutDays ());
118110 data .setWarns (warnRepository .getActiveWarnsByUserId (user .getIdLong (), cutoff ));
0 commit comments