mirror of
https://github.com/devproje/px32-bot.git
synced 2024-11-26 10:43:05 +00:00
feat: change ping command output to [string message => embed]
This commit is contained in:
parent
3478cfc229
commit
49af19fcd3
3 changed files with 45 additions and 19 deletions
|
@ -1,11 +1,16 @@
|
|||
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 {
|
||||
|
@ -21,11 +26,20 @@ public class Ping implements Command {
|
|||
@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());
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {}
|
||||
}
|
Loading…
Reference in a new issue