feat: change ping command output to [string message => embed]

This commit is contained in:
Project_IO 2024-09-02 14:40:29 +09:00
parent 3478cfc229
commit 49af19fcd3
3 changed files with 45 additions and 19 deletions

View file

@ -1,11 +1,16 @@
package net.projecttl.p.x32.command; package net.projecttl.p.x32.command;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.projecttl.p.x32.handler.Command; import net.projecttl.p.x32.handler.Command;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import static java.lang.String.format; import static java.lang.String.format;
public class Ping implements Command { public class Ping implements Command {
@ -21,11 +26,20 @@ public class Ping implements Command {
@Override @Override
public void execute(SlashCommandInteractionEvent ev) { public void execute(SlashCommandInteractionEvent ev) {
long current = System.currentTimeMillis(); long current = System.currentTimeMillis();
ev.reply(":hourglass: Just wait a seconds...").queue(hook -> { AtomicReference<MessageEmbed> embed = new AtomicReference<>(new EmbedBuilder()
String content = format("**BOT**: %d**ms**\n", System.currentTimeMillis() - current) + .setDescription(":hourglass: Just wait a seconds...")
format("**API**: %d**ms**", ev.getJDA().getGatewayPing()); .build());
hook.editOriginal(content).queue(); ev.replyEmbeds(embed.get()).queue(hook -> {
Random r = new Random();
embed.set(new EmbedBuilder()
.setTitle(":ping_pong: Pong!")
.addField("\uD83E\uDD16", format("**%d**ms", System.currentTimeMillis() - current), true)
.addField("\uD83D\uDD0C", format("**%d**ms", ev.getJDA().getGatewayPing()), true)
.setColor(r.nextInt(0x000001, 0xffffff))
.build());
hook.editOriginalEmbeds(embed.get()).queue();
}); });
} }
} }

View file

@ -1,4 +1,16 @@
package net.projecttl.p.x32.service package net.projecttl.p.x32.service
interface ServiceProvider { import org.jetbrains.exposed.sql.transactions.transaction
interface ServiceProvider<P, T> {
fun <T> dbQuery(block: () -> T): T =
transaction { block() }
fun create(data: T)
fun read(id: P): T?
fun update(id: P, data: T) {}
fun delete(id: P) {}
} }