@@ -125,15 +125,20 @@ private static boolean shouldBeArchived(MessageChannel channel, Instant archiveA
125125 }
126126
127127 private void handleArchiveFlow (ThreadChannel threadChannel , MessageEmbed embed ) {
128+ helper .getAuthorByHelpThreadId (threadChannel .getIdLong ())
129+ .ifPresentOrElse (authorId -> triggerArchiveFlow (threadChannel , authorId , embed ),
130+ () -> triggerAuthorIdNotFoundArchiveFlow (threadChannel , embed ));
131+ }
132+
133+ private void triggerArchiveFlow (ThreadChannel threadChannel , long authorId ,
134+ MessageEmbed embed ) {
128135
129136 Function <Member , RestAction <Message >> sendEmbedWithMention =
130137 member -> threadChannel .sendMessage (member .getAsMention ()).addEmbeds (embed );
131138
132139 Supplier <RestAction <Message >> sendEmbedWithoutMention =
133140 () -> threadChannel .sendMessageEmbeds (embed );
134141
135- long authorId = helper .getAuthorByHelpThreadId (threadChannel .getIdLong ()).orElseThrow ();
136-
137142 threadChannel .getGuild ()
138143 .retrieveMemberById (authorId )
139144 .mapToResult ()
@@ -151,4 +156,15 @@ private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed)
151156 .flatMap (any -> threadChannel .getManager ().setArchived (true ))
152157 .queue ();
153158 }
159+
160+ private void triggerAuthorIdNotFoundArchiveFlow (ThreadChannel threadChannel ,
161+ MessageEmbed embed ) {
162+
163+ logger .info (
164+ "Was unable to find a matching thread for id: {} in DB, archiving thread without mentioning OP" ,
165+ threadChannel .getId ());
166+ threadChannel .sendMessageEmbeds (embed )
167+ .flatMap (sentEmbed -> threadChannel .getManager ().setArchived (true ))
168+ .queue ();
169+ }
154170}
0 commit comments