lmariscal / twitchirc

Twitch Bot Development made Easier | DEPRECATED
Other
40 stars 15 forks source link

Suggestion: Arguments for onCommand(). #16

Closed Squidkingdom closed 7 years ago

Squidkingdom commented 7 years ago

It would be nice to be able to have arguments for the onCommand() method. So like if you wanted to have chat vote ban someone You could do !voteban user instead of !setban and !voteban. It would just make life a bit easier. If their is a easy way to acheive this goal, let me know!

lmariscal commented 7 years ago

It has the same arguments that onMessasge has, it actually is the same only that the onCommand is called when a message starts with !

Squidkingdom commented 7 years ago

I don't think I explained it very well, it would be nice to be able to have arguments in the command itself, for example twitch has the command /timeout [user] <time> if we wanted to run the timeout command through the bot, if you wanted to keep track of people. So you could do !TO [User] <Time> and that would have the chat not execute the timeout method, as well as add there name to a list of offenders.

lmariscal commented 7 years ago

In the user the onCommand gives you you have the function .timeout .ban and some more

Squidkingdom commented 7 years ago

Sorry, that was a poorly used analogy. The actual reason I suggested this is I am trying to created the command, is to make a !quote command. I would like to be able to do !quote [add] [whatever quote] and then to call that quote as such !quote [int] I would then like to be able to use the [add] and the [whatever quote] in the code to add [whatever quote] to a file. I would like to be able to see the the text after the initial !something

lmariscal commented 7 years ago

Like in bukkit that instead of a message it gives you a string with arguments?

Squidkingdom commented 7 years ago

Yeah so that when you do a command like !quote you can have more information to be used in the code

lmariscal commented 7 years ago

Well on the message if the chat message is "!quote a Message" the message variable passed is "!quote a Message" you can manually split it in parts with split in the strihg object of java

Squidkingdom commented 7 years ago

Ok gotcha

Squidkingdom commented 7 years ago

For anyone looking at this for answers in the future us the extension .regionMatches() and .substring() Here is an example of my code `else if(message.regionMatches(true, 6, "add", 0, 3) == true){

                try {
                    Thread.sleep(1500);
                    String qte = message.substring(10);
                    writeFile(user, channel, path, qte);
                    sendMessage("Sucessfully added the quote \"" + qte + "\" (" + user + ")"  , channel);
                } catch (InterruptedException e) {
                    sendMessage("Error", channel);
                    e.printStackTrace();
                }`

Also note that you cannot use .equalsIgnoreCase when you check if the message is your command, instead use .regionMatches() again