-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Banned user support #252
Comments
What is "it"? I don't understand what you're asking here. Can you provide the code you're using and a sample use case? |
I got a NullPointerException so I assumed that reddit.user("") returned null, but it did not(the .about() call threw the exception) however, there don't seem to be a direct distinction between non-existent and banned users only with the exceptions they throw(NullPointer for banned and ApiException for not existing ones). val user = reddit.user(name)
if (user.isSelf) {
BotUtils.sendMsg(event.getChannel, "Oh, that is me! Hello!")
} else try {
val about = user.about() //this throws the exceptions
/*...*/
} catch {
case _: ApiException =>
/*...If the user doesn't exist and reddit returns 404...*/
case _: NullPointerException =>
/*...If the user is banned...*/
case e: Exception =>
logger.error(s"Unknown error occurred: ${e.getClass.toString}: ${e.getMessage}")
} I suggested that instead of throwing a NullPointerException the .about() call could still create a user and it should have a suspended field that can be checked val user = reddit.user(name)
val about = user.about()
if (about.isSuspended) {
/*The user is suspended*/
} else (about.isNotExistent) { //needs a better naming
/*User doesn't exist and reddit returned 404*/
} else {
/* The user is normal a user and about can be used safely */
} |
Can you post the stacktrace of the NPE? |
Sorry for late response, here it is.
|
Can you given an example of a user that's banned? That NPE is definitely a bug |
Fixed with commit Use AccountQuery query = redditClient.user("TheFlintASteel").query();
if (query.getStatus() == AccountStatus.SUSPENDED) {
// do something
} else if (query.getStatus() == AccountStatus.NON_EXISTENT) {
// do something
} else {
Account account = query.getAccount();
// do something
} |
Whenever a user is banned or doesn't exist it just returns null. A banned user should be created with an isSuspended or something field, to be able to check it. Because Reddit returns this for banned users:
And just a 404 for not existent ones:
EDIT:
I was being stupid, non-existent ones generate a different error, but this feature still wouldn't be bad for easier management of suspended users.
The text was updated successfully, but these errors were encountered: