Skip to content

Commit

Permalink
Change offline message
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCai2019 committed Jan 15, 2023
1 parent a6f9065 commit b7131db
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 40 deletions.
29 changes: 0 additions & 29 deletions .idea/artifacts/Cartoland.xml

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Manifest-Version: 1.0
Main-Class: cartoland.Cartoland

1 change: 1 addition & 0 deletions src/main/java/cartoland/Cartoland.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/cartoland/events/BotOffline.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
16 changes: 14 additions & 2 deletions src/main/java/cartoland/events/commands/CommandUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/cartoland/utility/FileHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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<String> lines = Files.lines(Paths.get("megumin"));
Stream<String> lines = Files.lines(megumin);
Optional<String> line = lines.skip(lineNumber).findFirst();
return line.orElse("pensukeo/status/1184557949714219009");
}
Expand Down

0 comments on commit b7131db

Please sign in to comment.