Get a user's presence - discord JDA library - java

I'm trying to write a discord bot using JDA, and while I can get the presence of the bot fairly easily, I cannot get the presence of a selected user. An example use case for this might be the user typing in a command like !game and then the bot sends a message telling the user what game they're playing. As far as I know, the bot cannot get the user's game activity without getting the user's presence, and I do not see a way to do so. If I missed it in the documentation, please link the method/class.

After a bunch of digging and documentation reading, I have come to a solution. There is no way to get a presence like I was thinking, but since my original intent was to get the game activity, this solution works. First, the bot must have guild presence permissions granted through the developer portal. Then we need to include the line jdaBuilder.enableIntents(GatewayIntent.GUILD_PRESENCES); before we call the build method in our main method. Finally, to get member activities, we need to include jdaBuilder.enableCache(CacheFlag.ACTIVITY);. This lets us use the member.getActivities() method. Generally speaking, getting data associated with specific users requires enabling guild presences.

Related

Send proactive message without prior interaction

I use this sample: 16.proactive-messages - as the base for my bot and it works fine, but I'd like to extend it, so that it can send messages in a group chat without anyone interacting with it first (like sending a "Hello I'm up!" message at startup), because currently it can only respond if someone has mentioned the bot after it has initialized.
Perhaps there is a proper way to get the group chat(s) where the bot resides at the bot initialization?
I've answered before some tips on Proactive messaging, please see here for that.
To answer your question though, the bot can definitely start the engagement, either by replying to an existing message in a group chat or starting a completely new thread in the chat. However, it does require to have been installed initially, either by a user or programmatically (e.g. Graph API). That part only needs to be done once, then you can capture the conversation reference and use it again anytime thereafter. That is shown in the sample I link to in my other answer I referenced above.
It's not possible to send proactive message without prior interaction.
Sending a proactive message is different from sending a regular message. There's no active turnContext to use for a reply. You must create the conversation before sending the message.
Ref Doc: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=dotnet

FirebaseUser - how to use PhoneAuthCredential parameter for FirebaseUser.updatePhoneNumber(PhoneAuthCredential)

I'm in the middle of developing an Android app using Firebase, and have Phone Number Authentication enabled as a method of user sign-in. This all works fine.
Inside my app, I have an Account Details page that allows the user to edit their information and update their record in the FirebaseDatabase (in a separate node that I have created and called users). I'm able to update this table with no problems, but I need to update the table that Firebase keeps when users register, so that phone numbers don't get out of sync.
In theory, it should be really easy to do. I've done some reading up and seen that a method exists in the FirebaseUser class called updatePhoneNumber(PhoneAuthCredential). The only problem is that I have no idea how the PhoneAuthCredential class works and, after a couple of hours of Googling, haven't been able to find a single example, or many other forms of support for the method.
An example for the FirebaseUser.updateEmail(String) method can be seen here, so I'd guess that it can't be all that different, and should work fine if I can get the PhoneAuthCredential object set up correctly.
Update:
I tried to create an instance using new PhoneAuthCredential(...), but the suggested parameters aren't much help...
Android Studio displays the constructor as public PhoneAuthCredential(String s, String s1, boolean b, String s2, boolean b2, String s3), so I am very much none-the-wiser.
If I can figure out how to use this constructor, I might well be off the ground, hopefully.
If anyone can advise on how to use PhoneAuthCredential, or how the FirebaseUser.updatePhoneNumber() method should be implemented, that would be a huge help!
Thanks in advance,
Mark
Phone auth is quite complicated, so I'd recommend reading this guide. This section is especially relevant to your case. Basically, you'll have to go through the entire phone auth flow again to get a credential and set the user's new phone number.
If you're thinking of the phone number as a part of the user's profile, that's incorrect as you can see from the profile request. The phone number is considered to be a sort of user identifier, like the email which also requires a credential if the user's sign-in action is 5 mins old. Hope this helps!

What should I do to receive turn based match update properly if I use tbmp skeleton but tbmp skeleton is not the main activity?

