Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move away from !prefix commands #287

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 0 additions & 4 deletions src/main/java/org/geysermc/discordbot/GeyserBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public static void main(String[] args) throws IOException, LoginException {
CommandClientBuilder client = new CommandClientBuilder();
client.setActivity(null);
client.setOwnerId("0"); // No owner
client.setPrefix(PropertiesManager.getPrefix());
client.useHelpBuilder(false);
client.addCommands(COMMANDS.toArray(new Command[0]));
client.addSlashCommands(SLASH_COMMANDS.toArray(new SlashCommand[0]));
Expand All @@ -176,9 +175,6 @@ public static void main(String[] args) throws IOException, LoginException {
CommandClientBuilder tagClient = new CommandClientBuilder();
tagClient.setActivity(null);
tagClient.setOwnerId("0"); // No owner
String tagPrefix = PropertiesManager.getPrefix() + PropertiesManager.getPrefix();
tagClient.setPrefix(tagPrefix);
tagClient.setPrefixes(new String[] {"!tag "});
tagClient.useHelpBuilder(false);
tagClient.addCommands(TagsManager.getTags().toArray(new Command[0]));
tagClient.setListener(new TagsListener());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ public DownloadCommand() {
);
}

@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));

String program = "geyser";
if (!args.get(0).isEmpty()) {
program = args.get(0);
}

DownloadOption downloadOption = optionsToRepository.getOrDefault(program.toLowerCase(Locale.ROOT), this.defaultDownloadOption);

event.getMessage().replyEmbeds(new EmbedBuilder()
.setTitle("Download " + downloadOption.friendlyName)
.setDescription("Download at " + downloadOption.downloadUrl)
.setThumbnail(downloadOption.imageUrl)
.setColor(BotColors.SUCCESS.getColor())
.build()).queue();
}

