Page Menu
Home
desp's stash
Search
Configure Global Search
Log In
Files
F374384
Choose.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
Choose.java
View Options
package
me.despawningbone.discordbot.command.misc
;
import
java.util.Arrays
;
import
java.util.Random
;
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.TextChannel
;
import
net.dv8tion.jda.api.entities.User
;
import
net.dv8tion.jda.api.utils.MarkdownSanitizer
;
public
class
Choose
extends
Command
{
public
Choose
()
{
this
.
desc
=
"Let me choose the best for you!"
;
this
.
usage
=
"<choice> | <choice> [...]"
;
this
.
examples
=
Arrays
.
asList
(
"eggs | ham | sausage | tomato"
);
}
@Override
//tags might get echoed if someone did "markdown injection" lmao //nvm fixed
public
CommandResult
execute
(
TextChannel
channel
,
User
author
,
Message
msg
,
String
[]
args
)
{
if
(
args
.
length
<
1
)
{
return
new
CommandResult
(
CommandResultType
.
INVALIDARGS
,
"Please enter something for me to choose from lol"
);
}
String
stripped
=
MarkdownSanitizer
.
sanitize
(
String
.
join
(
" "
,
args
));
String
[]
split
=
stripped
.
split
(
" *\\| *"
);
Random
randomno
=
new
Random
();
//System.out.println(split.length);
if
(
split
.
length
<
2
||
(
split
.
length
==
2
&&
(
split
[
0
].
isEmpty
()
||
split
[
1
].
isEmpty
())))
{
return
new
CommandResult
(
CommandResultType
.
INVALIDARGS
,
"At least put 2 choices for me to choose from lol"
);
}
else
if
(
Arrays
.
asList
(
split
).
contains
(
""
))
{
return
new
CommandResult
(
CommandResultType
.
INVALIDARGS
,
"Please do not input empty choices."
);
}
int
ran
=
randomno
.
nextInt
(
split
.
length
);
channel
.
sendMessage
(
"<@!"
+
author
.
getId
()
+
">: If I were you, I would have chosen `"
+
split
[
ran
]
+
"` :stuck_out_tongue:"
).
queue
();
return
new
CommandResult
(
CommandResultType
.
SUCCESS
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Aug 4, 1:54 PM (14 h, 59 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
64/b4/118416a0eada1e38c6d06f9ad0a2
Attached To
rDESB despbot
Event Timeline
Log In to Comment