-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor resource bundle method and update class instances.
- Loading branch information
1 parent
f70cd96
commit f194bf2
Showing
14 changed files
with
89 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 25 additions & 26 deletions
51
src/main/java/com/severalcircles/flames/events/CommandEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
/* | ||
* Copyright (c) 2021 Several Circles. | ||
*/ | ||
|
||
package com.severalcircles.flames.events; | ||
|
||
import com.severalcircles.flames.Flames; | ||
import com.severalcircles.flames.data.FlamesDataManager; | ||
import com.severalcircles.flames.data.user.FlamesUser; | ||
import com.severalcircles.flames.events.FlamesDiscordEvent; | ||
import com.severalcircles.flames.exception.FlamesException; | ||
import com.severalcircles.flames.exception.handle.ExceptionHandler; | ||
import com.severalcircles.flames.frontend.FlamesCommand; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class CommandEvent extends ListenerAdapter implements FlamesDiscordEvent { | ||
|
||
private final Logger logger = Logger.getLogger(CommandEvent.class.getName()); | ||
|
||
public void register(JDA api) { | ||
api.addEventListener(new CommandEvent()); | ||
Logger.getGlobal().log(Level.FINE, "Registering " + MessageEvent.class.getName()); | ||
logger.log(Level.FINE, "Registering " + MessageEvent.class.getName()); | ||
} | ||
|
||
@Override | ||
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { | ||
new Thread(() ->{ | ||
System.out.println("Slash command detected"); | ||
//noinspection ResultOfMethodCallIgnored | ||
event.deferReply(true); | ||
System.out.println(event.getName()); | ||
for (Map.Entry<String, FlamesCommand> entry : Flames.commandMap.entrySet()) { | ||
if (entry.getKey().contains(event.getName())) { | ||
try { | ||
// System.out.println(Flames.commandMap.get(entry.getKey())); | ||
FlamesUser fl = FlamesDataManager.readUser(event.getUser()); | ||
// throw new BadArgumentsException(fl, "This is a shitpost"); | ||
Flames.commandMap.get(entry.getKey()).execute(event, fl); | ||
} catch (FlamesException e) { | ||
event.replyEmbeds(e.getHandler().handleThenGetFrontend()).complete(); | ||
} catch (Exception e) { | ||
event.replyEmbeds(new ExceptionHandler(e).handleThenGetFrontend()).complete(); | ||
} | ||
} | ||
} | ||
}).start();}} | ||
logger.log(Level.FINE, "Slash command detected"); | ||
|
||
logger.log(Level.FINE, event.getName()); | ||
Flames.commandMap.entrySet().stream() | ||
.filter(entry -> entry.getKey().contains(event.getName())) | ||
.findFirst() | ||
.ifPresentOrElse(entry -> { | ||
try { | ||
FlamesUser flu = FlamesDataManager.readUser(event.getUser()); | ||
entry.getValue().execute(event, flu); | ||
} catch (FlamesException e) { | ||
event.replyEmbeds(e.getHandler().handleThenGetFrontend()).complete(); | ||
} catch (Exception e) { | ||
event.replyEmbeds(new ExceptionHandler(e).handleThenGetFrontend()).complete(); | ||
} | ||
}, () -> { | ||
logger.log(Level.INFO, "No Command Found."); | ||
}); | ||
}).start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters