aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-07-07 01:22:04 +1000
committerGitHub <noreply@github.com>2023-07-06 17:22:04 +0200
commit5f4281f7d17a4b9e940f9d2d43ec1a4494744d30 (patch)
treebc92a38710e04ebcc23ead5e07ffd175579a573a /src/main
parent0c94c8cf85824c2a8798a4c72d345738b1583388 (diff)
downloadNotEnoughUpdates-5f4281f7d17a4b9e940f9d2d43ec1a4494744d30.tar.gz
NotEnoughUpdates-5f4281f7d17a4b9e940f9d2d43ec1a4494744d30.tar.bz2
NotEnoughUpdates-5f4281f7d17a4b9e940f9d2d43ec1a4494744d30.zip
Adding /neustats repo (#748)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/DiscordMarkdownBuilder.java7
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt47
2 files changed, 49 insertions, 5 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/DiscordMarkdownBuilder.java b/src/main/java/io/github/moulberry/notenoughupdates/util/DiscordMarkdownBuilder.java
index 3c6c5f3d..941615fb 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/DiscordMarkdownBuilder.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/DiscordMarkdownBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 NotEnoughUpdates contributors
+ * Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
@@ -33,7 +33,10 @@ public class DiscordMarkdownBuilder {
}
public DiscordMarkdownBuilder append(String key, Object value) {
- builder.append("[").append(key).append("]").append("[").append(value).append("]").append("\n");
+ if (!key.isEmpty()) {
+ builder.append("[").append(key).append("]");
+ }
+ builder.append("[").append(value).append("]").append("\n");
return this;
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
index 2bc8ae6f..e17e856c 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
@@ -61,10 +61,19 @@ class NEUStatsCommand {
.toString()
)
}.withHelp("Copy the mod list to your clipboard")
+ thenLiteralExecute("repo") {
+ clipboardAndSendMessage(
+ DiscordMarkdownBuilder()
+ .also(::appendRepoStats)
+ .also(::appendAdvancedRepoStats)
+ .toString()
+ )
+ }.withHelp("Copy the repo stats to your clipboard")
thenLiteralExecute("full") {
clipboardAndSendMessage(
DiscordMarkdownBuilder()
.also(::appendStats)
+ .also(::appendAdvancedRepoStats)
.also(::appendModList)
.toString()
)
@@ -166,9 +175,7 @@ class NEUStatsCommand {
)
builder.append("SB Profile", SBInfo.getInstance().currentProfile)
builder.append("Has Advanced Tab", if (SBInfo.getInstance().hasNewTab) "TRUE" else "FALSE")
- builder.category("Repo Stats")
- builder.append("Last Commit", NotEnoughUpdates.INSTANCE.manager.latestRepoCommit)
- builder.append("Loaded Items", NotEnoughUpdates.INSTANCE.manager.itemInformation.size.toString())
+ .also(::appendRepoStats)
}
private fun appendModList(builder: DiscordMarkdownBuilder): DiscordMarkdownBuilder {
@@ -179,6 +186,40 @@ class NEUStatsCommand {
return builder
}
+ private fun appendRepoStats(builder: DiscordMarkdownBuilder): DiscordMarkdownBuilder {
+ val apiData = NotEnoughUpdates.INSTANCE.config.apiData
+ if (apiData.repoUser == "" || apiData.repoName == "" || apiData.repoBranch == "") {
+ NotEnoughUpdates.INSTANCE.config.executeRunnable(23)
+ NotEnoughUpdates.INSTANCE.config.executeRunnable(22)
+ builder.append("", "")
+ builder.category("Reset Repository location")
+ builder.append("", "")
+ } else {
+ builder.category("Repo Stats")
+ builder.append("Last Commit", NotEnoughUpdates.INSTANCE.manager.latestRepoCommit)
+ builder.append("Loaded Items", NotEnoughUpdates.INSTANCE.manager.itemInformation.size.toString())
+ builder.append("Repo Location", "https://github.com/${apiData.repoUser}/${apiData.repoName}/tree/${apiData.repoBranch}")
+ }
+ return builder
+ }
+
+ private fun appendAdvancedRepoStats(builder: DiscordMarkdownBuilder): DiscordMarkdownBuilder {
+ if (NotEnoughUpdates.INSTANCE.manager.repoLocation.isDirectory) {
+ val files = NotEnoughUpdates.INSTANCE.manager.repoLocation.listFiles()
+ builder.category("Repo Files")
+ files?.forEach { file ->
+ if (file.isDirectory) {
+ builder.append(file.name, file.listFiles()?.size)
+ } else if (file.isFile) {
+ builder.append("", file.name)
+ }
+ }
+ } else {
+ builder.category("Repo folder not found!")
+ }
+ return builder
+ }
+
fun CommandContext<ICommandSender>.clipboardAndSendMessage(data: String?) {
if (data == null) {
reply("${DARK_RED}Error occurred trying to perform command.")