mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
🐛 fix(apps/music.js): correct regex patterns and improve error messages for music commands in bot interaction
This commit is contained in:
parent
941c5a2cc6
commit
840d26300a
@ -25,11 +25,11 @@ export class CrystelfMusic extends plugin {
|
|||||||
priority: -1000,
|
priority: -1000,
|
||||||
rule: [
|
rule: [
|
||||||
{
|
{
|
||||||
reg: '^#?点歌\\s+(.+)$',
|
reg: '^#?点歌\\s*(.+)$',
|
||||||
fnc: 'handleSearch'
|
fnc: 'handleSearch'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '^#?听\\s+(.+)$',
|
reg: '^#?听\\s*(.+)',
|
||||||
fnc: 'handleDirectPlay'
|
fnc: 'handleDirectPlay'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -53,7 +53,6 @@ export class CrystelfMusic extends plugin {
|
|||||||
const adapter = await YunzaiUtils.getAdapter(e);
|
const adapter = await YunzaiUtils.getAdapter(e);
|
||||||
await Message.emojiLike(e, e.message_id, 60, e.group_id, adapter);
|
await Message.emojiLike(e, e.message_id, 60, e.group_id, adapter);
|
||||||
const result = await musicSearch.handleSearch(e, keyword);
|
const result = await musicSearch.handleSearch(e, keyword);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
await e.reply({
|
await e.reply({
|
||||||
type: 'image',
|
type: 'image',
|
||||||
@ -62,7 +61,6 @@ export class CrystelfMusic extends plugin {
|
|||||||
} else {
|
} else {
|
||||||
await e.reply(`${result.message}`, true);
|
await e.reply(`${result.message}`, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[crystelf-music] 处理搜索失败:', error);
|
logger.error('[crystelf-music] 处理搜索失败:', error);
|
||||||
await e.reply('搜索失败,请稍后重试', true);
|
await e.reply('搜索失败,请稍后重试', true);
|
||||||
@ -75,18 +73,35 @@ export class CrystelfMusic extends plugin {
|
|||||||
*/
|
*/
|
||||||
async handleDirectPlay(e) {
|
async handleDirectPlay(e) {
|
||||||
try {
|
try {
|
||||||
const songName = e.msg.replace(/^#?听\s*/, '').trim();
|
const content = e.msg.replace(/^#?听\s*/, '').trim();
|
||||||
if (!songName) {
|
if (!content) {
|
||||||
return await e.reply('请输入要听的歌名,例如:#听 夜曲', true);
|
return await e.reply('请输入要听的歌名或序号,例如:#听 夜曲 或 #听 1', true);
|
||||||
|
}
|
||||||
|
const index = parseInt(content);
|
||||||
|
if (!isNaN(index) && index >= 1 && index <= 20) {
|
||||||
|
const searchResult = musicSearch.getGroupSearchResult(e.group_id);
|
||||||
|
if (!searchResult) {
|
||||||
|
return await e.reply('没有找到当前可选择的音乐列表,请先搜索歌曲', true);
|
||||||
}
|
}
|
||||||
const adapter = await YunzaiUtils.getAdapter(e);
|
const adapter = await YunzaiUtils.getAdapter(e);
|
||||||
await Message.emojiLike(e, e.message_id, 60, e.group_id, adapter);
|
await Message.emojiLike(e, e.message_id, 60, e.group_id, adapter);
|
||||||
const result = await musicSearch.handleDirectPlay(e, songName);
|
const result = await musicSearch.handleSelection(e, index);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
await this.sendMusicResult(e, result);
|
await this.sendMusicResult(e, result);
|
||||||
} else {
|
} else {
|
||||||
await e.reply(`${result.message}`, true);
|
await e.reply(`${result.message}`, true);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const adapter = await YunzaiUtils.getAdapter(e);
|
||||||
|
await Message.emojiLike(e, e.message_id, 60, e.group_id, adapter);
|
||||||
|
|
||||||
|
const result = await musicSearch.handleDirectPlay(e, content);
|
||||||
|
if (result.success) {
|
||||||
|
await this.sendMusicResult(e, result);
|
||||||
|
} else {
|
||||||
|
await e.reply(`${result.message}`, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[crystelf-music] 处理直接播放失败:', error);
|
logger.error('[crystelf-music] 处理直接播放失败:', error);
|
||||||
await e.reply('播放失败,请稍后重试', true);
|
await e.reply('播放失败,请稍后重试', true);
|
||||||
@ -134,7 +149,9 @@ export class CrystelfMusic extends plugin {
|
|||||||
await Group.sendGroupRecord(e, e.group_id, `file://${audioFile}`, adapter);
|
await Group.sendGroupRecord(e, e.group_id, `file://${audioFile}`, adapter);
|
||||||
} else {
|
} else {
|
||||||
const extension = await this.getFileExtension();
|
const extension = await this.getFileExtension();
|
||||||
const filename = `${song.displayTitle} - ${song.displayArtist}.${extension}`;
|
const sanitizedTitle = song.displayTitle.replace(/\s+/g, '_');
|
||||||
|
const sanitizedArtist = song.displayArtist.replace(/\s+/g, '_');
|
||||||
|
const filename = `${sanitizedTitle} - ${sanitizedArtist}.${extension}`;
|
||||||
await Group.sendGroupFile(e, e.group_id, `file://${audioFile}`, filename, adapter);
|
await Group.sendGroupFile(e, e.group_id, `file://${audioFile}`, filename, adapter);
|
||||||
}
|
}
|
||||||
musicSearch.clearUserSelection(e.group_id, e.user_id);
|
musicSearch.clearUserSelection(e.group_id, e.user_id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user