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;
|
|
|
|
|
import com.coloryr.allmusic.server.core.music.play.MusicSearch;
|
|
|
|
|
import com.coloryr.allmusic.server.core.music.play.PlayMusic;
|
|
|
|
|
import com.coloryr.allmusic.server.core.objs.SearchMusicObj;
|
|
|
|
|
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
|
|
|
|
import com.coloryr.allmusic.server.core.objs.music.SearchPageObj;
|
|
|
|
|
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<>();
|
2024-05-08 16:25:33 +08:00
|
|
|
private static final List<String> normal = new ArrayList<String>() {{
|
|
|
|
|
this.add("stop");
|
|
|
|
|
this.add("cancel");
|
|
|
|
|
this.add("list");
|
|
|
|
|
this.add("vote");
|
|
|
|
|
this.add("mute");
|
|
|
|
|
this.add("search");
|
|
|
|
|
this.add("hud");
|
|
|
|
|
this.add("push");
|
|
|
|
|
}};
|
|
|
|
|
/**
|
|
|
|
|
* 管理员的指令
|
|
|
|
|
*/
|
|
|
|
|
private static final List<String> admin = new ArrayList<String>() {{
|
|
|
|
|
this.add("reload");
|
|
|
|
|
this.add("next");
|
|
|
|
|
this.add("ban");
|
|
|
|
|
this.add("delete");
|
|
|
|
|
this.add("addlist");
|
|
|
|
|
this.add("clearlist");
|
|
|
|
|
this.add("login");
|
|
|
|
|
this.add("code");
|
|
|
|
|
}};
|
|
|
|
|
/**
|
|
|
|
|
* 搜歌的指令
|
|
|
|
|
*/
|
|
|
|
|
private static final List<String> search = new ArrayList<String>() {{
|
|
|
|
|
this.add("select");
|
|
|
|
|
this.add("nextpage");
|
|
|
|
|
this.add("lastpage");
|
|
|
|
|
}};
|
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());
|
|
|
|
|
commandAdminList.put("banplayer", new CommandBanPlayer());
|
|
|
|
|
commandAdminList.put("url", new CommandUrl());
|
|
|
|
|
commandAdminList.put("delete", new CommandDelete());
|
|
|
|
|
commandAdminList.put("addlist", new CommandAddList());
|
|
|
|
|
commandAdminList.put("clearlist", new CommandClearList());
|
|
|
|
|
commandAdminList.put("code", new CommandCode());
|
|
|
|
|
commandAdminList.put("login", new CommandLogin());
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
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
|
2023-01-06 17:03:07 +08:00
|
|
|
.replace("%Cost%", "" + 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")) {
|
2020-02-29 22:09:52 +08:00
|
|
|
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);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else if (args[0].contains("song/")) {
|
|
|
|
|
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) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.listFull);
|
|
|
|
|
} else if (AllMusic.getConfig().banMusic.contains(musicID)) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.banMusic);
|
|
|
|
|
} else if (PlayMusic.haveMusic(musicID)) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.existMusic);
|
2023-10-22 10:14:55 +08:00
|
|
|
} else if (PlayMusic.havePlayer(name)) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.playerToMany);
|
|
|
|
|
} else if (AllMusic.getConfig().banPlayer.contains(name)) {
|
|
|
|
|
AllMusic.side.sendMessage(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
|
|
|
}
|
2021-06-21 22:25:17 +08:00
|
|
|
AllMusic.getConfig().RemoveNoMusicPlayer(name);
|
2022-12-27 10:31:41 +08:00
|
|
|
if (AllMusic.side.needPlay()) {
|
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)) {
|
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-02-07 20:41:12 +08:00
|
|
|
PlayMusic.addTask(obj);
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.success);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.noPlayer);
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|
|
|
|
|
} else
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.noID);
|
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 发送者
|
|
|
|
|
* @param search 搜歌结果
|
|
|
|
|
*/
|
2023-01-06 18:15:10 +08:00
|
|
|
public static void showSearch(Object sender, SearchPageObj search) {
|
2020-03-05 19:27:39 +08:00
|
|
|
int index = search.getIndex();
|
2023-01-09 15:56:26 +08:00
|
|
|
SearchMusicObj item;
|
2020-03-20 22:25:51 +08:00
|
|
|
String info;
|
2021-11-30 13:37:43 +08:00
|
|
|
AllMusic.side.sendMessage(sender, "");
|
2020-03-25 22:14:05 +08:00
|
|
|
if (search.haveLastPage()) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessageRun(sender, "§d[AllMusic3]§2输入/music lastpage上一页",
|
|
|
|
|
AllMusic.getMessage().page.last, "/music lastpage");
|
2020-03-25 22:14:05 +08:00
|
|
|
}
|
2020-03-07 15:56:57 +08:00
|
|
|
for (int a = 0; a < index; a++) {
|
2023-01-06 18:04:01 +08:00
|
|
|
item = search.getRes(a + search.getPage() * 10);
|
2024-04-17 22:15:12 +08:00
|
|
|
info = AllMusic.getMessage().page.choice;
|
2023-08-03 10:15:57 +08:00
|
|
|
info = info.replace("%Index%", "" + (a + 1))
|
2023-01-06 18:04:01 +08:00
|
|
|
.replace("%MusicName%", item.name)
|
|
|
|
|
.replace("%MusicAuthor%", item.author)
|
|
|
|
|
.replace("%MusicAl%", item.al);
|
2021-11-30 13:37:43 +08:00
|
|
|
AllMusic.side.sendMessageRun(sender, info,
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.getMessage().click.clickRun, "/music select " + (a + 1));
|
2020-03-05 19:27:39 +08:00
|
|
|
}
|
2020-03-07 15:56:57 +08:00
|
|
|
if (search.haveNextPage()) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessageRun(sender, "§d[AllMusic3]§2输入/music nextpage下一页",
|
|
|
|
|
AllMusic.getMessage().page.next, "/music nextpage");
|
2020-03-05 19:27:39 +08:00
|
|
|
}
|
2021-11-30 13:37:43 +08:00
|
|
|
AllMusic.side.sendMessage(sender, "");
|
2020-03-04 11:53:37 +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
|
|
|
*/
|
2021-06-21 22:25:17 +08:00
|
|
|
public static void ex(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) {
|
|
|
|
|
command.ex(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
|
|
|
|
2024-04-17 22:15:12 +08:00
|
|
|
if (AllMusic.getConfig().adminList.stream().anyMatch(name::equalsIgnoreCase)) {
|
|
|
|
|
command = commandAdminList.get(args[0]);
|
2023-10-22 10:14:55 +08:00
|
|
|
if (command != null) {
|
|
|
|
|
command.ex(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 &&
|
2023-01-03 18:31:35 +08:00
|
|
|
AllMusic.side.checkPermission(name, "allmusic.addmusic"))
|
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:
|
2021-06-21 22:25:17 +08:00
|
|
|
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 指令列表
|
|
|
|
|
*/
|
|
|
|
|
public static List<String> getTabList(String name, String[] arg) {
|
|
|
|
|
List<String> arguments = new ArrayList<>();
|
|
|
|
|
if (arg.length == 0) {
|
|
|
|
|
arguments.addAll(normal);
|
|
|
|
|
if (AllMusic.getConfig().adminList.contains(name)) {
|
|
|
|
|
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);
|
|
|
|
|
if (AllMusic.getConfig().adminList.contains(name)) {
|
|
|
|
|
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) {
|
2024-04-18 09:03:23 +08:00
|
|
|
arguments.addAll(command.tab(name, arg, 1));
|
2024-04-17 22:15:12 +08:00
|
|
|
}
|
|
|
|
|
command = CommandEX.commandAdminList.get(arg[0]);
|
|
|
|
|
if (command != null) {
|
2024-04-18 09:03:23 +08:00
|
|
|
arguments.addAll(command.tab(name, arg, 1));
|
2024-04-17 22:15:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|