@Override
protected void execute(SlashCommandEvent event) {
String program = event.optString("program", "geyser");
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/org/geysermc/discordbot/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.geysermc.discordbot.GeyserBot;
import org.geysermc.discordbot.util.BotColors;
import org.geysermc.discordbot.util.PropertiesManager;

import java.util.Comparator;
import java.util.stream.Collectors;

/**
* Handle the help command
Expand All @@ -54,17 +51,12 @@ protected void execute(SlashCommandEvent event) {
event.replyEmbeds(handle("/")).queue();
}

@Override
protected void execute(CommandEvent event) {
event.getMessage().replyEmbeds(handle(PropertiesManager.getPrefix())).queue();
}

private MessageEmbed handle(String prefix) {
EmbedBuilder helpEmbed = new EmbedBuilder()
.setColor(BotColors.SUCCESS.getColor())
.setTitle("Geyser Bot Help");

for (Command command : GeyserBot.COMMANDS.stream().sorted(Comparator.comparing(Command::getName)).collect(Collectors.toList())) {
for (Command command : GeyserBot.COMMANDS.stream().sorted(Comparator.comparing(Command::getName)).toList()) {
if (!command.isHidden()) {
helpEmbed.addField("`" + prefix + command.getName() + (command.getArguments() != null ? " " + command.getArguments() : "") + "`", command.getHelp(), true);
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/org/geysermc/discordbot/commands/IssueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -78,18 +77,6 @@ protected void execute(SlashCommandEvent event) {
event.replyEmbeds(handle(issue, repo)).queue();
}

@Override
protected void execute(CommandEvent event) {
Matcher matcherIssue = ISSUE_PATTERN.matcher(event.getArgs());

if (!matcherIssue.find()) {
MessageHelper.errorResponse(event, "Invalid Issue Format", "Please specify the issue you wish to locate.\nEG: `#100` or `100`");
return;
}

event.getMessage().replyEmbeds(handle(Integer.parseInt(matcherIssue.group(2)), event.getArgs().replace(matcherIssue.group(0), ""))).queue();
}

private MessageEmbed handle(int issueNumber, String repoString) {
GHIssue issue;
GHUser user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public LeaderboardCommand() {
this.help = "Sends a link to the leaderboard for the current server";
}

@Override
protected void execute(CommandEvent event) {
event.getMessage().replyEmbeds(getEmbed(event.getGuild()))
.addActionRow(Button.link(Server.getUrl(event.getGuild().getIdLong()), "Leaderboard"))
.queue();
}

@Override
protected void execute(SlashCommandEvent event) {
event.replyEmbeds(getEmbed(event.getGuild()))
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/org/geysermc/discordbot/commands/LevelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.entities.Member;
Expand All @@ -44,17 +43,13 @@
import org.geysermc.discordbot.storage.LevelInfo;
import org.geysermc.discordbot.util.BotHelpers;
import org.geysermc.discordbot.util.InkscapeCssParser;
import org.geysermc.discordbot.util.MessageHelper;
import org.w3c.dom.Document;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class LevelCommand extends SlashCommand {

Expand All @@ -79,27 +74,6 @@ protected void execute(SlashCommandEvent event) {
interactionHook.editOriginalAttachments(FileUpload.fromData(levelFile)).queue(message -> levelFile.delete());
}

@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));

Member member;
if (args.size() == 0 || args.get(0).isEmpty()) {
member = event.getMember();
} else {
member = BotHelpers.getMember(event.getGuild(), args.remove(0));
}

// Check user is valid
if (member == null) {
MessageHelper.errorResponse(event, "Invalid user", "The user ID specified doesn't link with any valid user in this server.");
return;
}

File levelFile = handle(member);
event.getMessage().replyFiles(FileUpload.fromData(levelFile)).queue(message -> levelFile.delete());
}

protected File handle(Member member) {
// Get the user from the member
User user = member.getUser();
Expand All @@ -117,7 +91,6 @@ protected File handle(Member member) {
// Set the text for the svg fields
doc.getElementById("level").getFirstChild().setTextContent(String.valueOf(levelInfo.getLevel()));
doc.getElementById("name").getFirstChild().setTextContent(user.getName());
doc.getElementById("discriminator").getFirstChild().setTextContent("#" + user.getDiscriminator());
doc.getElementById("xp").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXp()));
doc.getElementById("xpnext").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXpForNextLevel()));
doc.getElementById("avatar").setAttributeNS("http://www.w3.org/1999/xlink", "href", user.getAvatarUrl().replace(".gif", ".png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
Expand All @@ -35,7 +34,6 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.geysermc.discordbot.util.BotColors;
import org.geysermc.discordbot.util.BotHelpers;

import java.time.Instant;
import java.util.Collections;
Expand All @@ -61,11 +59,6 @@ protected void execute(SlashCommandEvent event) {
event.replyEmbeds(handle(event.getGuild(), role)).queue();
}

@Override
protected void execute(CommandEvent event) {
event.getMessage().replyEmbeds(handle(event.getGuild(), BotHelpers.getRole(event.getGuild(), event.getArgs()))).queue();
}

protected MessageEmbed handle(Guild guild, Role role) {
return new EmbedBuilder()
.addField("Members" + (role != null ? " in " + role.getName() : ""), String.format("%,d", role != null ? guild.getMembersWithRoles(role).size() : guild.getMemberCount()), false)
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/geysermc/discordbot/commands/PingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import br.com.azalim.mcserverping.MCPingOptions;
import br.com.azalim.mcserverping.MCPingResponse;
import br.com.azalim.mcserverping.MCPingUtil;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import com.nukkitx.protocol.bedrock.BedrockClient;
Expand All @@ -46,10 +45,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -77,19 +73,6 @@ protected void execute(SlashCommandEvent event) {
interactionHook.editOriginalEmbeds(handle(ip)).queue();
}

@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));

// Check they specified an ip
if (args.get(0).isEmpty()) {
MessageHelper.errorResponse(event, "Missing IP", "Please specify an IP to ping.");
return;
}

event.getMessage().replyEmbeds(handle(args.get(0))).queue();
}

private MessageEmbed handle(String ip) {
// Check we were given a valid IP/domain
if (!ip.matches("[\\w.\\-:]+")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -55,11 +54,6 @@ protected void execute(SlashCommandEvent event) {
interactionHook.editOriginalEmbeds(handle()).queue();
}

@Override
protected void execute(CommandEvent event) {
event.getMessage().replyEmbeds(handle()).queue();
}

protected MessageEmbed handle() {
JSONObject stats = RestClient.simpleGetJsonObject("https://api.geysermc.org/v2/stats");
if (stats.has("error")) {
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/org/geysermc/discordbot/commands/RankCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.geysermc.discordbot.commands;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
Expand All @@ -35,15 +34,12 @@
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.internal.utils.Checks;
import org.geysermc.discordbot.storage.ServerSettings;
import org.geysermc.discordbot.util.BotColors;
import org.geysermc.discordbot.util.MessageHelper;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class RankCommand extends SlashCommand {
Expand All @@ -62,23 +58,10 @@ public RankCommand() {
@Override
protected void execute(SlashCommandEvent event) {
String role = event.optString("role", "");

Checks.notNull(event.getGuild(), "server");
event.replyEmbeds(handle(event.getGuild(), event.getMember(), role)).queue();
}

@Override
protected void execute(CommandEvent event) {
List<String> args = new ArrayList<>(Arrays.asList(event.getArgs().split(" ")));

// Check they specified an role
if (args.get(0).isEmpty()) {
MessageHelper.errorResponse(event, "Missing role", "Please specify an role to get.");
return;
}

event.getMessage().replyEmbeds(handle(event.getGuild(), event.getMember(), args.get(0))).queue();
}

protected MessageEmbed handle(Guild guild, Member member, String wantedRole) {
Map<String, String> roles = ServerSettings.getMap(guild.getIdLong(), "roles");
for (Map.Entry<String, String> roleData : roles.entrySet()) {
Expand Down
Loading