2024-04-19 09:46:54 +08:00
|
|
|
package com.coloryr.allmusic.server.core.command;
|
2020-02-29 22:09:52 +08:00
|
|
|
|
2024-04-19 09:46:54 +08:00
|
|
|
import com.coloryr.allmusic.server.core.AllMusic;
|
2025-08-28 13:49:55 +08:00
|
|
|
import com.coloryr.allmusic.server.core.command.sub.*;
|
2024-04-19 09:46:54 +08:00
|
|
|
import com.coloryr.allmusic.server.core.music.play.MusicSearch;
|
|
|
|
|
import com.coloryr.allmusic.server.core.music.play.PlayMusic;
|
2024-06-21 11:06:14 +08:00
|
|
|
import com.coloryr.allmusic.server.core.objs.message.PAL;
|
2024-04-19 09:46:54 +08:00
|
|
|
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
2025-03-24 18:20:45 +08:00
|
|
|
import com.coloryr.allmusic.server.core.sql.DataSql;
|
2024-04-19 09:46:54 +08:00
|
|
|
import com.coloryr.allmusic.server.core.utils.Function;
|
2020-02-29 22:09:52 +08:00
|
|
|
|
2024-04-17 22:15:12 +08:00
|
|
|
import java.util.ArrayList;
|
2023-10-22 10:14:55 +08:00
|
|
|
import java.util.HashMap;
|
2024-04-17 22:15:12 +08:00
|
|
|
import java.util.List;
|
2023-10-22 10:14:55 +08:00
|
|
|
import java.util.Map;
|
2021-06-12 15:57:35 +08:00
|
|
|
|
2020-02-29 22:09:52 +08:00
|
|
|
public class CommandEX {
|
2023-10-22 10:14:55 +08:00
|
|
|
|
2024-04-17 22:15:12 +08:00
|
|
|
public static final Map<String, ICommand> commandList = new HashMap<>();
|
|
|
|
|
public static final Map<String, ICommand> commandAdminList = new HashMap<>();
|
2023-10-22 10:14:55 +08:00
|
|
|
|
|
|
|
|
static {
|
2024-04-17 22:15:12 +08:00
|
|
|
commandList.put("stop", new CommandStop());
|
|
|
|
|
commandList.put("help", new CommandHelp());
|
|
|
|
|
commandList.put("list", new CommandList());
|
|
|
|
|
commandList.put("vote", new CommandVote());
|
|
|
|
|
commandList.put("mute", new CommandMute());
|
|
|
|
|
commandList.put("search", new CommandSearch());
|
|
|
|
|
commandList.put("select", new CommandSelect());
|
|
|
|
|
commandList.put("nextpage", new CommandNextPage());
|
|
|
|
|
commandList.put("lastpage", new CommandLastPage());
|
|
|
|
|
commandList.put("hud", new CommandHud());
|
|
|
|
|
commandList.put("reload", new CommandReload());
|
|
|
|
|
commandList.put("push", new CommandPush());
|
|
|
|
|
commandList.put("cancel", new CommandCancel());
|
|
|
|
|
|
|
|
|
|
commandAdminList.put("next", new CommandNext());
|
|
|
|
|
commandAdminList.put("ban", new CommandBan());
|
2025-03-24 18:20:45 +08:00
|
|
|
commandAdminList.put("unban", new CommandUnban());
|
2024-04-17 22:15:12 +08:00
|
|
|
commandAdminList.put("banplayer", new CommandBanPlayer());
|
2025-03-24 18:20:45 +08:00
|
|
|
commandAdminList.put("unbanplayer", new CommandUnbanPlayer());
|
2024-04-17 22:15:12 +08:00
|
|
|
commandAdminList.put("url", new CommandUrl());
|
|
|
|
|
commandAdminList.put("delete", new CommandDelete());
|
|
|
|
|
commandAdminList.put("addlist", new CommandAddList());
|
|
|
|
|
commandAdminList.put("clearlist", new CommandClearList());
|
2025-03-24 18:20:45 +08:00
|
|
|
commandAdminList.put("clearban", new CommandClearBanList());
|
|
|
|
|
commandAdminList.put("clearbanplayer", new CommandClearBanPlayerList());
|
2024-11-16 21:54:34 +08:00
|
|
|
commandAdminList.put("cookie", new CommandCookie());
|
2024-07-09 11:06:38 +08:00
|
|
|
commandAdminList.put("test", new CommandTest());
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:01:34 +08:00
|
|
|
private static final List<String> normal = new ArrayList<String>() {{
|
|
|
|
|
this.addAll(commandList.keySet());
|
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员的指令
|
|
|
|
|
*/
|
|
|
|
|
private static final List<String> admin = new ArrayList<String>() {{
|
|
|
|
|
this.addAll(commandAdminList.keySet());
|
|
|
|
|
}};
|
|
|
|
|
/**
|
|
|
|
|
* 搜歌的指令
|
|
|
|
|
*/
|
|
|
|
|
private static final List<String> search = new ArrayList<String>() {{
|
|
|
|
|
this.add("select");
|
|
|
|
|
this.add("nextpage");
|
|
|
|
|
this.add("lastpage");
|
|
|
|
|
}};
|
|
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
/**
|
|
|
|
|
* 搜索音乐
|
2023-01-08 20:55:21 +08:00
|
|
|
*
|
|
|
|
|
* @param sender 发送者
|
|
|
|
|
* @param name 用户名
|
|
|
|
|
* @param args 参数
|
2023-01-06 17:03:07 +08:00
|
|
|
* @param isDefault 是否是默认点歌方式
|
|
|
|
|
*/
|
2023-10-22 10:14:55 +08:00
|
|
|
public static void searchMusic(Object sender, String name, String[] args, boolean isDefault) {
|
2021-03-19 15:32:47 +08:00
|
|
|
MusicObj obj = new MusicObj();
|
2021-02-07 20:26:36 +08:00
|
|
|
obj.sender = sender;
|
2021-11-30 13:37:43 +08:00
|
|
|
obj.name = name;
|
2021-02-07 20:26:36 +08:00
|
|
|
obj.args = args;
|
|
|
|
|
obj.isDefault = isDefault;
|
2022-12-27 11:33:26 +08:00
|
|
|
|
|
|
|
|
if (AllMusic.side.onMusicAdd(sender, obj)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.cancel);
|
2022-12-27 11:33:26 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 15:32:47 +08:00
|
|
|
MusicSearch.addSearch(obj);
|
2020-08-19 19:18:38 +08:00
|
|
|
}
|
2020-02-29 22:09:52 +08:00
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
/**
|
|
|
|
|
* 检查金额是否够
|
2023-01-08 20:55:21 +08:00
|
|
|
*
|
2023-01-06 17:03:07 +08:00
|
|
|
* @param sender 发送者
|
2023-01-08 20:55:21 +08:00
|
|
|
* @param name 用户名
|
|
|
|
|
* @param cost 金额
|
2023-01-06 17:03:07 +08:00
|
|
|
* @return 结果
|
|
|
|
|
*/
|
2023-10-22 10:14:55 +08:00
|
|
|
public static boolean checkMoney(Object sender, String name, int cost) {
|
2024-05-13 09:33:41 +08:00
|
|
|
if (!AllMusic.getConfig().cost.useCost || AllMusic.economy == null) {
|
2023-01-08 14:31:20 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AllMusic.economy.check(name, cost)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().cost.noMoney);
|
2023-01-08 14:31:20 +08:00
|
|
|
return true;
|
2023-01-03 18:31:35 +08:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
/**
|
|
|
|
|
* 扣钱
|
2023-01-08 20:55:21 +08:00
|
|
|
*
|
|
|
|
|
* @param sender 发送者
|
|
|
|
|
* @param name 用户名
|
|
|
|
|
* @param cost 金额
|
2023-01-06 17:03:07 +08:00
|
|
|
* @param message 结果消息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
2023-10-22 10:14:55 +08:00
|
|
|
public static boolean cost(Object sender, String name, int cost, String message) {
|
2024-05-13 09:33:41 +08:00
|
|
|
if (!AllMusic.getConfig().cost.useCost || AllMusic.economy == null) {
|
2023-01-08 14:31:20 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
if (AllMusic.economy.cost(name, cost)) {
|
2023-01-03 18:31:35 +08:00
|
|
|
AllMusic.side.sendMessage(sender, message
|
2024-06-21 11:06:14 +08:00
|
|
|
.replace(PAL.cost, String.valueOf(cost)));
|
2023-01-03 18:31:35 +08:00
|
|
|
return false;
|
|
|
|
|
} else {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().cost.costFail);
|
2023-01-03 18:31:35 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
/**
|
|
|
|
|
* 添加音乐
|
2023-01-08 20:55:21 +08:00
|
|
|
*
|
2023-01-06 17:03:07 +08:00
|
|
|
* @param sender 发送者
|
2023-01-08 20:55:21 +08:00
|
|
|
* @param name 用户名
|
|
|
|
|
* @param args 参数
|
2023-01-06 17:03:07 +08:00
|
|
|
*/
|
2023-10-22 10:14:55 +08:00
|
|
|
public static void addMusic(Object sender, String name, String[] args) {
|
2021-06-21 22:25:17 +08:00
|
|
|
String musicID;
|
2020-04-13 13:04:04 +08:00
|
|
|
if (args[0].contains("id=") && !args[0].contains("/?userid")) {
|
2024-09-16 12:54:35 +08:00
|
|
|
if (args[0].contains("&uct2")) {
|
|
|
|
|
musicID = Function.getString(args[0], "id=", "&uct2");
|
2025-03-09 21:24:18 +08:00
|
|
|
} else if (args[0].contains("&user"))
|
2021-06-21 22:25:17 +08:00
|
|
|
musicID = Function.getString(args[0], "id=", "&user");
|
2020-02-29 22:09:52 +08:00
|
|
|
else
|
2021-06-21 22:25:17 +08:00
|
|
|
musicID = Function.getString(args[0], "id=", null);
|
2025-03-09 21:24:18 +08:00
|
|
|
} else if (args[0].contains("song/")) {
|
2020-02-29 22:09:52 +08:00
|
|
|
if (args[0].contains("/?userid"))
|
2021-06-21 22:25:17 +08:00
|
|
|
musicID = Function.getString(args[0], "song/", "/?userid");
|
2020-02-29 22:09:52 +08:00
|
|
|
else
|
2021-06-21 22:25:17 +08:00
|
|
|
musicID = Function.getString(args[0], "song/", null);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else
|
2021-06-21 22:25:17 +08:00
|
|
|
musicID = args[0];
|
|
|
|
|
if (Function.isInteger(musicID)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
if (PlayMusic.getListSize() >= AllMusic.getConfig().maxPlayList) {
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.listFull);
|
|
|
|
|
} else if (DataSql.checkBanMusic(musicID)) {
|
|
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.banMusic);
|
2024-04-17 22:15:12 +08:00
|
|
|
} else if (PlayMusic.haveMusic(musicID)) {
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.existMusic);
|
2024-06-09 20:41:33 +08:00
|
|
|
} else if (PlayMusic.isPlayerMax(name)) {
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.playerToMany);
|
|
|
|
|
} else if (DataSql.checkBanPlayer(name)) {
|
|
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.playerBan);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else {
|
2024-05-13 09:33:41 +08:00
|
|
|
if (checkMoney(sender, name, AllMusic.getConfig().cost.addMusicCost)) {
|
2023-01-03 18:31:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2024-05-13 09:33:41 +08:00
|
|
|
if (cost(sender, name, AllMusic.getConfig().cost.addMusicCost,
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.getMessage().cost.addMusic)) {
|
2023-01-03 18:31:35 +08:00
|
|
|
return;
|
2020-08-19 19:18:38 +08:00
|
|
|
}
|
2025-03-24 18:20:45 +08:00
|
|
|
DataSql.removeMutePlayer(name);
|
2025-03-24 20:13:54 +08:00
|
|
|
if (AllMusic.side.needPlay(false)) {
|
2021-03-19 15:32:47 +08:00
|
|
|
MusicObj obj = new MusicObj();
|
2022-12-26 15:36:01 +08:00
|
|
|
obj.sender = sender;
|
|
|
|
|
obj.id = musicID;
|
2021-11-30 13:37:43 +08:00
|
|
|
obj.name = name;
|
2021-02-07 20:41:12 +08:00
|
|
|
obj.isDefault = false;
|
2022-12-27 11:33:26 +08:00
|
|
|
|
|
|
|
|
if (AllMusic.side.onMusicAdd(sender, obj)) {
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.cancel);
|
2022-12-27 11:33:26 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 20:41:12 +08:00
|
|
|
PlayMusic.addTask(obj);
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.success);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.noPlayer);
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|
|
|
|
|
} else
|
2025-03-24 18:20:45 +08:00
|
|
|
AllMusic.side.sendMessageTask(sender, AllMusic.getMessage().addMusic.noID);
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-09 21:24:18 +08:00
|
|
|
private static boolean isAdmin(String name) {
|
2024-11-19 10:53:23 +08:00
|
|
|
for (String item : AllMusic.getConfig().adminList) {
|
|
|
|
|
if (item.equalsIgnoreCase(name)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-09 21:24:18 +08:00
|
|
|
return false;
|
2024-11-19 10:53:23 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-06 17:03:07 +08:00
|
|
|
/**
|
|
|
|
|
* 执行命令
|
2023-01-08 20:55:21 +08:00
|
|
|
*
|
2023-01-06 17:03:07 +08:00
|
|
|
* @param sender 发送者
|
2023-01-08 20:55:21 +08:00
|
|
|
* @param name 用户名
|
|
|
|
|
* @param args 参数
|
2023-01-06 17:03:07 +08:00
|
|
|
*/
|
2025-01-19 22:51:01 +08:00
|
|
|
public static void execute(Object sender, String name, String[] args) {
|
2020-02-29 22:09:52 +08:00
|
|
|
if (args.length == 0) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.error);
|
2021-09-04 20:29:47 +08:00
|
|
|
return;
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
2024-04-17 22:15:12 +08:00
|
|
|
ICommand command = commandList.get(args[0]);
|
2023-10-22 10:14:55 +08:00
|
|
|
if (command != null) {
|
2025-01-19 22:51:01 +08:00
|
|
|
command.execute(sender, name, args);
|
2021-09-04 20:29:47 +08:00
|
|
|
return;
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
2023-01-03 18:31:35 +08:00
|
|
|
|
2025-08-28 13:49:55 +08:00
|
|
|
if (checkAdmin(sender, name)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
command = commandAdminList.get(args[0]);
|
2023-10-22 10:14:55 +08:00
|
|
|
if (command != null) {
|
2025-01-19 22:51:01 +08:00
|
|
|
command.execute(sender, name, args);
|
2021-09-04 20:29:47 +08:00
|
|
|
return;
|
2021-09-04 17:22:48 +08:00
|
|
|
}
|
2021-09-04 20:00:41 +08:00
|
|
|
}
|
2024-04-17 22:15:12 +08:00
|
|
|
if (AllMusic.getConfig().needPermission &&
|
2025-08-28 13:49:55 +08:00
|
|
|
!AllMusic.side.checkPermission(sender, PermissionList.PERMISSION_ADD_MUSIC))
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.noPer);
|
2020-08-19 19:18:38 +08:00
|
|
|
else {
|
2024-04-17 22:15:12 +08:00
|
|
|
switch (AllMusic.getConfig().defaultAddMusic) {
|
2020-08-19 19:18:38 +08:00
|
|
|
case 1:
|
2021-06-21 22:25:17 +08:00
|
|
|
searchMusic(sender, name, args, true);
|
2020-08-19 19:18:38 +08:00
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
default:
|
2025-03-24 20:13:54 +08:00
|
|
|
DataSql.task(() -> addMusic(sender, name, args));
|
2020-08-19 19:18:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|
2024-04-17 22:15:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取Tab指令列表
|
|
|
|
|
*
|
|
|
|
|
* @param name 用户名
|
|
|
|
|
* @param arg 参数
|
|
|
|
|
* @return 指令列表
|
|
|
|
|
*/
|
2025-03-09 21:24:18 +08:00
|
|
|
public static List<String> getTabList(Object sender, String name, String[] arg) {
|
2024-04-17 22:15:12 +08:00
|
|
|
List<String> arguments = new ArrayList<>();
|
|
|
|
|
if (arg.length == 0) {
|
|
|
|
|
arguments.addAll(normal);
|
2025-08-28 13:49:55 +08:00
|
|
|
if (checkAdmin(sender, name)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
arguments.addAll(admin);
|
|
|
|
|
}
|
|
|
|
|
if (AllMusic.getSearch(name) != null) {
|
|
|
|
|
return search;
|
|
|
|
|
}
|
2024-04-17 23:43:11 +08:00
|
|
|
} else {
|
2024-04-30 14:11:07 +08:00
|
|
|
if (arg[0] == null || arg[0].isEmpty() || arg.length == 1) {
|
2024-04-17 22:15:12 +08:00
|
|
|
arguments.addAll(normal);
|
2025-08-28 13:49:55 +08:00
|
|
|
if (checkAdmin(sender, name)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
arguments.addAll(admin);
|
|
|
|
|
}
|
2024-04-30 14:11:07 +08:00
|
|
|
if (arg[0] == null || arg[0].isEmpty()) {
|
2024-04-17 22:15:12 +08:00
|
|
|
if (AllMusic.getSearch(name) != null) {
|
|
|
|
|
return search;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-18 09:03:23 +08:00
|
|
|
} else {
|
2024-04-17 22:15:12 +08:00
|
|
|
ICommand command = CommandEX.commandList.get(arg[0]);
|
|
|
|
|
if (command != null) {
|
2025-03-09 21:24:18 +08:00
|
|
|
arguments.addAll(command.tab(sender, name, arg, 1));
|
2024-04-17 22:15:12 +08:00
|
|
|
}
|
2025-08-28 13:49:55 +08:00
|
|
|
if (checkAdmin(sender, name)) {
|
2024-07-03 17:42:27 +08:00
|
|
|
command = CommandEX.commandAdminList.get(arg[0]);
|
|
|
|
|
if (command != null) {
|
2025-03-09 21:24:18 +08:00
|
|
|
arguments.addAll(command.tab(sender, name, arg, 1));
|
2024-07-03 17:42:27 +08:00
|
|
|
}
|
2024-04-17 22:15:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
2025-08-28 13:49:55 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为管理员
|
|
|
|
|
* @param sender 用户
|
|
|
|
|
* @param name 用户名
|
|
|
|
|
* @return 是否为管理员
|
|
|
|
|
*/
|
|
|
|
|
public static boolean checkAdmin(Object sender, String name) {
|
|
|
|
|
return isAdmin(name) || AllMusic.side.checkPermission(sender);
|
|
|
|
|
}
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|