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,31 +1,45 @@
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.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.projecttl.p.x32.handler.Command;
import org.jetbrains.annotations.NotNull;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import static java.lang.String.format;
public class Ping implements Command {
@NotNull
@Override
public CommandData getData() {
return CommandData.fromData(new CommandDataImpl(
"ping",
"Discord API 레이턴시를 확인 합니다."
).toData());
}
@NotNull
@Override
public CommandData getData() {
return CommandData.fromData(new CommandDataImpl(
"ping",
"Discord API 레이턴시를 확인 합니다."
).toData());
}
@Override
public void execute(SlashCommandInteractionEvent ev) {
long current = System.currentTimeMillis();
ev.reply(":hourglass: Just wait a seconds...").queue(hook -> {
String content = format("**BOT**: %d**ms**\n", System.currentTimeMillis() - current) +
format("**API**: %d**ms**", ev.getJDA().getGatewayPing());
@Override
public void execute(SlashCommandInteractionEvent ev) {
long current = System.currentTimeMillis();
AtomicReference<MessageEmbed> embed = new AtomicReference<>(new EmbedBuilder()
.setDescription(":hourglass: Just wait a seconds...")
.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
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) {}
}