Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ This file is basically a checklist of things to do in the codebase.
## Chores

* Add comments
* Role mention rendering
* fix possible race condition so that the bot doesn't start with nonexistent ids

## Implement

* Performance improvements, don't know how yet
* rewrite using https://github.com/discord-jda/JDA because discord4j is ass
* make a waypoint class for the xearos waypoint parser
* Performance improvements, don't know how yet
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ dependencies {
include "com.discord4j:discord4j-core:3.2.7"

*/
extraLibs group: 'com.discord4j', name: 'discord4j-core', version: '3.2.7'
extraLibs (group: 'net.dv8tion', name: 'JDA', version: '5.6.1') {
exclude module: 'opus-java' // required for encoding audio into opus, not needed if audio is already provided in opus encoding
exclude module: 'tink' // required for encrypting and decrypting audio
}
extraLibs group: 'com.github.zafarkhaja', name: 'java-semver', version: '0.10.2'
extraLibs group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'

configurations.implementation.extendsFrom(configurations.extraLibs)
}
Expand Down
12 changes: 10 additions & 2 deletions docs/md/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ messages.server.starting.allowed=true
| functions.promotions.enabled | true | false | are tips and hints/promotion embeds allowed to be sent to Discord |
| functions.bot.enabled | true | false | is two-way chat (the bot) enabled? |
| functions.bot.token | "TOKEN" | (blank string) | bot token |
| functions.bot.prefix | $ | $ | bot command prefix |
| functions.update | true | false | auto check for updates |
| webhook.url | <https://discord.com/api/webhooks/000/ABCDEF> | (blank string) | url of webhook |
| messages.server.starting | The server is starting! | messages.server.starting | start message |
Expand All @@ -65,7 +64,6 @@ messages.server.starting.allowed=true
| messages.server.stopped.allowed | true | false | stop message allowed? |
| messages.server.started.allowed | true | false | opened/fully started message |
| messages.server.stopping.allowed | true | false | stopping message allowed? |
| messages.server.game.allowed | true | false | default leave/join, advancement and death messages allowed? (currently not functional) |

1. default, as in it's the value generated with the file
2. fallback, as in if the key isn't found, this value will be used instead
Expand All @@ -80,6 +78,16 @@ Out-of-Character messages. Ending a message with double slashes (`//`) will tell

Send a message in the desired Discord channel, and make that message appear in game!

### Utility Commands

Utility slash commands that you can use to do things like get player listing right from discord or get the current time in the server. Current commands:

* `time`: get the current time and overworld weather in the server;
* `mods`: get a list of both-sided-mods/plugins;
* `list`: get a list of currently online players;
* `stats`: get some technical details of the server;
* `about`: get some info about the mod.

### Xaero's World Map support

