@@ -339,6 +339,10 @@ public void command_unmute(final IMessage message, final String userString) {
339
339
* @param channel The channel to send error messages to. Can be null.
340
340
*/
341
341
private void muteUserForGuild (final IUser user , final IGuild guild , final int muteDuration , final ChronoUnit muteDurationUnit , final IChannel channel ) {
342
+ if (!guild .getUsers ().contains (user )) {
343
+ throw new IllegalArgumentException ("Specified user is not a member of the specified guild!" );
344
+ }
345
+
342
346
// Get mute role for this guild
343
347
final IRole muteRole = getMuteRoleForGuild (guild );
344
348
if (muteRole == null ) {
@@ -801,10 +805,15 @@ public void onStartup(final ReadyEvent event) {
801
805
802
806
final long guildLongID = Long .parseLong (guildStringID );
803
807
final IGuild guild = event .getClient ().getGuildByID (guildLongID );
804
- LOG .debug ("Found guild '{}'." , guild .getName ());
805
808
806
- restoreGuildUserMutes (guild );
807
- restoreGuildChannelMutes (guild );
809
+ if (guild == null ) {
810
+ LOG .warn ("Found modstuff entry for guild with invalid ID '%l'. Skipping." , guildLongID );
811
+ }
812
+ else {
813
+ LOG .debug ("Found guild '{}'." , guild .getName ());
814
+ restoreGuildUserMutes (guild );
815
+ restoreGuildChannelMutes (guild );
816
+ }
808
817
}
809
818
810
819
LOG .info ("Restored all mutes." );
@@ -841,7 +850,11 @@ private void restoreGuildUserMutes(final IGuild guild) {
841
850
final String unmuteTimestampString = currentUserMute .getString ("mutedUntil" );
842
851
final LocalDateTime unmuteTimestamp = LocalDateTime .parse (unmuteTimestampString , formatter );
843
852
844
- if (LocalDateTime .now ().isBefore (unmuteTimestamp )) {
853
+ if (user == null ) {
854
+ LOG .info ("Mute for user with id {} on guild '{}' (ID: {}) could not be restored. User is not a member of the guild" ,
855
+ userLongID , guild .getName (), guild .getStringID ());
856
+ }
857
+ else if (LocalDateTime .now ().isBefore (unmuteTimestamp )) {
845
858
final int delaySeconds = (int )LocalDateTime .now ().until (unmuteTimestamp , ChronoUnit .SECONDS );
846
859
muteUserForGuild (user , guild , delaySeconds , ChronoUnit .SECONDS , null );
847
860
LOG .info ("Restored mute for user '{}' (ID: {}) on guild '{}' (ID: {}). Muted until {}" ,
0 commit comments