|
5 | 5 | import net.dv8tion.jda.api.Permission; |
6 | 6 | import net.dv8tion.jda.api.entities.Guild; |
7 | 7 | import net.dv8tion.jda.api.entities.MessageEmbed; |
| 8 | +import net.dv8tion.jda.api.entities.ScheduledEvent; |
| 9 | +import net.dv8tion.jda.api.entities.User; |
8 | 10 | import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; |
9 | 11 | import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; |
10 | 12 | import net.dv8tion.jda.api.exceptions.InsufficientPermissionException; |
@@ -574,6 +576,30 @@ public static void endGame(String gamePk, GameState currentState, String scoreca |
574 | 576 | } catch (InsufficientPermissionException ignored) { |
575 | 577 | logger.debug("Insufficient permissions to send message to channel " + game.channelId()); |
576 | 578 | } |
| 579 | + |
| 580 | + // Check for scheduled game and end it, game is over |
| 581 | + List<ScheduledEvent> events = channel.getGuild().getScheduledEvents(); |
| 582 | + for (ScheduledEvent event : events) { |
| 583 | + User creator = event.getCreator(); |
| 584 | + // If no creator, skip |
| 585 | + if (creator == null) continue; |
| 586 | + // If not us, skip |
| 587 | + if (!creator.getId().equals(jda.getSelfUser().getId())) continue; |
| 588 | + |
| 589 | + // Get description |
| 590 | + String description = event.getDescription(); |
| 591 | + // If no description, skip |
| 592 | + if (description == null) continue; |
| 593 | + // Game link is at very end |
| 594 | + String id = description.split("/")[description.split("/").length - 1]; |
| 595 | + |
| 596 | + // If we can't do anything, skip |
| 597 | + if (!channel.getGuild().getSelfMember().hasPermission(Permission.MANAGE_EVENTS)) continue; |
| 598 | + |
| 599 | + if (id.equals(gamePk)) { |
| 600 | + event.delete().queue(); |
| 601 | + } |
| 602 | + } |
577 | 603 | } |
578 | 604 |
|
579 | 605 | // Remove the games from the active games list |
|
0 commit comments