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

/addcommand and /remove command #19

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open

Conversation

wiauxb
Copy link
Contributor

@wiauxb wiauxb commented Jun 18, 2023

implementing issue 16

@wiauxb
Copy link
Contributor Author

wiauxb commented Jun 18, 2023

It's a little mess of commits, normally it doesn't cause any problems, but if you want me to spend time cleaning it up, just say so ;)

@Hokkaydo
Copy link
Owner

Hokkaydo commented Jun 20, 2023

Adding & removing Discord side commands on the fly is not well supported by Discord.
There's a limit of 200 command updates per day. On each command adding or removing, the whole bunch of commands is updated so each time we add or remove a command, the n previous commands count too.
Technically this limit will be hard to hit so we should be safe but it's something to think about in the future if we encounter a potential bug.
If a bug arises, we might consider the old-school command system based on prefixes (like "!").

Reviewing tomorrow

It's a little mess of commits, normally it doesn't cause any problems, but if you want me to spend time cleaning it up, just say so ;)

Don't worry about that. Anyway, everything will get squashed into one single commit

Copy link
Owner

@Hokkaydo Hokkaydo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the few comments, it looks nice, many thanks
However, I have some worries about Discord API limitations.
A bot cannot add more than 200 commands a day.
Each time this system adds or removes a command, it adds the other N-1 commands.
Thus if someday we have ~50 commands (reachable IMO), we could encounter an error if we add or remove commands more than four times.
At first, I wanted to do that to remove commands of disabled modules. However, when I started testing the idea I quickly reached the limit.
The system is still really cool. We could merge it and keep in mind that if someday a bug about that occurs, it's maybe related here


public class CustomCommand implements Command {

private String NAME;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fields should be in lowerCase and final

public class CustomCommand implements Command {

private String NAME;
private String TEXT;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

} catch (IOException e) {
e.printStackTrace();
}
System.out.println(commands);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove sysout or Logger.log if absolutely necessary

public List<Command> getCommands() {
List<Command> new_commands = new ArrayList<>();
commands.forEach((name, item) -> new_commands.add(new CustomCommand(name, item.content)));
System.out.println(new_commands);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove sysout or Logger.log if absolutely necessary

StringBuilder commandContent = new StringBuilder();
StringBuilder authorId = new StringBuilder();
int index = 0;
while((c = stream.read()) != -1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the BufferedReader here which allows you to split on "\n" using BufferedReader#readLine then split the line on ";" and use each of the three parts. Sounds easier to me but at your convenience


CommandItem command = commands.get(commandName);

if(!command.authorId.equals(author.getId())) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check?
Admins will not be able to delete a command 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tough it would be more logical that only the author of the command would be able to delete it ... but we can drop this mechanic and let anyone delete any CustomCommand

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo command creation & deletion was a thing only available to mods


@Override
public List<OptionData> getOptions() {
return List.of(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.singletonList

Copy link
Owner

@Hokkaydo Hokkaydo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot this one


@Override
public Supplier<String> getDescription() {
return () -> TEXT;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it could be better to add a description field in commands (and so in /addcommand)

@Hokkaydo Hokkaydo linked an issue Jun 21, 2023 that may be closed by this pull request
@Hokkaydo Hokkaydo changed the base branch from master to dev August 10, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/addcommand <name> <text>
2 participants