Discord bot that plays music from every website ever via youtube-dl
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Chords/src/main/java/moe/nekojimi/chords/commands/SoundboardCommand.java

98 lines
3.1 KiB

/*
* Copyright (C) 2024 jimj316
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package moe.nekojimi.chords.commands;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import moe.nekojimi.chords.Chords;
import moe.nekojimi.chords.TrackRequest;
/**
*
* @author jimj316
*/
public class SoundboardCommand extends Command
{
public SoundboardCommand(Chords bot)
{
super(bot, "board");
}
@Override
public void call(Invocation invocation)
{
String action = invocation.getArgs().isEmpty() ? "" : invocation.getArgs().get(0);
String emoji = invocation.getArgs().size() < 2 ? "" : invocation.getArgs().get(1);
if (action.equals("add"))
{
String urlString = invocation.getArgs().get(2);
if (emoji.isBlank())
{
invocation.respond("You must specify a trigger!");
return;
}
try
{
URL url;
if (invocation.getArgs().size() < 3)
{
invocation.respond("No URL given!");
return;
}
url = new URL(urlString);
TrackRequest request = new TrackRequest();
request.setUrl(url);
request.setInvocation(invocation);
request.setKeepTracks(true);
bot.getDownloader().requestSpecific(List.of(request), (t) ->
{
bot.getSoundboard().add(emoji, t);
bot.saveSoundboard();
});
} catch (MalformedURLException ex)
{
invocation.respond("That's not a valid URL! " + ex.getMessage());
return;
}
} else if (action.equals("remove"))
{
if (emoji.isBlank())
{
invocation.respond("You must specify a trigger!");
return;
}
bot.getSoundboard().remove(emoji);
bot.saveSoundboard();
} else if (action.equals("list"))
{
List<String> list = bot.getSoundboard().getEmoji();
String response = "__Soundboard commands available:__\n";
for (String item : list)
{
response += item + " ";
}
invocation.respond(response);
} else
{
invocation.respond("Specify \"add\" or \"remove\" after the command!");
}
}
}