Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/FixedDev/command-flow into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
FixedDev committed Jan 6, 2024
2 parents 150d65d + a497271 commit e68ebeb
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 @@ -24,7 +24,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>team.unnamed</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import team.unnamed.commandflow.Authorizer;
import team.unnamed.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 @@ -6,9 +6,10 @@
import team.unnamed.commandflow.exception.CommandException;
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 @@ -23,11 +24,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 @@ -37,7 +43,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 @@ -48,7 +58,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 team.unnamed.commandflow.annotated.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 team.unnamed.commandflow.part.CommandPart;
import team.unnamed.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 e68ebeb

Please sign in to comment.