Skip to content

Commit

Permalink
Adminコマンドの不具合修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Apr 1, 2022
1 parent 513dc3b commit 5e9bda8
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 246 deletions.
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.4.0_350</version>
<version>4.4.0_352</version>
</dependency>
<dependency>
<groupId>com.github.Cosgy-Dev</groupId>
Expand Down Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils</artifactId>
<version>1.23.0</version>
<version>1.24.1</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -222,15 +222,19 @@
<goal>testCompile</goal>
</goals>
</execution>
</executions><configuration><source>8</source><target>8</target></configuration>
</executions>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.6.10</kotlin.version>
</properties>
</project>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void load() {
+ "\nhttps://github.com/jagrosh/MusicBot/wiki/Getting-a-Bot-Token."
+ "\nBOTトークン: ");
if (token == null) {
prompt.alert(Prompt.Level.WARNING, CONTEXT, "トークンが入力されていません!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.WARNING, CONTEXT, "トークンが入力されていません!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath());
return;
} else {
write = true;
Expand All @@ -157,7 +157,7 @@ public void load() {
owner = 0;
}
if (owner <= 0) {
prompt.alert(Prompt.Level.ERROR, CONTEXT, "無効なユーザーIDです!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.ERROR, CONTEXT, "無効なユーザーIDです!終了します。\n\n設定ファイルの場所: " + path.toAbsolutePath());
System.exit(0);
} else {
write = true;
Expand All @@ -182,7 +182,7 @@ public void load() {
// if we get through the whole config, it's good to go
valid = true;
} catch (ConfigException | IOException ex) {
prompt.alert(Prompt.Level.ERROR, CONTEXT, ex + ": " + ex.getMessage() + "\n\n設定ファイルの場所: " + path.toAbsolutePath().toString());
prompt.alert(Prompt.Level.ERROR, CONTEXT, ex + ": " + ex.getMessage() + "\n\n設定ファイルの場所: " + path.toAbsolutePath());
}
}

Expand Down Expand Up @@ -358,5 +358,7 @@ public boolean isOfficialInvite() {
return officialInvite;
}

public boolean isUseInviteCommand(){return useinvitecommand; }
public boolean isUseInviteCommand() {
return useinvitecommand;
}
}
64 changes: 4 additions & 60 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,73 +139,15 @@ public static void main(String[] args) {
}

List<Command> commandList = new ArrayList<Command>() {{
//その他
add(new HelpCmd(bot));
add(aboutCommand);
if(config.isUseInviteCommand()){
add(new InviteCommand());
}
add(new PingCommand());
add(new SettingsCmd(bot));
if (config.getCosgyDevHost()) add(new InfoCommand(bot));
// General
add(new ServerInfo());
//add(new UserInfo());
add(new CashCmd(bot));
// Music
add(new LyricsCmd(bot));
add(new NowplayingCmd(bot));
add(new PlayCmd(bot));
add(new PlaylistsCmd(bot));
add(new MylistCmd(bot));
//add(new QueueCmd(bot));
add(new QueueCmd(bot));
add(new RemoveCmd(bot));
add(new SearchCmd(bot));
add(new SCSearchCmd(bot));
add(new NicoSearchCmd(bot));
add(new ShuffleCmd(bot));
add(new SkipCmd(bot));
add(new VolumeCmd(bot));
// DJ
add(new ForceRemoveCmd(bot));
add(new ForceskipCmd(bot));
add(new NextCmd(bot));
add(new MoveTrackCmd(bot));
add(new PauseCmd(bot));
add(new PlaynextCmd(bot));
//add(new RepeatCmd(bot));
add(new RepeatCmd(bot));
add(new SkipToCmd(bot));
add(new PlaylistCmd(bot));
add(new StopCmd(bot));
//add(new VolumeCmd(bot));
// Admin
add(new PrefixCmd(bot));
add(new SetdjCmd(bot));
add(new SkipratioCmd(bot));
add(new SettcCmd(bot));
add(new SetvcCmd(bot));
add(new AutoplaylistCmd(bot));
add(new ServerListCmd(bot));
// Owner
add(new DebugCmd(bot));
add(new SetavatarCmd(bot));
add(new SetgameCmd(bot));
add(new SetnameCmd(bot));
add(new SetstatusCmd(bot));
add(new PublistCmd(bot));
add(new ShutdownCmd(bot));
//add(new LeaveCmd(bot));
}};

cb.addCommands(commandList.toArray(new Command[0]));

// スラッシュコマンドの実装
List<SlashCommand> slashCommandList = new ArrayList<SlashCommand>() {{
add(new HelpCmd(bot));
add(aboutCommand);
if(config.isUseInviteCommand()){
if (config.isUseInviteCommand()) {
add(new InviteCommand());
}
add(new PingCommand());
Expand Down Expand Up @@ -244,6 +186,7 @@ public static void main(String[] args) {
add(new StopCmd(bot));
//add(new VolumeCmd(bot));
// Admin
//add(new ActivateCmd(bot));
add(new PrefixCmd(bot));
add(new SetdjCmd(bot));
add(new SkipratioCmd(bot));
Expand All @@ -270,7 +213,7 @@ public static void main(String[] args) {
if (config.getStatus() != OnlineStatus.UNKNOWN)
cb.setStatus(config.getStatus());
if (config.getGame() == null)
cb.setActivity(Activity.playing(config.getPrefix() + config.getHelp() + "でヘルプを確認"));
cb.setActivity(Activity.playing("/" + config.getHelp() + "でヘルプを確認"));
else if (config.getGame().getName().toLowerCase().matches("(none|なし)")) {
cb.setActivity(null);
nogame = true;
Expand Down Expand Up @@ -303,6 +246,7 @@ else if (config.getGame().getName().toLowerCase().matches("(none|なし)")) {
.setBulkDeleteSplittingEnabled(true)
.build();
bot.setJDA(jda);

} catch (LoginException ex) {
prompt.alert(Prompt.Level.ERROR, "JMusicBot", ex + "\n" +
"正しい設定ファイルを編集していることを確認してください。Botトークンでのログインに失敗しました。" +
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import java.awt.*;
import java.nio.ByteBuffer;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -206,7 +205,7 @@ public Message getNowPlaying(JDA jda) {
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(guild.getSelfMember().getColor());
RequestMetadata rm = getRequestMetadata();
if(!track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
if (!track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
if (rm.getOwner() != 0L) {
User u = guild.getJDA().getUserById(rm.user.id);
if (u == null)
Expand All @@ -233,9 +232,7 @@ public Message getNowPlaying(JDA jda) {
+ " `[" + FormatUtil.formatTime(track.getPosition()) + "/" + FormatUtil.formatTime(track.getDuration()) + "]` "
+ FormatUtil.volumeIcon(audioPlayer.getVolume()));

}
else
{
} else {
JSONObject data = XML.toJSONObject(GensokyoInfoAgent.getInfo()).getJSONObject("GENSOKYORADIODATA");

String titleUrl = data.getJSONObject("MISC").getString("CIRCLELINK").equals("") ?
Expand Down Expand Up @@ -291,7 +288,7 @@ public String getTopicFormat(JDA jda) {
AudioTrack track = audioPlayer.getPlayingTrack();

// 幻想郷ラジオを再生しているか確認
if(track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
if (track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
return "**幻想郷ラジオ** [" + (userid == 0 ? "自動再生" : "<@" + userid + ">") + "]"
+ "\n" + (audioPlayer.isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI) + " "
+ "[LIVE] "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public void onTrackUpdate(long guildId, AudioTrack track, AudioHandler handler)
if (bot.getConfig().getSongInStatus()) {
if (track != null && bot.getJDA().getGuilds().stream().filter(g -> Objects.requireNonNull(g.getSelfMember().getVoiceState()).inVoiceChannel()).count() <= 1)

if(track.getInfo().uri.contains("https://stream.gensokyoradio.net/")){
if (track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
bot.getJDA().getPresence().setActivity(Activity.listening("幻想郷ラジオ"));
}else {
} else {
bot.getJDA().getPresence().setActivity(Activity.listening(track.getInfo().title));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void init() {
);
}

TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(t -> registerSourceManager(t));
TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(this::registerSourceManager);
AudioSourceManagers.registerRemoteSources(this);
AudioSourceManagers.registerLocalSource(this);
source(YoutubeAudioSourceManager.class).setPlaylistPageCount(10);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/audio/QueuedTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AudioTrack getTrack() {
@Override
public String toString() {

if(track.getInfo().uri.contains("https://stream.gensokyoradio.net/")){
if (track.getInfo().uri.contains("https://stream.gensokyoradio.net/")) {
JSONObject data = XML.toJSONObject(GensokyoInfoAgent.getInfo()).getJSONObject("GENSOKYORADIODATA");
String title = data.getJSONObject("SONGINFO").getString("TITLE");
String titleUrl = data.getJSONObject("MISC").getString("CIRCLELINK").equals("") ?
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/jmusicbot/entities/Prompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Prompt {
private final String noguiMessage;

private boolean nogui;
private boolean noprompt;
private final boolean noprompt;
private Scanner scanner;

public Prompt(String title) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/utils/OtherUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand Down Expand Up @@ -87,7 +88,7 @@ public static String readString(InputStream inputStream) throws IOException {
into.write(buf, 0, n);
}
into.close();
return into.toString("utf-8");
return into.toString(StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

public class HelpCmd extends SlashCommand {
public Bot bot;
public HelpCmd(Bot bot){

public HelpCmd(Bot bot) {
this.bot = bot;
this.name = "help";
this.help = "コマンド一覧を表示します。";
Expand All @@ -40,7 +41,7 @@ protected void execute(SlashCommandEvent event) {
Category category = null;
List<Command> commands = client.getCommands();
for (Command command : commands) {
if (!command.isHidden() && (!command.isOwnerCommand() ||event.getMember().isOwner())) {
if (!command.isHidden() && (!command.isOwnerCommand() || event.getMember().isOwner())) {
if (!Objects.equals(category, command.getCategory())) {
category = command.getCategory();
builder.append("\n\n __").append(category == null ? "カテゴリなし" : category.getName()).append("__:\n");
Expand Down Expand Up @@ -81,13 +82,13 @@ public void execute(CommandEvent event) {
if (event.getClient().getServerInvite() != null)
builder.append("\n\nさらにヘルプが必要な場合は、公式サーバーに参加することもできます: ").append(event.getClient().getServerInvite());

if(bot.getConfig().getHelpToDm()){
if (bot.getConfig().getHelpToDm()) {
event.replyInDm(builder.toString(), unused ->
{
if (event.isFromType(ChannelType.TEXT))
event.reactSuccess();
}, t -> event.replyWarning("ダイレクトメッセージをブロックしているため、ヘルプを送信できません。"));
}else{
} else {
event.reply(builder.toString());
}
}
Expand Down
Loading

0 comments on commit 5e9bda8

Please sign in to comment.