2023-03-02 08:42:34 +08:00
|
|
|
package coloryr.allmusic.core.command;
|
2020-02-29 22:09:52 +08:00
|
|
|
|
2023-03-02 08:42:34 +08:00
|
|
|
import coloryr.allmusic.core.AllMusic;
|
|
|
|
|
import coloryr.allmusic.core.music.play.MusicSearch;
|
|
|
|
|
import coloryr.allmusic.core.music.play.PlayMusic;
|
|
|
|
|
import coloryr.allmusic.core.objs.SearchMusicObj;
|
|
|
|
|
import coloryr.allmusic.core.objs.music.MusicObj;
|
|
|
|
|
import coloryr.allmusic.core.objs.music.SearchPageObj;
|
|
|
|
|
import coloryr.allmusic.core.utils.Function;
|
2020-02-29 22:09:52 +08:00
|
|
|
|
2023-10-22 10:14:55 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
private static final Map<String, ICommand> CommandList = new HashMap<>();
|
|
|
|
|
private static final Map<String, ICommand> CommandAdminList = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
CommandList.put("stop", new CommandStop());
|
|
|
|
|
CommandList.put("help", new CommandHelp());
|
|
|
|
|
CommandList.put("list", new CommandList());
|
|
|
|
|
CommandList.put("vote", new CommandVote());
|
|
|
|
|
CommandList.put("nomusic", new CommandNoMusic());
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
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-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)) {
|
2023-01-06 17:03:07 +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) {
|
2023-01-08 14:31:20 +08:00
|
|
|
if (!AllMusic.getConfig().UseCost || AllMusic.economy == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AllMusic.economy.check(name, cost)) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().Cost.NoMoney);
|
|
|
|
|
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) {
|
2023-01-08 20:55:21 +08:00
|
|
|
if (!AllMusic.getConfig().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 {
|
2023-01-06 17:03:07 +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)) {
|
2023-01-06 17:03:07 +08:00
|
|
|
if (PlayMusic.getSize() >= AllMusic.getConfig().MaxList) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().AddMusic.ListFull);
|
|
|
|
|
} else if (AllMusic.getConfig().BanMusic.contains(musicID)) {
|
|
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().AddMusic.BanMusic);
|
2021-06-21 22:25:17 +08:00
|
|
|
} else if (PlayMusic.isHave(musicID)) {
|
2023-01-06 17:03:07 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().AddMusic.ExistMusic);
|
2023-10-22 10:14:55 +08:00
|
|
|
} else if (PlayMusic.havePlayer(name)) {
|
|
|
|
|
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 {
|
2023-01-06 17:03:07 +08:00
|
|
|
if (checkMoney(sender, name, AllMusic.getConfig().AddMusicCost)) {
|
2023-01-03 18:31:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-01-06 17:03:07 +08:00
|
|
|
if (cost(sender, name, AllMusic.getConfig().AddMusicCost,
|
|
|
|
|
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)) {
|
2023-01-06 17:03:07 +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);
|
2023-01-06 17:03:07 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().AddMusic.Success);
|
2020-02-29 22:09:52 +08:00
|
|
|
} else
|
2023-01-06 17:03:07 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().AddMusic.NoPlayer);
|
2020-02-29 22:09:52 +08:00
|
|
|
}
|
|
|
|
|
} else
|
2023-01-06 17:03:07 +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()) {
|
2021-11-30 13:37:43 +08:00
|
|
|
AllMusic.side.sendMessageRun(sender, "§d[AllMusic]§2输入/music lastpage上一页",
|
2023-01-06 17:03:07 +08:00
|
|
|
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);
|
2023-01-06 17:03:07 +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,
|
2023-01-06 17:03:07 +08:00
|
|
|
AllMusic.getMessage().Click.This, "/music select " + (a + 1));
|
2020-03-05 19:27:39 +08:00
|
|
|
}
|
2020-03-07 15:56:57 +08:00
|
|
|
if (search.haveNextPage()) {
|
2021-11-30 13:37:43 +08:00
|
|
|
AllMusic.side.sendMessageRun(sender, "§d[AllMusic]§2输入/music nextpage下一页",
|
2023-01-06 17:03:07 +08:00
|
|
|
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) {
|
2023-01-06 17:03:07 +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
|
|
|
}
|
|
|
|
|
ICommand command = CommandList.get(args[0]);
|
|
|
|
|
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
|
|
|
|
2023-11-23 21:08:17 +08:00
|
|
|
if (AllMusic.getConfig().Admin.stream().anyMatch(name::equalsIgnoreCase)) {
|
2023-10-22 10:14:55 +08:00
|
|
|
command = CommandAdminList.get(args[0]);
|
|
|
|
|
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
|
|
|
}
|
2023-01-06 17:03:07 +08:00
|
|
|
if (AllMusic.getConfig().NeedPermission &&
|
2023-01-03 18:31:35 +08:00
|
|
|
AllMusic.side.checkPermission(name, "allmusic.addmusic"))
|
2023-01-06 17:03:07 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().Command.NoPer);
|
2020-08-19 19:18:38 +08:00
|
|
|
else {
|
2023-01-06 17:03:07 +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
|
|
|
}
|
|
|
|
|
}
|