Page Menu
Home
desp's stash
Search
Configure Global Search
Log In
Files
F399116
Ping.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
Ping.java
View Options
package
me.despawningbone.discordbot.command.info
;
import
java.time.OffsetDateTime
;
import
java.time.temporal.ChronoUnit
;
import
java.util.Arrays
;
import
me.despawningbone.discordbot.command.Command
;
import
me.despawningbone.discordbot.command.CommandResult
;
import
me.despawningbone.discordbot.command.CommandResult.CommandResultType
;
import
net.dv8tion.jda.api.entities.Message
;
import
net.dv8tion.jda.api.entities.channel.concrete.TextChannel
;
import
net.dv8tion.jda.api.entities.User
;
public
class
Ping
extends
Command
{
public
Ping
()
{
this
.
desc
=
"Check the round trip latency between the server and the bot!"
;
this
.
usage
=
"[debug]"
;
this
.
remarks
=
Arrays
.
asList
(
"Putting the debug parameter will output the WebSocket latency too."
);
}
@Override
public
CommandResult
execute
(
TextChannel
channel
,
User
author
,
Message
msg
,
String
[]
args
)
{
//DONE USE RESTACTION INSTEAD
OffsetDateTime
timesent
=
OffsetDateTime
.
now
();
if
(
args
.
length
>
0
&&
args
[
0
].
equals
(
"debug"
))
{
channel
.
sendMessage
(
":ping_pong: Pong! Response latency: "
).
queue
(
m
->
{
long
ms
=
Math
.
abs
(
timesent
.
until
(
OffsetDateTime
.
now
(),
ChronoUnit
.
MILLIS
));
// System.out.println(String.valueOf(ms));
channel
.
editMessageById
(
m
.
getId
(),
":ping_pong: Pong! Response latency: "
+
ms
+
"ms"
+
(
ms
<
250
?
"\nNot bad! :D"
:
ms
>
500
?
"\nWow. God damn Internet issues!"
:
""
)).
queue
();
channel
.
sendMessage
(
"WebSocket response latency: "
+
channel
.
getJDA
().
getGatewayPing
()
+
"ms"
).
queue
();
});
}
else
{
channel
.
getJDA
().
getRestPing
().
queue
(
ms
->
channel
.
sendMessage
(
":ping_pong: Pong! Response latency: "
+
ms
+
"ms"
+
(
ms
<
250
?
"\nNot bad! :D"
:
ms
>
500
?
"\nWow. God damn Internet issues!"
:
""
)).
queue
());
}
return
new
CommandResult
(
CommandResultType
.
SUCCESS
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, Oct 8, 11:30 PM (2 h, 29 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5c/24/a3785d348a3155cc54bf80a13ad6
Attached To
rDESB despbot
Event Timeline
Log In to Comment