use of net.kodehawa.mantarobot.core.modules.commands.AliasCommand in project MantaroBot by Mantaro.
the class CommandRegistry method process.
// BEWARE OF INSTANCEOF CALLS
// I know there are better approaches to this, THIS IS JUST A WORKAROUND, DON'T TRY TO REPLICATE THIS.
public boolean process(GuildMessageReceivedEvent event, String cmdName, String content) {
long start = System.currentTimeMillis();
Command command = commands.get(cmdName);
if (command == null) {
command = commands.get(cmdName.toLowerCase());
if (command == null)
return false;
}
// Variable used in lambda expression should be final or effectively final...
final Command cmd = command;
if (MantaroData.db().getMantaroData().getBlackListedUsers().contains(event.getAuthor().getId())) {
return false;
}
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
if (data.getDisabledCommands().contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).getOriginalName() : cmdName)) {
return false;
}
List<String> channelDisabledCommands = data.getChannelSpecificDisabledCommands().get(event.getChannel().getId());
if (channelDisabledCommands != null && channelDisabledCommands.contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).getOriginalName() : cmdName)) {
return false;
}
if (data.getDisabledUsers().contains(event.getAuthor().getId()) && !isAdmin(event.getMember())) {
return false;
}
if (data.getDisabledChannels().contains(event.getChannel().getId()) && (cmd instanceof AliasCommand ? ((AliasCommand) cmd).parentCategory() != Category.MODERATION : cmd.category() != Category.MODERATION)) {
return false;
}
if (conf.isPremiumBot() && (cmd instanceof AliasCommand ? ((AliasCommand) cmd).parentCategory() == Category.CURRENCY : cmd.category() == Category.CURRENCY)) {
return false;
}
if (data.getDisabledCategories().contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).parentCategory() : cmd.category())) {
return false;
}
if (data.getChannelSpecificDisabledCategories().computeIfAbsent(event.getChannel().getId(), c -> new ArrayList<>()).contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).parentCategory() : cmd.category())) {
return false;
}
if (!data.getDisabledRoles().isEmpty() && event.getMember().getRoles().stream().anyMatch(r -> data.getDisabledRoles().contains(r.getId())) && !isAdmin(event.getMember())) {
return false;
}
HashMap<String, List<String>> roleSpecificDisabledCommands = data.getRoleSpecificDisabledCommands();
if (event.getMember().getRoles().stream().anyMatch(r -> roleSpecificDisabledCommands.computeIfAbsent(r.getId(), s -> new ArrayList<>()).contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).getOriginalName() : cmdName)) && !isAdmin(event.getMember())) {
return false;
}
HashMap<String, List<Category>> roleSpecificDisabledCategories = data.getRoleSpecificDisabledCategories();
if (event.getMember().getRoles().stream().anyMatch(r -> roleSpecificDisabledCategories.computeIfAbsent(r.getId(), s -> new ArrayList<>()).contains(cmd instanceof AliasCommand ? ((AliasCommand) cmd).parentCategory() : cmd.category())) && !isAdmin(event.getMember())) {
return false;
}
// If we are in the patreon bot, deny all requests from unknown guilds.
if (conf.isPremiumBot() && !conf.isOwner(event.getAuthor()) && !dbg.isPremium()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like you're trying to use the Patreon bot when this guild is **not** marked as premium. " + "**If you think this is an error please contact Kodehawa#3457 or poke me on #donators in the support guild**").queue();
return false;
}
if (!cmd.permission().test(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.STOP + "You have no permissions to trigger this command :(").queue();
return false;
}
long end = System.currentTimeMillis();
MantaroBot.getInstance().getStatsClient().increment("commands");
log.debug("Command invoked: {}, by {}#{} with timestamp {}", cmdName, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), new Date(System.currentTimeMillis()));
cmd.run(event, cmdName, content);
if (cmd.category() != null && cmd.category().name() != null && !cmd.category().name().isEmpty()) {
MantaroBot.getInstance().getStatsClient().increment("command", "name:" + cmdName);
MantaroBot.getInstance().getStatsClient().increment("category", "name:" + cmd.category().name().toLowerCase());
CommandStatsManager.log(cmdName);
CategoryStatsManager.log(cmd.category().name().toLowerCase());
}
MantaroBot.getInstance().getStatsClient().histogram("command_process_time", (end - start));
return true;
}
Aggregations