I am attempting to use tbmp skeleton but I do not use it as the main activity. Everything seems to work except when during testing I try to accept an invitation and get to the next turn screen to perform Turn 1(the second turn). In onActivityResult (in the secondary Activity I start with an Intent) the line:
TurnBasedMatch match = data.getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH);
triggers a BadParcelableException: ClassNotFoundException when unmarshalling TurnBasedMatchEntity
The previously asked question on the site about "BadParcelablException on passing TurnBasedMatch in intent" did not provide any useful leads. I have tried over 2 dozen variations in the code published as alphas and tested. I have come to the conclusion that the problem is that I do not have tbmp skeleton set up as the main activity. Is there some way around this problem that does not require me to try to combine my normal main Activity with SkeletonActivity in tbmp? Otherwise, tbmp as a secondary activity seems to work just fine. It signs in automatically to google+, I can "start match", "check games", "sign out", and start an auto game. A game created by "start match" lets the starter add to the present string and clicking Done results in a game that can be seen in "check games". Selection of an opponent (my other gmail test account) works. The other test gmail account can see the game in check games and can accept an invitation. If the other gmail game process is active and signed in then when the 1st game process sends the invitation I see the toast on the 2nd game process that gives notice that an invitation is received. However, there is no way to get to Turn 1 assuming getSelectOpponentsIntent is used in onStartMatchClicked. Replacing getSelectOpponentsIntent with createMatch seems to lead to what is essentially auto match.
If I used auto match to start a game in the 1st test account, and use auto match subsequently in the 2nd test account then in the 2nd account I DO get to Turn 1 but then the same problem reappears because the 1st account can never actually see or make the Turn 2 move.
There are 4 other questions on this site which hit around this problem.
"How to detect Intent from Google Play Services Notification", "How to determine the match selected from a Google Play turn based notification", "TBMP Skeleton:Why are both onTurnBasedMatchReceived and onInvitationReceived not called on physical device", and (peripherally) "TBMP Skeleton-How do I override notification events". Sync is on for my accounts and notifications is on for Google Play Games. Adding another extra to the intent and searching for that does not seem to work. Turning on and off registerMatchUpdateListener and registerInvitationListener does not produce beneficial results. I think it would be helpful to know what are the needed changes to tbmp skeleton when you shift it to not being the main activity. To my eyes, this is a common problem with Java code, you often cannot move a code block from one place to another because it will break if you do.
My alternate course of actions are 1)set up tbmp skeleton in an alpha-only google play account and see if problem replicates when SkeletonActivity is the main activity, 2)graft SkeletonActivity onto my normal main activity, 3)drop tbmp skeleton and try to use another example from github or programcreek
If you are getting invitations/match updates via notifications and just not getting your listener called make sure you remembered to register the listeners!!! I spent way too long on this, simply forgot to register the listener(was positive I had too lol).
Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
Games.TurnBasedMultiplayer.registerMatchUpdateListener(mGoogleApiClient, this);
Don't use ACCEPT INVITATION code from android github sample given below:
TurnBasedMatch match = data.getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH);
Instead, use the below method to get the match value:
public Task<TurnBasedMatch> acceptInvitation (String invitationId)
& use event listener to get the match & further proceed to take turn.
If you fail to use the above method, debugging the app works fine while the release version crashes & return the same exception after publishing in play store.
It's not mandatory to register listeners which is depreciated methods & instead register callbacks to get invitation Id.
Add this line to your proguard configuration:
-keep class com.google.android.gms.games.multiplayer.turnbased.TurnBasedMatchEntity
Consider also adding this one for the invitations:
-keep class com.google.android.gms.games.multiplayer.InvitationEntity

Android app, Google maps api location validation for java

I'm using Android Studio to create an app that utilizes google maps api. I am having trouble validating if the user input is an actual location.
i.e if the user enters "fdfdfaef", program crashes.
i have the following code to store the user "location" input:
address = geocoder.getFromLocationName(location, 1)
Any help on how to check if the input is valid or not or at least to prevent a crash. Thanks and appreciate it.
Since you haven't posted any code, I will go out on a limb and suggest that you might be doing this on your main UI thread.
From the doc,
The query will block and returned values will be obtained by means of
a network lookup. The results are a best guess and are not guaranteed
to be meaningful or correct. It may be useful to call this method from
a thread separate from your primary UI thread.
Try doing a async task that requests information using the Geocoding API. On getting a result, update the UI. Offloading to an AsyncTask will prevent the crash, at the very least.
Does that help you?

New user creation notification mails are not going in Alfresco

When Admin creates a new user account, an email should go to the created user's mail id.
How can I enable this? Can I do it in "alfresco-global.properties", If yes, how?
I don't think that is possible out of the box. You could however implement this functionality with a java behavior. Be sure to not interfere with the emails that is sent out when inviting external users though otherwise those will get double emails.
Update after doing some research:
Well, someone made a decision to not make the notification option configurable in the create user gui. I have followed the calls made from the GUI down to the repository and it ends up calling a java method documented like this:
/**
* Create a Person with an optionally generated user name.
* This version doesn't notify them.
*
*/
Which means you have to do some coding to implement notifications in this scenario.

Categories