Skip to content

Commit

Permalink
Merge pull request #3 from orewaee/dev
Browse files Browse the repository at this point in the history
New team and small fixes
  • Loading branch information
orewaee authored Dec 23, 2023
2 parents 6b8e645 + 6af6105 commit ef80339
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ discord_admin_id = ""

### Discord

- `/add <name> <discord id>` - adds a new account.
- `/remove <name> <discord id>` - deletes an existing account.
- `/add <name> <discord_id>` - adds a new account.
- `/remove <name> <discord_id>` - deletes an existing account.
- `/accounts` - displays a list of accounts.

### Minecraft

- `/discordauth reload config` - reloads the plugin config.
- `/discordauth reload messages` - reloads the plugin messages.
- `/discordauth reload all` - reloads the plugin config and messages.

- `/account add <discord id> <name>` - adds a new account.
- `/account Remove <discord id> <name>` - deletes an existing account.
- `/account add <discord_id> <name>` - adds a new account.
- `/account Remove <discord_id> <name>` - deletes an existing account.
- `/test` is a temporary command needed for debugging.


Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "dev.orewaee"
version = "0.3.1"
version = "0.3.2"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/orewaee/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public class Constants {
public static final String ID = "discordauth";
public static final String NAME = "DiscordAuth";
public static final String VERSION = "0.3.1";
public static final String VERSION = "0.3.2";
}
49 changes: 49 additions & 0 deletions src/main/java/dev/orewaee/bot/AccountsCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.orewaee.bot;

import dev.orewaee.account.Account;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.jetbrains.annotations.NotNull;

import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import dev.orewaee.account.AccountManager;
import dev.orewaee.account.JsonAccountManager;
import dev.orewaee.config.Config;
import dev.orewaee.config.TomlConfig;

import java.util.Set;
import java.util.StringJoiner;

public class AccountsCommand extends ListenerAdapter {
private final AccountManager accountManager = JsonAccountManager.getInstance();

private final Config config = TomlConfig.getInstance();

@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (!event.getUser().getId().equals(config.adminDiscordId())) return;

if (!event.getName().equals("accounts")) return;

Set<Account> accounts = accountManager.getAccounts();
int quantity = accounts.size();
StringJoiner result = new StringJoiner("\n");
for (Account account : accounts)
result.add(
String.format("- `%s` ||%s||", account.name(), account.discordId())
);

MessageEmbed embed = new EmbedBuilder()
.setColor(0x5865f2)
.setTitle(":page_with_curl: List of accounts")
.setDescription(
quantity == 0 ? "No accounts found at this time." :
String.format("At the moment, %d accounts have been found.\n\n%s", quantity, result)
)
.build();

event.replyEmbeds(embed).queue();
}
}
6 changes: 4 additions & 2 deletions src/main/java/dev/orewaee/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public Bot(String token) {
.enableIntents(GatewayIntent.DIRECT_MESSAGES)
.addEventListeners(new EventsListener())
.addEventListeners(new AddCommand())
.addEventListeners(new RemoveCommand());
.addEventListeners(new RemoveCommand())
.addEventListeners(new AccountsCommand());

JDA jda = jdaBuilder.build();

Expand Down Expand Up @@ -43,7 +44,8 @@ public Bot(String token) {
"discord_id",
"Account discord id",
true
)
),
Commands.slash("accounts", "Displays a list of all accounts")
).queue();
}
}
5 changes: 5 additions & 0 deletions src/main/java/dev/orewaee/commands/AccountCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public void execute(Invocation invocation) {
));
}
}

@Override
public boolean hasPermission(Invocation invocation) {
return invocation.source().hasPermission("discordauth.account");
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ lobby_server_name = "lobby"
bot_token = ""

# Discord admin
discord_admin_id = ""
admin_discord_id = ""

0 comments on commit ef80339

Please sign in to comment.