Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/com/diamondfire/helpbot/HelpBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

public class HelpBot {

public static void main(String[] args) throws LoginException, IOException {
public static void main(String[] args) throws LoginException {
CodeDatabase.initialize();
TagHandler.cacheJson();
HelpBotInstance.initialize();
CodeDifferenceHandler.refresh();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.diamondfire.helpbot.bot.command.executor.checks;

import com.diamondfire.helpbot.bot.command.permissions.Permission;
import com.diamondfire.helpbot.bot.command.reply.PresetBuilder;
import com.diamondfire.helpbot.bot.command.reply.feature.informative.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
Expand All @@ -8,7 +9,8 @@ public class PermissionCheck implements CommandCheck {

@Override
public boolean check(CommandEvent event) {
return event.getCommand().getPermission().hasPermission(event.getMember());
return event.getCommand().getPermission().hasPermission(event.getMember())
|| Permission.getOverrides(event.getCommand()).contains(event.getAuthor().getIdLong());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected ArgumentSet compileArguments() {

@Override
public Permission getPermission() {
return Permission.EXPERT;
return Permission.EXPERT
.setOverrides(this, 808966728201666620L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected ArgumentSet compileArguments() {

@Override
public Permission getPermission() {
return Permission.EXPERT;
return Permission.EXPERT
.setOverrides(this, 808966728201666620L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ protected ArgumentSet compileArguments() {

@Override
public Permission getPermission() {
return Permission.EXPERT;
return Permission.EXPERT
.setOverrides(this, 808966728201666620L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.diamondfire.helpbot.bot.command.permissions;

import com.diamondfire.helpbot.bot.command.impl.Command;
import net.dv8tion.jda.api.entities.Member;

import java.util.HashMap;
import java.util.*;
import java.util.stream.Collectors;

public enum Permission {
BOT_DEVELOPER(589238520145510400L, 999),
Expand All @@ -16,6 +18,7 @@ public enum Permission {
USER(349434193517740033L, 1);

private static final HashMap<Long, Permission> roleMap = new HashMap<>();
private static final HashMap<Command, Set<Long>> overrides = new HashMap<>();

static {
for (Permission perm : values()) {
Expand All @@ -39,6 +42,15 @@ public static Permission fromRole(long roleID) {
return perm;
}

public Permission setOverrides(Command command, Long... userIds) {
overrides.put(command, Arrays.stream(userIds).collect(Collectors.toSet()));
return this;
}

public static Set<Long> getOverrides(Command command) {
return Objects.requireNonNullElse(overrides.get(command), new HashSet<>());
}

public long getRole() {
return role;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public class TagHandler {
private static final List<Tag> tags = new ArrayList<>();
private static final File FILE = ExternalFiles.TAGS;

static {
try {
cacheJson();
} catch (IOException e) {
e.printStackTrace();
}
}

public static List<Tag> getTags() throws IOException {
return tags;
}
Expand Down