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

Concatenating Preset Commands #154

Open
dannegm opened this issue Oct 7, 2020 · 2 comments
Open

Concatenating Preset Commands #154

dannegm opened this issue Oct 7, 2020 · 2 comments

Comments

@dannegm
Copy link

dannegm commented Oct 7, 2020

Hello everyone!

I just discover this awesome bot. I think it's the best option in the market but, could be nice have an extra feature when you are creating presets.

In my case, I look for some preset that execute two o more commands in one single preset. for example, I trying to create a custom command that can jump to a specific sogn of my play list without lost the queue of my playlist. Here is the preset:

$botify preset play %s && $as add \$spotify \$list <playlist_url> $as jump

And you can execute as

$botify jump <song_name>

So, as you notice, I'm trying to concat two commands using && but this is not still posible, so, the request for this issue it's bsically add support to contact commands when you are creating a preset.

Thank you!

@SalvaFiorenza8
Copy link

This would be awesome!

@robinfriedli
Copy link
Owner

robinfriedli commented Oct 8, 2020

This cannot be done using presets because a preset always resolves to one command. It's just that - a preset for a command. Executing several commands is something that is possible using scripts in botify 2. For example the following script could be used to skip to a track with a certain name in the queue as you described:

def queue = playback.audioQueue
if (queue.isEmpty()) {
  return null
}
def target = input.toLowerCase()
while (queue.getCurrent().getTitle().toLowerCase() != target) {
  if (!queue.hasNext(true)) {
    messages.sendError(String.format('Could not find %s in upcoming tracks', input), channel)
    break
  }
  queue.iterate()
}
command.run('play')

(create the script via script $identifier="skipTo" "groovy script" then invoke it with skipTo track or to be verbose script $invoke="skipTo" track)

This is just an example as the queue management system and scripts are subject to change in botify 2, also this does not actually involve invoking several commands as the queue is iterated directly before using the play command. Invoking multiple commands is possible too, but limited to 5 invocations. For example the following script could be used to invoke the queue command for each item in a comma separated list of up to 5 items:

def argsRaw = input.split(',')
def args = Arrays.stream(argsRaw).map({s -> s.trim()}).filter({s -> !s.isEmpty()}).collect(Collectors.toList())
if (args.size() > 5) {
    messages.sendError('Cannot select more than 5 items', channel)
    return null
}
for (def arg : args) {
    command.run('queue ' + arg)
}
return null

that even allows mixing arguments to, for example, queue a spotify track, a youtube playlist, another spotify track and a botify playlist in one command: queueAll numb, $list $youtube rock, crawling, $list lp (assuming the script is saved as "queueAll")

The scripting sandbox even allows adding "interceptor" and "finalizer" scripts that run before / after each command. For example the following interceptor script could be created (using the interceptor command) that has a slight chance to "rick roll" people when they try using the play command, playing never gonna give you up by rick astley and optionally queueing the actual input instead:

if (command.getIdentifier() == 'play'
  && !command.getCommandInput().isBlank()) {
def rand = new Random()
// generate random number up to 10000
def i = rand.nextInt(10000)
// check if divisible by 33
if (i % 33 == 0) {
  // send rickroll message
  messages.sendTemporary('Get rickrolled 🤡', channel)
  // play Rick Astley - Never Gonna Give You Up on youtube
  command.run('play https://www.youtube.com/watch?v=dQw4w9WgXcQ ')
  // uncomment the following line to queue the actual input instead
  // command.run('queue ' + command.getCommandBody())
  // abort the actual command
  command.abort()
}
}

The possibilities are endless. I'd say this already offers more than you're asking for ;). Only "small" problem is that it's way too much to ask for the average user to create such scripts which is way I'm planning on adding a script sharing platform to the botify 2 webapp. Not sure if it'll make it into 2.0 though.

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

No branches or pull requests

3 participants