Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
Upgrade to Discord4J 3.0.14, add all_roles config option, change comm…
Browse files Browse the repository at this point in the history
…and format
  • Loading branch information
132ikl committed May 27, 2020
1 parent dd83cea commit 9fede92
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 84 deletions.
52 changes: 26 additions & 26 deletions .idea/artifacts/Server_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Socket;
import java.net.SocketException;

public final class MessageReceiver {
private final Socket socket;
Expand Down Expand Up @@ -82,7 +83,7 @@ private void receiverThread() {
System.err.println("[PolyChat] Warning: Illegal message id: " + messageId);
}
}
} catch (InterruptedIOException | EOFException ignored) {
} catch (InterruptedIOException | EOFException | SocketException ignored) {
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class PlayerStatusMessage extends AbstractMessage {
private final String userName, serverID, formattedPrefix;
private final boolean joined, silent;

public PlayerStatusMessage(String userName, String serverID, String prefixJson, boolean joined, boolean silent) {
public PlayerStatusMessage(String userName, String serverID, String formattedJson, boolean joined, boolean silent) {
this.userName = userName;
this.serverID = serverID;
this.formattedPrefix = prefixJson;
this.formattedPrefix = formattedJson;
this.joined = joined;
this.silent = silent;
}
Expand Down
2 changes: 1 addition & 1 deletion Server/Server.iml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<orderEntry type="module" module-name="NetworkLibrary" />
<orderEntry type="library" name="org.yaml:snakeyaml:1.25" level="project" />
<orderEntry type="library" name="com.vdurmont:emoji-java:5.1.0" level="project" />
<orderEntry type="library" name="com.discord4j:discord4j-core:3.0.10" level="project" />
<orderEntry type="library" name="com.discord4j:discord4j-core:3.0.14" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,18 @@ public void registerCommands() throws FileNotFoundException, NoSuchMethodExcepti

ArrayList<String> commandChannels = (ArrayList<String>) yamlObj.remove("channels");
manager.setChannels(commandChannels);
for (Object entryObj : yamlObj.entrySet()) {

Map.Entry<String, ArrayList> entry = (Map.Entry<String, ArrayList>) entryObj;
ArrayList<String> prefixRoles = (ArrayList<String>) yamlObj.remove("all_roles");
manager.addPrefixRoles(prefixRoles);

for (Object entryObj : (ArrayList) yamlObj.get("commands")) {
LinkedHashMap entry = (LinkedHashMap) entryObj;
HashMap<String, String> argMap = new HashMap<>();
for (Object mapObj : entry.getValue()) {
for (Object mapObj : (ArrayList) entry.values().iterator().next()) {
argMap.putAll((HashMap<String, String>) mapObj);
}

String name = entry.getKey();
String name = (String) entry.keySet().iterator().next(); // kinda ugly but way too deep down the rabbit hole
String type = argMap.remove("type");

Class<? extends Command> element = COMMAND_TYPES.get(type);
Expand Down Expand Up @@ -143,8 +146,9 @@ public boolean processCommand(Message message) {
}

public void processMessage(Message message) {
ChatMessage discordMessage = new ChatMessage(message.getAuthorAsMember().block().getDisplayName() + ":", formatMessage(message), "empty");
System.out.println(discordMessage.getMessage());
String author = message.getAuthorAsMember().block().getDisplayName() + ":";
ChatMessage discordMessage = new ChatMessage(author, formatMessage(message), "empty");
System.out.println(String.format("[Discord] %s %s", author, discordMessage.getMessage()));
Main.chatServer.sendMessage(discordMessage);
}

Expand Down
2 changes: 1 addition & 1 deletion Server/src/club/moddedminecraft/polychat/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static boolean handleConfig() {

//Initializes the connection to the discord API using the API token
public static void initDiscord() {
discordClient = new DiscordClientBuilder(config.getProperty("api_token")).build();
discordClient = DiscordClientBuilder.create(config.getProperty("api_token")).build();
discordHandler.registerEventSubscribers(discordClient);
discordClient.login().block();
}
Expand Down
Loading

0 comments on commit 9fede92

Please sign in to comment.