diff --git a/src/main/java/net/projecttl/p/x32/command/Ping.java b/src/main/java/net/projecttl/p/x32/command/Ping.java index 51d7283..963118b 100644 --- a/src/main/java/net/projecttl/p/x32/command/Ping.java +++ b/src/main/java/net/projecttl/p/x32/command/Ping.java @@ -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 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(); + }); + } } diff --git a/src/main/kotlin/net/projecttl/p/x32/Database.kt b/src/main/kotlin/net/projecttl/p/x32/Database.kt index 0094a73..9cff878 100644 --- a/src/main/kotlin/net/projecttl/p/x32/Database.kt +++ b/src/main/kotlin/net/projecttl/p/x32/Database.kt @@ -1,4 +1,4 @@ package net.projecttl.p.x32 class Database { -} \ No newline at end of file +} diff --git a/src/main/kotlin/net/projecttl/p/x32/service/ServiceProvider.kt b/src/main/kotlin/net/projecttl/p/x32/service/ServiceProvider.kt index 9b8b851..c631815 100644 --- a/src/main/kotlin/net/projecttl/p/x32/service/ServiceProvider.kt +++ b/src/main/kotlin/net/projecttl/p/x32/service/ServiceProvider.kt @@ -1,4 +1,16 @@ package net.projecttl.p.x32.service -interface ServiceProvider { +import org.jetbrains.exposed.sql.transactions.transaction + +interface ServiceProvider { + fun 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) {} } \ No newline at end of file