Skip to content

Commit

Permalink
Check for deletion/deactivation when joining
Browse files Browse the repository at this point in the history
  • Loading branch information
polypixeldev committed Sep 10, 2024
1 parent aca1470 commit d417e80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/com/hackclub/hccore/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,20 @@ public void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
}

public static boolean isSlackJoinAllowed(PlayerData data) {
if (!HCCorePlugin.getPlugin(HCCorePlugin.class).getConfig()
HCCorePlugin plugin = HCCorePlugin.getPlugin(HCCorePlugin.class);

if (!plugin.getConfig()
.getBoolean("settings.slack-link.enabled", false)) {
return true;
}
if (!HCCorePlugin.getPlugin(HCCorePlugin.class).getConfig()
if (!plugin.getConfig()
.getBoolean("settings.slack-link.required", false)) {
return true;
}
return data.getSlackId() != null;

String id = data.getSlackId();

return !plugin.getSlackBot().isDeactivated(id);
}


Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/hackclub/hccore/slack/SlackBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,21 @@ public void onCustomAdvancementProgressed(ProgressionUpdateEvent e) {
}
}

public boolean isDeactivated(String id) {
MethodsClient client = app.getClient();

try {
var res = client.usersInfo(r -> r.token(getBotToken()).user(id));

return res.getUser().isDeleted();
} catch (SlackApiException e) {
return true;
} catch (IOException e) {
e.printStackTrace();
return true;
}
}

private String getSlackChannel() {
String id = this.plugin.getConfig().getString("settings.slack-link.channel-id");

Expand Down

0 comments on commit d417e80

Please sign in to comment.