coding-buddies-discord / cb-bots

4 stars 3 forks source link

Earn/create suffix #9

Closed waream2 closed 2 years ago

waream2 commented 2 years ago

@consecutes specifically asking you to look at this PR. I went into the file that you created last week and added the ability for it to also know what to do with a suffix. So that as we build out the point system, we'll be able to use the messageCreate event to handle it.

Few things to note:

I realize this is a significant refactor of the work you did. Let me know if you don't like the way something is done. My thought here was just to give it the ability to understand prefix and suffix.

chrisestabaocupado commented 2 years ago

I also think that the suffix system could be implemented with the original code more easily, what do you think about something like

const { prefix, suffix } = config;
const { content } = interaction;

const args = (content.indexOf(prefix) === 0 ||  content.indexOf(suffix) === content.length - 2) &&
        content.slice(prefix.length).split(" ");
if(!args) return;

let hadPrefix, cmd;
if(args[args.lenght] != suffix) hadPrefix = true;
if(hadPrefix) cmd = args[0]

if(hadPrefix) {
    switch (cmd) {
        /* bla bla bla */
    }
}

Last edit: applying recommendations by @Claudi0-V

cubiquitous commented 2 years ago

i know that my opinion was not asked, but I will suggest going with earn way. is more easy to understand and if in the future we want to make more commands it will be easier to change.

The only suggestion that I have is instead of using an else, use another if.

if (hasPrefix {
}
if (hasSufix)) {
}

this is because else could get any other thing beyond the hasSufix.

waream2 commented 2 years ago

@doulovera @consecutes @Claudi0-V @emilydta I think this solves our problem. Feel like I kind of went out of my way to not use regex (sorry Cub) but I think it does what we want. You can run several commands in one message with this method and I think it's pretty easy to read.

Open to all feedback, like always.

Thanks!