Page Menu
Home
desp's stash
Search
Configure Global Search
Log In
Files
F374144
CommandResult.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
CommandResult.java
View Options
package
me.despawningbone.discordbot.command
;
import
net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
;
import
net.dv8tion.jda.api.utils.messages.MessageCreateData
;
public
class
CommandResult
{
//for logging
private
CommandResultType
t
;
private
String
r
;
public
enum
CommandResultType
{
//TODO add a noargs to specify please enter something to search for?
INTERRUPTED
,
INVALIDARGS
,
//print help?
NORESULT
,
NOPERMS
,
TOOLONG
,
FAILURE
,
//generic failure
ERROR
,
SUCCESS
,
DISABLED
}
public
CommandResult
(
CommandResultType
type
,
String
remarks
)
{
//TODO overload with CommandResult(CommandResultType, Exception)?
t
=
type
;
r
=
remarks
;
}
public
CommandResult
(
CommandResultType
type
)
{
t
=
type
;
r
=
null
;
}
public
CommandResultType
getResultType
()
{
return
t
;
}
public
String
getRemarks
()
{
return
t
==
CommandResultType
.
NORESULT
||
t
==
CommandResultType
.
NOPERMS
||
t
==
CommandResultType
.
TOOLONG
?
null
:
r
;
}
//make a getLogLevel() for log4j integration later?
public
MessageCreateData
getMessage
()
{
MessageCreateBuilder
mb
=
new
MessageCreateBuilder
();
switch
(
t
)
{
case
DISABLED:
case
SUCCESS:
//already sent message
return
null
;
case
INTERRUPTED:
//both are errors
case
ERROR:
String
[]
splits
=
r
.
split
(
"\n"
);
String
line
=
"Unknown Source"
;
for
(
String
split
:
splits
)
{
if
(
split
.
matches
(
"(?s).*command\\..*"
)
&&
split
.
trim
().
startsWith
(
"at"
))
{
line
=
split
.
replaceFirst
(
".*command\\..*\\((.*?)\\).*"
,
"$1"
);
break
;
}
}
mb
.
addContent
(
"Something went wrong at `"
+
line
+
"`: `"
+
splits
[
0
].
replaceAll
(
":.*"
,
""
)
+
"`"
);
break
;
case
NOPERMS:
mb
.
addContent
(
"You need the `"
+
r
+
"` permission(s) for this channel to execute that command."
);
break
;
case
NORESULT:
mb
.
addContent
(
"Unfortunately there was no results"
+
(
r
!=
null
?
" for "
+
r
:
""
)
+
" :cry:"
);
break
;
case
TOOLONG:
mb
.
addContent
(
"The description was too long discord can't stand it :joy:"
);
break
;
default
:
//TODO add "For help, do" for INVALIDARGS?
mb
.
addContent
(
r
);
}
return
mb
.
build
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Aug 3, 3:58 AM (42 m, 6 s)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
86/48/4bd4d8876e7be69031b007b986de
Attached To
rDESB despbot
Event Timeline
Log In to Comment