Skip to content

Commit

Permalink
Show latest 5 commits in help command
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed May 30, 2024
1 parent 994a8cc commit 5e89f6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
22 changes: 22 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ tasks.register('run', JavaExec).configure {
})
}

abstract class Log extends DefaultTask {
@OutputFile
abstract RegularFileProperty getOutput()

Log() {
outputs.upToDateWhen { false }
}

@TaskAction
void exec() {
new ProcessBuilder('git', 'log', '-5', '--pretty=oneline')
.redirectOutput(getOutput().asFile.get())
.start().waitFor()
}
}

tasks.register('gitLog', Log) {
it.output.set(new File(project.buildDir, 'gitlog'))
}

java.toolchain.languageVersion = JavaLanguageVersion.of(21)
java.toolchain.vendor = JvmVendorSpec.GRAAL_VM

Expand Down Expand Up @@ -151,6 +171,8 @@ shadowJar {
mergeServiceFiles()
archiveClassifier = 'all'
archiveFile.set(project.file("$buildDir/libs/camelot-all.jar"))
dependsOn(tasks.gitLog)
from(tasks.gitLog.output)
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public HelpCommand(ButtonManager buttonManager) {
super(buttonManager);
this.name = "help";
this.help = "Show information about the bot's commands";
this.itemsPerPage = 25;
this.itemsPerPage = 15;
}

@Override
Expand All @@ -45,7 +45,20 @@ public CompletableFuture<MessageEditData> createMessage(int page, SimpleData dat
public EmbedBuilder getHelpStartingAt(int index) {
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor(Common.NAME_WITH_VERSION, Common.REPO, BotMain.get().getSelfUser().getAvatarUrl());
embed.setDescription("All registered commands:");
embed.setDescription("## Latest commits:\n");

appendCommits: try (var is = HelpCommand.class.getResourceAsStream("/gitlog")) {
if (is == null) break appendCommits;
var lines = new String(is.readAllBytes()).split("\n");
for (String line : lines) {
var split = line.split(" ", 2);
embed.appendDescription(STR."- [\{split[1]}](\{Common.REPO}/commit/\{split[0]})\n");
}
} catch (Exception ex) {
embed.appendDescription("Failed to read git log.\n");
}

embed.appendDescription("\n## Registered commands:");

List<Command> commandList = Commands.get().getCommands();
commandList.addAll(Commands.get().getSlashCommands());
Expand Down

0 comments on commit 5e89f6c

Please sign in to comment.