mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-08 18:54:44 +00:00
新特性
This commit is contained in:
1 parent
27859d41b8
commit
49120eef6a
9 files changed
+119
-20
No files matched your search
@@ -117,6 +117,7 @@ AllMusic不会内置音乐api,你想要正常使用需要自己安装
|
||||
| `/music search <歌名>` | 用默认API搜索歌曲 |
|
||||
| `/music searchapi <音乐API> <歌名>` | 指定API搜索歌曲 |
|
||||
| `/music select <序号>` | 选择搜索结果 |
|
||||
| `/music <序号>` | 搜索后直接按序号选择搜索结果,等同 `/music select <序号>` |
|
||||
| `/music nextpage` | 搜索结果下一页 |
|
||||
| `/music lastpage` | 搜索结果上一页 |
|
||||
| `/music join` | 重新接收当前正在播放的歌曲(重连/切服后使用) |
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ allprojects {
|
||||
apply(plugin = "com.gradleup.shadow")
|
||||
|
||||
group = "com.coloryr"
|
||||
version = "4.3.1"
|
||||
version = "4.3.2"
|
||||
|
||||
// 设置项目JDK版本
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
@@ -61,7 +61,7 @@ public class AllMusic {
|
||||
/**
|
||||
* 语言文件配置版本号
|
||||
*/
|
||||
public static final String messageVersion = "402";
|
||||
public static final String messageVersion = "403";
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
@@ -128,10 +128,15 @@ public class AllMusic {
|
||||
* 检查语言文件完整性
|
||||
*/
|
||||
private static void messageCheck() {
|
||||
if (message == null || message.check()) {
|
||||
if (message == null) {
|
||||
message = MessageObj.make();
|
||||
log.data("<light_purple>[AllMusic]<red>配置文件message.json错误,已覆盖");
|
||||
saveMessage();
|
||||
} else if (message.check()) {
|
||||
// 保留已有内容,只补全缺失的字段
|
||||
message.version = messageVersion;
|
||||
log.data("<light_purple>[AllMusic]<yellow>配置文件message.json缺少内容,已补全");
|
||||
saveMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.coloryr.allmusic.server.core.music.MusicSearch;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.message.ARG;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SearchPageObj;
|
||||
import com.coloryr.allmusic.server.core.saves.BanSave;
|
||||
import com.coloryr.allmusic.server.core.saves.SaveTask;
|
||||
|
||||
@@ -275,6 +276,10 @@ public class CommandEX {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 搜歌后可以直接用 /music 序号 选择搜索结果
|
||||
if (args.length == 1 && CommandSelect.selectSearch(sender, name, args[0])) {
|
||||
return;
|
||||
}
|
||||
if (AllMusic.getConfig().needPermission &&
|
||||
!AllMusic.side.checkPermission(sender, PermissionList.PERMISSION_ADD_MUSIC))
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.noPer);
|
||||
@@ -297,6 +302,25 @@ public class CommandEX {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取搜歌结果的补全列表
|
||||
* <p>
|
||||
* 包含搜歌相关的指令和当前页可以选择的序号
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 补全列表
|
||||
*/
|
||||
private static List<String> getSearchTabList(String name) {
|
||||
List<String> list = new ArrayList<>(search);
|
||||
SearchPageObj obj = MusicSearch.getSearch(name);
|
||||
if (obj != null) {
|
||||
for (int a = 1; a <= obj.getIndex(); a++) {
|
||||
list.add(String.valueOf(a));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Tab指令列表
|
||||
*
|
||||
@@ -312,7 +336,7 @@ public class CommandEX {
|
||||
arguments.addAll(admin);
|
||||
}
|
||||
if (MusicSearch.getSearch(name) != null) {
|
||||
return search;
|
||||
return getSearchTabList(name);
|
||||
}
|
||||
} else {
|
||||
if (arg[0] == null || arg[0].isEmpty() || arg.length == 1) {
|
||||
@@ -322,7 +346,7 @@ public class CommandEX {
|
||||
}
|
||||
if (arg[0] == null || arg[0].isEmpty()) {
|
||||
if (MusicSearch.getSearch(name) != null) {
|
||||
return search;
|
||||
return getSearchTabList(name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
+56
-13
@@ -25,20 +25,63 @@ public class CommandSelect extends ACommand {
|
||||
SearchPageObj obj = MusicSearch.getSearch(name);
|
||||
if (obj == null) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.emptySearch);
|
||||
} else if (!args[1].isEmpty() && Function.isInteger(args[1])) {
|
||||
int a = Integer.parseInt(args[1]);
|
||||
if (a == 0) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
||||
return;
|
||||
}
|
||||
String id = obj.getSong((obj.getPage() * 10) + (a - 1));
|
||||
AllMusic.side.sendMessage(sender,
|
||||
AllMusic.getMessage().search.choice.replace(ARG.index, "" + a));
|
||||
SaveTask.task(() -> CommandEX.addMusic(sender, name, obj.getApi(), id));
|
||||
MusicSearch.removeSearch(name);
|
||||
} else {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = args.length > 1 ? Function.getInt(args[1], -1) : -1;
|
||||
if (index < 1 || index > obj.getIndex()) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
||||
return;
|
||||
}
|
||||
|
||||
select(sender, name, obj, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试把参数当作搜歌结果的序号来选择
|
||||
* <p>
|
||||
* 没有搜歌结果或序号无效时返回false,由调用方继续处理
|
||||
*
|
||||
* @param sender 发送者
|
||||
* @param name 用户名
|
||||
* @param arg 序号
|
||||
* @return 是否已处理
|
||||
*/
|
||||
public static boolean selectSearch(Object sender, String name, String arg) {
|
||||
SearchPageObj obj = MusicSearch.getSearch(name);
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = Function.getInt(arg, -1);
|
||||
if (index < 1 || index > obj.getIndex()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AllMusic.getConfig().needPermission &&
|
||||
!AllMusic.side.checkPermission(sender, PermissionList.PERMISSION_SEARCH)) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.noPer);
|
||||
return true;
|
||||
}
|
||||
|
||||
select(sender, name, obj, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择搜歌结果
|
||||
*
|
||||
* @param sender 发送者
|
||||
* @param name 用户名
|
||||
* @param obj 搜歌结果
|
||||
* @param index 序号(从1开始)
|
||||
*/
|
||||
private static void select(Object sender, String name, SearchPageObj obj, int index) {
|
||||
String id = obj.getSong((obj.getPage() * 10) + (index - 1));
|
||||
AllMusic.side.sendMessage(sender,
|
||||
AllMusic.getMessage().search.choice.replace(ARG.index, "" + index));
|
||||
SaveTask.task(() -> CommandEX.addMusic(sender, name, obj.getApi(), id));
|
||||
MusicSearch.removeSearch(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,7 +86,11 @@ public class MusicSearch {
|
||||
.replace(ARG.musicAuthor, TextUtils.escapeVar(item.author))
|
||||
.replace(ARG.musicAl, TextUtils.escapeVar(item.al));
|
||||
AllMusic.side.sendMessage(sender, AllMusic.side.miniMessage(info)
|
||||
.append(AllMusic.side.clickRun(AllMusic.getMessage().click.clickRun, "/music select " + (a + 1))));
|
||||
.append(AllMusic.side.clickRun(AllMusic.getMessage().click.clickRun, "/music " + (a + 1))));
|
||||
}
|
||||
if (index > 0) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.side.miniMessage(AllMusic.getMessage().search.select)
|
||||
.append(AllMusic.side.clickSuggest(AllMusic.getMessage().click.clickCheck, "/music select ")));
|
||||
}
|
||||
if (search.haveNextPage()) {
|
||||
AllMusic.side.sendMessage(sender, AllMusic.side.miniMessage(AllMusic.getMessage().search.nextPage)
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ public class HelpNormalObj {
|
||||
if (search == null)
|
||||
search = "<light_purple>[AllMusic]<yellow>/music search [歌名] 搜索歌曲";
|
||||
if (select == null)
|
||||
select = "<light_purple>[AllMusic]<yellow>/music select [序列] 选择歌曲";
|
||||
select = "<light_purple>[AllMusic]<yellow>/music [序号] 或 /music select [序号] 选择搜索结果";
|
||||
if (nextpage == null)
|
||||
nextpage = "<light_purple>[AllMusic]<yellow>/music nextpage 切换下一页歌曲搜索结果";
|
||||
if (lastpage == null)
|
||||
|
||||
@@ -7,6 +7,7 @@ public class SearchObj {
|
||||
public String emptySearch;
|
||||
public String errorNum;
|
||||
public String choice;
|
||||
public String select;
|
||||
public String cantNext;
|
||||
public String cantLast;
|
||||
public String startSearch;
|
||||
@@ -41,6 +42,8 @@ public class SearchObj {
|
||||
return true;
|
||||
if (nextPage == null)
|
||||
return true;
|
||||
if (select == null)
|
||||
return true;
|
||||
return startSearch == null;
|
||||
}
|
||||
|
||||
@@ -59,6 +62,8 @@ public class SearchObj {
|
||||
errorNum = "<light_purple>[AllMusic]<red>请输入正确的序号";
|
||||
if (choice == null)
|
||||
choice = "<light_purple>[AllMusic]<yellow>你选择了序号:" + ARG.index;
|
||||
if (select == null)
|
||||
select = "<light_purple>[AllMusic]<dark_green>输入/music select [序号] 或 /music [序号] 选择搜索结果";
|
||||
if (cantNext == null)
|
||||
cantNext = "<light_purple>[AllMusic]<red>无法下一页";
|
||||
if (cantLast == null)
|
||||
|
||||
@@ -8,6 +8,23 @@ public class Function {
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转为整数
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param def 无法转换时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static int getInt(String str, int def) {
|
||||
if (str == null)
|
||||
return def;
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getString(String a, String b, String c) {
|
||||
int x = a.indexOf(b) + b.length();
|
||||
int y;
|
||||
|
||||
Reference in new issue
Block a user