Skip to content

Commit 7fe41ef

Browse files
authored
Merge pull request #180 from hackclub/deactivated-check
Check for deletion/deactivation when joining
2 parents aca1470 + d417e80 commit 7fe41ef

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/com/hackclub/hccore/listeners/PlayerListener.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,20 @@ public void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
9292
}
9393

9494
public static boolean isSlackJoinAllowed(PlayerData data) {
95-
if (!HCCorePlugin.getPlugin(HCCorePlugin.class).getConfig()
95+
HCCorePlugin plugin = HCCorePlugin.getPlugin(HCCorePlugin.class);
96+
97+
if (!plugin.getConfig()
9698
.getBoolean("settings.slack-link.enabled", false)) {
9799
return true;
98100
}
99-
if (!HCCorePlugin.getPlugin(HCCorePlugin.class).getConfig()
101+
if (!plugin.getConfig()
100102
.getBoolean("settings.slack-link.required", false)) {
101103
return true;
102104
}
103-
return data.getSlackId() != null;
105+
106+
String id = data.getSlackId();
107+
108+
return !plugin.getSlackBot().isDeactivated(id);
104109
}
105110

106111

src/main/java/com/hackclub/hccore/slack/SlackBot.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,21 @@ public void onCustomAdvancementProgressed(ProgressionUpdateEvent e) {
460460
}
461461
}
462462

463+
public boolean isDeactivated(String id) {
464+
MethodsClient client = app.getClient();
465+
466+
try {
467+
var res = client.usersInfo(r -> r.token(getBotToken()).user(id));
468+
469+
return res.getUser().isDeleted();
470+
} catch (SlackApiException e) {
471+
return true;
472+
} catch (IOException e) {
473+
e.printStackTrace();
474+
return true;
475+
}
476+
}
477+
463478
private String getSlackChannel() {
464479
String id = this.plugin.getConfig().getString("settings.slack-link.channel-id");
465480

0 commit comments

Comments
 (0)