diff --git a/.idea/artifacts/Cartoland.xml b/.idea/artifacts/Cartoland.xml deleted file mode 100644 index 47da23b..0000000 --- a/.idea/artifacts/Cartoland.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - $PROJECT_DIR$/out/artifacts/Cartoland - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index 1ab8877..0290551 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,2 +1,3 @@ Manifest-Version: 1.0 Main-Class: cartoland.Cartoland + diff --git a/src/main/java/cartoland/Cartoland.java b/src/main/java/cartoland/Cartoland.java index 2012caf..0f938be 100644 --- a/src/main/java/cartoland/Cartoland.java +++ b/src/main/java/cartoland/Cartoland.java @@ -50,6 +50,7 @@ public static void main(String[] args) throws InterruptedException .addOption(OptionType.INTEGER,"lang_name", "The language that user want to change", false), Commands.slash("language", "Change language or check current languages") .addOption(OptionType.INTEGER,"lang_name", "The language that user want to change", false), + Commands.slash("megumin", "The best anime girl"), Commands.slash("shutdown", "Use this to shutdown the bot") .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER)) diff --git a/src/main/java/cartoland/events/BotOffline.java b/src/main/java/cartoland/events/BotOffline.java index b385433..835797e 100644 --- a/src/main/java/cartoland/events/BotOffline.java +++ b/src/main/java/cartoland/events/BotOffline.java @@ -1,8 +1,6 @@ package cartoland.events; -import cartoland.Cartoland; import cartoland.utility.FileHandle; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.session.ShutdownEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; @@ -13,11 +11,7 @@ public class BotOffline extends ListenerAdapter public void onShutdown(@NotNull ShutdownEvent event) { super.onShutdown(event); - TextChannel channel = event.getJDA().getChannelById(TextChannel.class, Cartoland.BOT_CHANNEL_ID); - if (channel != null) - channel.sendMessage("Cartoland bot is now offline").queue(); System.out.println("Cartoland Bot is now offline"); FileHandle.logIntoFile("Cartoland Bot is now offline"); - //System.exit(0); } } diff --git a/src/main/java/cartoland/events/commands/CommandUsage.java b/src/main/java/cartoland/events/commands/CommandUsage.java index 56fdc68..09b1c15 100644 --- a/src/main/java/cartoland/events/commands/CommandUsage.java +++ b/src/main/java/cartoland/events/commands/CommandUsage.java @@ -4,6 +4,7 @@ import cartoland.utility.FileHandle; import cartoland.utility.JsonHandle; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.commands.OptionMapping; @@ -39,6 +40,9 @@ public CommandUsage() commands.put("shutdown", event -> { event.reply("Shutting down...").queue(); + TextChannel channel = event.getJDA().getChannelById(TextChannel.class, Cartoland.BOT_CHANNEL_ID); + if (channel != null) + channel.sendMessage("Cartoland bot is now offline").queue(); event.getJDA().shutdown(); }); } @@ -54,8 +58,16 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even userID = member.getId(); commands.get(event.getName()).commandProcess(event); - System.out.println(member.getUser().getName() + "(" + userID + ") used " + event.getName() + " " + argument); - FileHandle.logIntoFile(member.getUser().getName() + "(" + userID + ") used " + event.getName() + " " + argument); + if (argument != null) + { + System.out.println(member.getUser().getName() + "(" + userID + ") used /" + event.getName() + " " + argument); + FileHandle.logIntoFile(member.getUser().getName() + "(" + userID + ") used /" + event.getName() + " " + argument); + } + else + { + System.out.println(member.getUser().getName() + "(" + userID + ") used /" + event.getName()); + FileHandle.logIntoFile(member.getUser().getName() + "(" + userID + ") used /" + event.getName()); + } } String minecraftCommandRelated(String jsonKey, @NotNull SlashCommandInteractionEvent event) diff --git a/src/main/java/cartoland/utility/FileHandle.java b/src/main/java/cartoland/utility/FileHandle.java index c2c7865..2ab8705 100644 --- a/src/main/java/cartoland/utility/FileHandle.java +++ b/src/main/java/cartoland/utility/FileHandle.java @@ -3,6 +3,7 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDate; import java.time.LocalTime; @@ -49,7 +50,7 @@ public static void logIntoFile(String output) { //一定要事先備好logs資料夾 FileWriter logWriter = new FileWriter("logs/" + LocalDate.now(), true); - logWriter.write(LocalTime.now() + " " + output + "\n"); //時間 內容 換行 + logWriter.write(LocalTime.now() + "\t" + output + "\n"); //時間 內容 換行 logWriter.close(); } catch (IOException e) @@ -59,13 +60,15 @@ public static void logIntoFile(String output) } } - static Random random = new Random(); + private static final Random random = new Random(); + private static final Path megumin = Paths.get("megumin"); public static String readRandomMeguminUrl() { int lineNumber = random.nextInt(350); + try { - Stream lines = Files.lines(Paths.get("megumin")); + Stream lines = Files.lines(megumin); Optional line = lines.skip(lineNumber).findFirst(); return line.orElse("pensukeo/status/1184557949714219009"); }