[Xaero's World Map](https://modrinth.com/mod/xaeros-world-map) has a feature, with which you can share waypoints in chat for everyone to save and add. This will be converted to readable coordinates and dimension data when sent to Discord!
Expand Down
Binary file added docs/res/works.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.16.10

# Mod Properties
mod_version=0.3.1-alpha.6+fabric
mod_version=1.0.0+fabric
maven_group=com.github.pinmacaroon.dchook
archives_base_name=dchook

Expand Down
152 changes: 75 additions & 77 deletions src/main/java/com/github/pinmacaroon/dchook/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,100 +24,98 @@

public class Hook implements DedicatedServerModInitializer {

public static final String MOD_ID = "dchook";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final HttpClient HTTPCLIENT = HttpClient.newHttpClient();
public static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.create();
public static final Version VERSION = new Version.Builder()
.setMajorVersion(0)
.setMinorVersion(3)
.setPatchVersion(2)
public static final String MOD_ID = "dchook";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final HttpClient HTTPCLIENT = HttpClient.newHttpClient();
public static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.create();
public static final Version VERSION = new Version.Builder()
.setMajorVersion(1)
.setMinorVersion(0)
.setPatchVersion(0)
.setBuildMetadata("fabric")
.setPreReleaseVersion("alpha", "6")
//.setPreReleaseVersion("alpha", "2")
.build();
public static final String DOCS_URL = "https://modrinth.com/mod/dchook";
public static final Random RANDOM = new Random(Instant.now().getEpochSecond());
@SuppressWarnings("RegExpRedundantEscape")
public static final String DOCS_URL = "https://modrinth.com/mod/dchook";
public static final Random RANDOM = new Random(Instant.now().getEpochSecond());
@SuppressWarnings("RegExpRedundantEscape")
public static final Pattern WEBHOOK_URL_PATTERN = Pattern.compile(
"^https:\\/\\/(ptb\\.|canary\\.)?discord\\.com\\/api\\/webhooks\\/\\d+\\/.+$"
);
"^https:\\/\\/(ptb\\.|canary\\.)?discord\\.com\\/api\\/webhooks\\/\\d+\\/.+$"
);

public static volatile Bot BOT;
public static Thread BOT_THREAD;
public static volatile Bot BOT;

private static MinecraftServer MINECRAFT_SERVER;
private static MinecraftServer MINECRAFT_SERVER;

public static MinecraftServer getMinecraftServer() {
return MINECRAFT_SERVER;
}
public static MinecraftServer getGameServer() {
return MINECRAFT_SERVER;
}

public static void setMinecraftServer(MinecraftServer minecraftServer) {
MINECRAFT_SERVER = minecraftServer;
}
public static void setMinecraftServer(MinecraftServer minecraftServer) {
MINECRAFT_SERVER = minecraftServer;
}

@Override
public void onInitializeServer() {
ModConfigs.registerConfigs();
@Override
public void onInitializeServer() {
ModConfigs.registerConfigs();

if(!ModConfigs.FUNCTIONS_MODENABLED){
LOGGER.error("hook mod was explicitly told to not operate!");
return;
}
if(!ModConfigs.FUNCTIONS_MODENABLED){
LOGGER.error("hook mod was explicitly told to not operate!");
return;
}

if(!WEBHOOK_URL_PATTERN.matcher(ModConfigs.WEBHOOK_URL).find()){
LOGGER.error("webhook url was not a valid discord api endpoint, thus the mod cant operate!");
return;
}
if(!WEBHOOK_URL_PATTERN.matcher(ModConfigs.WEBHOOK_URL).find()){
LOGGER.error("webhook url was not a valid discord api endpoint, thus the mod cant operate!");
return;
}

if(ModConfigs.FUNCTIONS_BOT_ENABLED){
try {
BOT = new Bot(ModConfigs.FUNCTIONS_BOT_TOKEN, ModConfigs.FUNCTIONS_BOT_PREFIX.toCharArray()[0]);
} catch (Exception e){
LOGGER.error("couldn't initialise bot, two way chat disabled");
if(ModConfigs.FUNCTIONS_BOT_ENABLED){
try {
BOT = new Bot(ModConfigs.FUNCTIONS_BOT_TOKEN);
} catch (Exception e){
LOGGER.error("couldn't initialise bot, two way chat disabled");
LOGGER.error("{}:{}", e.getClass().getName(), e.getMessage());
return;
}
}

try {
HttpRequest get_webhook = HttpRequest.newBuilder()
.GET()
.uri(URI.create(ModConfigs.WEBHOOK_URL))
.build();

HttpResponse<String> response = HTTPCLIENT.send(get_webhook, HttpResponse.BodyHandlers.ofString());
int status = response.statusCode();
JsonObject body = JsonParser.parseString(response.body()).getAsJsonObject();
if(status != 200){
LOGGER.error(
"the webhook was not found or couldn't reach discord servers! discord said: '{}'",
body.get("message").getAsString()
);
return;
}
Thread bot_rutime_thread = new Thread(() -> {
return;
}
}

try {
HttpRequest get_webhook = HttpRequest.newBuilder()
.GET()
.uri(URI.create(ModConfigs.WEBHOOK_URL))
.build();

HttpResponse<String> response = HTTPCLIENT.send(get_webhook, HttpResponse.BodyHandlers.ofString());
int status = response.statusCode();
JsonObject body = JsonParser.parseString(response.body()).getAsJsonObject();
if(status != 200){
LOGGER.error(
"the webhook was not found or couldn't reach discord servers! discord said: '{}'",
body.get("message").getAsString()
);
return;
}
Thread bot_rutime_thread = new Thread(() -> {
while (BOT == null) {
Thread.onSpinWait();
}
BOT.setGUILD_ID(body.get("guild_id").getAsLong());
BOT.setCHANNEL_ID(body.get("channel_id").getAsLong());
BOT_THREAD = BOT.start();
});
bot_rutime_thread.start();
} catch (Exception e) {
LOGGER.error("{}:{}", e.getClass().getName(), e.getMessage());
throw new RuntimeException(e);
BOT.setGUILD_ID(body.get("guild_id").getAsLong());
BOT.setCHANNEL_ID(body.get("channel_id").getAsLong());
});
bot_rutime_thread.start();
} catch (Exception e) {
LOGGER.error("{}:{}", e.getClass().getName(), e.getMessage());
throw new RuntimeException(e);
}

if(ModConfigs.FUNCTIONS_UPDATE) VersionChecker.checkVersion();
if(ModConfigs.FUNCTIONS_UPDATE) VersionChecker.checkVersion();

LOGGER.info("all checks succeeded, starting webhook managing! version: {}", VERSION);
if(!ModConfigs.FUNCTIONS_PROMOTIONS_ENABLED){
LOGGER.warn("promotions were disabled by config. please consider turning them back on to support the mod!");
}
LOGGER.info("all checks succeeded, starting webhook managing! version: {}", VERSION);
if(!ModConfigs.FUNCTIONS_PROMOTIONS_ENABLED){
LOGGER.warn("promotions were disabled by config. please consider turning them back on to support the mod!");
}

EventListeners.registerEventListeners();
}
EventListeners.registerEventListeners();
}
}
Loading