mirror of
https://github.com/devproje/px32-bot.git
synced 2024-11-29 20:13:06 +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,31 +1,45 @@
|
||||||
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 {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public CommandData getData() {
|
public CommandData getData() {
|
||||||
return CommandData.fromData(new CommandDataImpl(
|
return CommandData.fromData(new CommandDataImpl(
|
||||||
"ping",
|
"ping",
|
||||||
"Discord API 레이턴시를 확인 합니다."
|
"Discord API 레이턴시를 확인 합니다."
|
||||||
).toData());
|
).toData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@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();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {}
|
||||||
}
|
}
|
Loading…
Reference in a new issue