Skip to content

Commit

Permalink
chore: merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Greazi-Times committed Jun 8, 2022
2 parents 887ad72 + de603ea commit 3585dd6
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Backup/members/MemberStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class MemberStorage {

public MemberStorage() {
if (!SimpleSettings.getInstance().isMysqlEnabled()) return;
if (!SimpleSettings.getMysqlEnabled()) return;

ITable membersTable = SimpleBot.getMySQL().table("members");

Expand All @@ -42,7 +42,7 @@ public MemberStorage() {
SimpleBot.getMySQL().getConnection().prepareStatement("alter table "+membersTable.getName()+" add primary key(`discord_id`);");

Common.warning("Adding all members");
Guild mainGuild = SimpleBot.getJDA().getGuildById(SimpleSettings.getInstance().getMainGuild());
Guild mainGuild = SimpleBot.getJDA().getGuildById(SimpleSettings.getMainGuild());
mainGuild.getMembers().forEach(member -> {
Insert query = membersTable.insert();
query.field("discord_id", member.getId());
Expand Down
27 changes: 18 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# [0.5.0](https://github.com/Greazi-Times/Discord_Bot_Foundation/compare/v0.4.1...v0.5.0) (2022-03-23)


### Bug Fixes

* Changed common file to better colors ([7f38774](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/7f387745e59b8be59aa2db84a71f10177f668a7f))
* Changed to a better color ([d04b57f](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/d04b57f0d73c1b8ea32017e385c0bbb052e47845))
* Fixed MySQL settings ([2f2e7b0](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/2f2e7b05e93dcaa5ae72d3ea47e01e69034202c3))
* Fixed some issues in the main file ([63033aa](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/63033aa06a20001b306aaf59e311a676d534bef2))
* Updated SlashCommand handler ([14a93c4](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/14a93c43cdd1802e0c4b208af0db2984a59225c3))


### Features

* Added ping command ([6276bc0](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/6276bc0ca67850d49e0bd9443d78442800945560))



## [0.4.1](https://github.com/Greazi-Times/Discord_Bot_Foundation/compare/v0.4.0...v0.4.1) (2022-03-07)


Expand Down Expand Up @@ -46,12 +64,3 @@



## [0.1.1](https://github.com/Greazi-Times/Discord_Bot_Foundation/compare/v0.1.0...v0.1.1) (2022-02-28)


### Bug Fixes

* realse workflow ([2824495](https://github.com/Greazi-Times/Discord_Bot_Foundation/commit/2824495a1bcee51f353e48f7dd8ec70cec62c9bb))



Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.greazi.discordbotfoundation.command;

import com.greazi.discordbotfoundation.SimpleBot;
import com.greazi.discordbotfoundation.debug.Debugger;
import com.greazi.discordbotfoundation.settings.SimpleSettings;
import com.greazi.discordbotfoundation.utils.SimpleEmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.api.interactions.commands.build.*;
import net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class SlashCommandHandler extends ListenerAdapter {

private final HashMap<String, SimpleSlashCommand> cmdList = new HashMap<>();
private final List<SlashCommandData> slashCommands = new ArrayList<>();

public SlashCommandHandler(){
Debugger.debug("SlashCommandHandler", "SlashCommandHandler main method");
SimpleBot.getJDA().addEventListener(this);
}

public SlashCommandHandler addCommand(SimpleSlashCommand module) {
Debugger.debug("SlashCommandHandler", "Start of addCommand(...);27");

SlashCommandData command = Commands.slash(module.getCommand(), module.getDescription());
Debugger.debug("SlashCommandHandler", "Retrieved SlashCommandData; " + module.getCommand() + ", " + module.getDescription());

Debugger.debug("SlashCommandHandler", " Retrieving subcommands for; " + module.getCommand());
List<SubcommandData> moduleSubcommands = module.getSubCommands();
for (SubcommandData var : moduleSubcommands) {
command.addSubcommands(var);
Debugger.debug("SlashCommandHandler", " - " + var);
}

Debugger.debug("SlashCommandHandler", " Retrieving subcommand groups for; " + module.getCommand());
List<SubcommandGroupData> moduleSubcommandGroup = module.getSubcommandGroup();
for (SubcommandGroupData var : moduleSubcommandGroup) {
command.addSubcommandGroups(var);
Debugger.debug("SlashCommandHandler", " - " + var);
}

Debugger.debug("SlashCommandHandler", " Checking if subcommands exists for; " + module.getCommand());
if (!module.getSubCommands().isEmpty() || !module.getSubcommandGroup().isEmpty()){
Debugger.debug("SlashCommandHandler", " No subcommands getting options;");
List<OptionData> moduleOptions = module.getOptions();
for (OptionData var : moduleOptions) {
command.addOptions(var);
Debugger.debug("SlashCommandHandler", " - " + var);
}
}
Debugger.debug("SlashCommandHandler", " Setting other info;",
" Default enabled; " + module.getDefaultEnabled(),
" Description; " + module.getDescription());
command.setDefaultEnabled(module.getDefaultEnabled());
command.setDescription(module.getDescription());

Debugger.debug("SlashCommandHandler", " Adding the whole command; " + command.getName());
slashCommands.add(command);
cmdList.put(module.getCommand(), module);

return this;
}

public void registerCommands() {
Debugger.debug("SlashCommandHandler", "Start of registerCommands()");
if (slashCommands.isEmpty()) return;

SimpleBot.getGuild().updateCommands()
.addCommands(slashCommands)
.queue(commands -> {
commands.forEach(cmd -> {
Debugger.debug("SlashCommandHandler", " Getting command from cmdList " + cmd.getName());
SimpleSlashCommand module = cmdList.get(cmd.getName());

Debugger.debug("SlashCommandHandler", " Adding privilages to " + cmd.getName());
List<CommandPrivilege> commandPrivileges = new ArrayList<>();
module.getDisabledRoles().forEach(role -> commandPrivileges.add(CommandPrivilege.disableRole(role.getId())));
module.getDisabledUsers().forEach(user -> commandPrivileges.add(CommandPrivilege.disableUser(user.getId())));
module.getEnabledRoles().forEach(role -> commandPrivileges.add(CommandPrivilege.enableRole(role.getId())));
module.getEnabledUsers().forEach(user -> commandPrivileges.add(CommandPrivilege.enableUser(user.getId())));

Debugger.debug("SlashCommandHandler", " Updating the command " + cmd.getName());
SimpleBot.getGuild().updateCommandPrivilegesById(cmd.getId(), commandPrivileges);
});
});
}

@Override
@SubscribeEvent
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
Debugger.debug("SlashCommandHandler", "A slash command event has been triggered onSlashCommandInteraction(...);96");
// Retrieve the command class from the command that has been run
SimpleSlashCommand module = cmdList.get(event.getName());

if (module == null) {
event.replyEmbeds(new SimpleEmbedBuilder("ERROR - command not found")
.text("The command that you have used does not exist or hasn't been activated!",
"Please contact an admin and report this error!")
.error()
.setFooter("")
.build()).setEphemeral(true).queue();
return;
}

Debugger.debug("SlashCommandHandler", " Found event; " + module);

if (module.getGuildOnly() && !Objects.requireNonNull(event.getGuild()).getId().equals(SimpleSettings.getMainGuild())){
return;
}

if (event.getTextChannel().isNSFW() && !module.getNsfwOnly()){
return;
}

Debugger.debug("SlashCommandHandler", " Executing command logic");
module.execute(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.NonNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -25,7 +24,7 @@ public final class Debugger {
/**
* Get if the given section is being debugged
* <p>
* You can set if the section is debugged by setting it in "Debug" key in your settings.yml,
* You can set if the section is debugged by setting it in "Debug" key in your settings.yaml,
* by default your class extending {@link SimpleSettings}
* <p>
* If you set Debug to ["*"] this will always return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,6 @@ public static String Password(){
public static String Debug(){
return getString("Debug");
}


}
1 change: 1 addition & 0 deletions src/main/resources/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: "0.5.0"

0 comments on commit 3585dd6

Please sign in to comment.