Skip to content

Commit

Permalink
Merge pull request #42 from MattyHD0/mattyhd0
Browse files Browse the repository at this point in the history
JDA Update and fixed
  • Loading branch information
FixedDev authored Nov 19, 2023
2 parents 67dce01 + b1e1fa0 commit a497271
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Discord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_208</version>
<version>5.0.0-beta.17</version>
</dependency>
<dependency>
<groupId>me.fixeddev</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import me.fixeddev.commandflow.Authorizer;
import me.fixeddev.commandflow.Namespace;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.GuildChannel;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;

public class DiscordAuthorizer implements Authorizer {

Expand All @@ -22,7 +22,7 @@ public boolean isAuthorized(Namespace namespace, String permission) {
return true;
}

GuildChannel channel = message.getTextChannel();
GuildChannel channel = message.getGuildChannel();
Permission permissionValue;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import me.fixeddev.commandflow.exception.NoPermissionsException;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.kyori.adventure.text.Component;

Expand All @@ -28,11 +29,16 @@ public MessageListener(CommandManager commandManager, String commandPrefix) {
}

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
public void onMessageReceived(MessageReceivedEvent event) {

if(!(event.getChannel() instanceof TextChannel)){
return;
}

Member member = event.getMember();
User user = event.getAuthor();
Message message = event.getMessage();
TextChannel channel = event.getChannel();
TextChannel channel = event.getChannel().asTextChannel();

String rawMessage = event.getMessage().getContentRaw();

Expand All @@ -42,7 +48,11 @@ public void onGuildMessageReceived(GuildMessageReceivedEvent event) {

rawMessage = rawMessage.substring(commandPrefix.length());

String label = rawMessage.substring(0, rawMessage.indexOf(" "));
String label = rawMessage;

if(label.indexOf(" ") > 0){
label = rawMessage.substring(0, rawMessage.indexOf(" "));
}

Namespace namespace = Namespace.create();

Expand All @@ -53,7 +63,7 @@ public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
namespace.setObject(String.class, "label", label);

try {
commandManager.execute(namespace, rawMessage.substring(commandPrefix.length()));
commandManager.execute(namespace, rawMessage);
} catch (CommandException e) {
CommandException exceptionToSend = e;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import me.fixeddev.commandflow.discord.annotation.Sender;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

public class DiscordModule extends AbstractModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getName() {
@Override
public List<? extends Member> parseValue(CommandContext context, ArgumentStack stack, CommandPart parent) throws ArgumentParseException {
Message message = context.getObject(Message.class, DiscordCommandManager.MESSAGE_NAMESPACE);
Guild guild = message.getTextChannel().getGuild();
Guild guild = message.getGuild();

String target = stack.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import me.fixeddev.commandflow.part.CommandPart;
import me.fixeddev.commandflow.stack.ArgumentStack;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.kyori.adventure.text.Component;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public UserPart(String name) {
@Override
public List<? extends User> parseValue(CommandContext context, ArgumentStack stack, CommandPart parent) throws ArgumentParseException {
Message message = context.getObject(Message.class, DiscordCommandManager.MESSAGE_NAMESPACE);
Guild guild = message.getTextChannel().getGuild();
Guild guild = message.getGuild();

String target = stack.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static boolean isRoleMention(String argument) {

private static boolean isMention(String argument, String mentionTypeIdentifier) {
return argument.startsWith("<" + mentionTypeIdentifier) && argument.endsWith(">")
&& argument.length() == (20 + mentionTypeIdentifier.length());
&& argument.length() >= (20 + mentionTypeIdentifier.length());
}

}

0 comments on commit a497271

Please sign in to comment.