Skip to content

Commit

Permalink
searchコマンドの不具合修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Mar 20, 2022
1 parent 6abcc5d commit 513dc3b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<!-- バージョン装飾子参考の参考に: https://kengotoda.gitbooks.io/what-is-maven/deploy/snapshot-and-stable.html -->
<version>0.6.7-beta.3</version>
<version>0.6.7-beta.4</version>
<packaging>jar</packaging>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void trackLoaded(AudioTrack track) {
@Override
public void playlistLoaded(AudioPlaylist playlist) {
builder.setColor(event.getGuild().getSelfMember().getColor())
.setText(FormatUtil.filter(client.getSuccess() + " の検索結果 `" + event.getOption("input").getAsString() + "`:"))
.setText(FormatUtil.filter(client.getSuccess() + " `" + event.getOption("input").getAsString() + "`の検索結果:"))
.setChoices()
.setSelection((msg, i) ->
{
Expand Down Expand Up @@ -153,72 +153,78 @@ public void loadFailed(FriendlyException throwable) {
}
}

private class ResultHandler implements AudioLoadResultHandler {
private class ResultHandler implements AudioLoadResultHandler
{
private final Message m;
private final CommandEvent event;

private ResultHandler(Message m, CommandEvent event) {
private ResultHandler(Message m, CommandEvent event)
{
this.m = m;
this.event = event;
}

@Override
public void trackLoaded(AudioTrack track) {
if (bot.getConfig().isTooLong(track)) {
m.editMessage(FormatUtil.filter(event.getClient().getWarning() + "**" + track.getInfo().title + "**`は許可されている最大長より長いです。"
+ FormatUtil.formatTime(track.getDuration()) + "` > `" + bot.getConfig().getMaxTime() + "`")).queue();
public void trackLoaded(AudioTrack track)
{
if(bot.getConfig().isTooLong(track))
{
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" この曲 (**"+track.getInfo().title+"**) は許可されている最大長よりも長いです。 `"
+FormatUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`")).queue();
return;
}
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor())) + 1;
m.editMessage(FormatUtil.filter(event.getClient().getSuccess() + "**" + track.getInfo().title
+ "**(`" + FormatUtil.formatTime(track.getDuration()) + "`) " + (pos == 0 ? "を追加しました。"
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1;
m.editMessage(FormatUtil.filter(event.getClient().getSuccess()+" **"+track.getInfo().title
+"** (`"+FormatUtil.formatTime(track.getDuration())+"`) "+(pos==0 ? "の再生を開始します。"
: "を" + pos + "番目の再生待ちに追加しました。"))).queue();
}

@Override
public void playlistLoaded(AudioPlaylist playlist) {
m.delete().queue();
public void playlistLoaded(AudioPlaylist playlist)
{
builder.setColor(event.getSelfMember().getColor())
.setText(FormatUtil.filter(event.getClient().getSuccess() + " の検索結果 `" + event.getArgs() + "`:"))
.setChoices()
.setSelection((msg, i) ->
.setText(FormatUtil.filter(event.getClient().getSuccess()+" `"+event.getArgs()+"`の検索結果:"))
.setChoices(new String[0])
.setSelection((msg,i) ->
{
AudioTrack track = playlist.getTracks().get(i - 1);
if (bot.getConfig().isTooLong(track)) {
event.replyWarning("**" + track.getInfo().title + "**`は許可されている最大長よりも長いです。"
+ FormatUtil.formatTime(track.getDuration()) + "` > `" + bot.getConfig().getMaxTime() + "`");
AudioTrack track = playlist.getTracks().get(i-1);
if(bot.getConfig().isTooLong(track))
{
event.replyWarning("この曲 (**"+track.getInfo().title+"**) は、許容される最大長より長いです。: `"
+FormatUtil.formatTime(track.getDuration())+"` > `"+bot.getConfig().getMaxTime()+"`");
return;
}
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor())) + 1;
event.replySuccess("**" + track.getInfo().title
+ "**(`" + FormatUtil.formatTime(track.getDuration()) + "`) " + (pos == 0 ? "を追加しました。"
: " を" + pos + "番目の再生待ちに追加しました。 "));
})
.setCancel((msg) -> {
AudioHandler handler = (AudioHandler)event.getGuild().getAudioManager().getSendingHandler();
int pos = handler.addTrack(new QueuedTrack(track, event.getAuthor()))+1;
event.replySuccess("**" + FormatUtil.filter(track.getInfo().title)
+ "** (`" + FormatUtil.formatTime(track.getDuration()) + "`) " + (pos==0 ? "の再生を開始します。"
: "を" + pos + "番目の再生待ちに追加しました。"));
})
.setCancel((msg) -> {})
.setUsers(event.getAuthor())
;
for (int i = 0; i < 4 && i < playlist.getTracks().size(); i++) {
for(int i=0; i<4 && i<playlist.getTracks().size(); i++)
{
AudioTrack track = playlist.getTracks().get(i);
builder.addChoices("`[" + FormatUtil.formatTime(track.getDuration()) + "]` [**" + track.getInfo().title + "**](" + track.getInfo().uri + ")");
builder.addChoices("`["+FormatUtil.formatTime(track.getDuration())+"]` [**"+track.getInfo().title+"**]("+track.getInfo().uri+")");
}
builder.build().display(m);
}

@Override
public void noMatches() {
m.editMessage(FormatUtil.filter(event.getClient().getWarning() + " の検索結果はありません。 `" + event.getArgs() + "`.")).queue();
public void noMatches()
{
m.editMessage(FormatUtil.filter(event.getClient().getWarning()+" `"+event.getArgs()+"`に該当する結果は見つかりませんでした。")).queue();
}

@Override
public void loadFailed(FriendlyException throwable) {

if (throwable.severity == Severity.COMMON)
m.editMessage(event.getClient().getError() + " 読み込み中にエラーが発生しました: " + throwable.getMessage()).queue();
public void loadFailed(FriendlyException throwable)
{
if(throwable.severity==Severity.COMMON)
m.editMessage(event.getClient().getError()+" 読み込みエラー: "+throwable.getMessage()).queue();
else
m.editMessage(event.getClient().getError() + " 読み込み中にエラーが発生しました").queue();
m.editMessage(event.getClient().getError()+" 曲の読み込みに失敗しました。").queue();
}
}
}

0 comments on commit 513dc3b

Please sign in to comment.