I have a Problem with Discord4Js MemberJoinEvent - java

I just started programming a new Discord bot for myself to see what I am able to create. Currently, I'm working on an Autorole feature but I just don't get why the Bot doesn't get triggered by a MemberJoinEvent.
Here is my code:
gateway.getEventDispatcher().on(MemberJoinEvent.class).subscribe(memberJoinEvent -> {
final Member member = memberJoinEvent.getMember();
System.out.println(member.toString());
});

I found the problem! I didnt know that discord changed something in their developer portal. Also I used my old project so I didnt notice it.
You have to manualy enable it in the developer portal, that the bot can access member information. A screenshot of the location to enable the gateway feature

In addition to leguans answer, I also had to request the gateway intents as well!
GatewayDiscordClient gatewayDiscordClient() {
return discordClient()
.gateway()
.setEnabledIntents(IntentSet.all())
.login()
.block();
}
https://docs.discord4j.com/migrating-from-v3-1-to-v3-2/#gateway-intents

Related

How to fix AWS 403 error "Check your AWS Secret Access Key and signing method" when calling SES listcontacts

I have been stuck for about the past 6 hours at this point I'm thinking the only reasonable explanations are that this is a AWS SDK bug or the error message is wrong.
I am using SESv2 class from the AWS SDK in a JAVA SpringBoot app and attempting to manage various details of my SES (Simple Email Service) account.
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.*;
I have created an IAM user, created security credentials, set them up using multiple different methods as described here guid to credentials environment I've given full access to SES to this IAM role user. I then wrote some code and I was able to do all of the following,
Create a contact list
Delete a contact list
Create contact
Create a Topic in a contact list
Send an email
However, for some unknown reason when I go to test a function I wrote to get a list of contacts so I can test sending an email to multiple contacts I get the following 403 error message,
The request signature we calculated does not match the signature you
provided. Check your AWS Secret Access Key and signing method. Consult
the service documentation for details.
I've verified the credentials are correct. I have created a new set of credentials and made the old set inactive. No dice, all the functions listed above still work however the listContacts in the SesV2Client class still fails with the same error. As you can see below I even bypassed the env variables and just hardcoded the key and secret to pull out all the stops, still fails. In the function that fails, I've gone over and over the values im passing in they are valid and exist 100% because as I said I can make the other calls in the list above to verify the topics and contact list exists.
private List<Contact> listContactsForSiteUpdatesMailingList() {
try (SesV2Client client = SesV2Client.builder()
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
.build()){
TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
ListContactsRequest listContactsRequest = ListContactsRequest.builder()
.contactListName(CONTACT_LIST).filter(listContactsFilter).build();
ListContactsResponse listContactsResponse = client.listContacts(listContactsRequest);
return listContactsResponse.contacts();
} catch (Exception ex) {
System.out.println("The email was not sent. Error message: "
+ ex.getMessage());
return null;
}
}
Whats going on here and how can I get to the bottom of this error?
EDIT:
Looking at AWS Console Users>Access Management and then looking at the user a created I can even verify that there was "programmatic access"
An example of accessing a ContactList with no issues
EDIT 2: My SES account is currently sandboxed. I just wanted to mention the question is this possibly happening because of that? Grasping at straws here.
I was able to reproduce your issue. I created a list and added a contact. Both worked. However, when i executed listContacts, I got this error:
This looks like a bug. To address this, open a Github issue on the SDK Java Github here:
https://github.com/aws/aws-sdk-java
This is confirmed as a bug in the AWS SDK. To get around this you can use the async client like so
SesV2AsyncClient client = SesV2AsyncClient.builder()
.region(Region.US_EAST_1)
.build())
TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
ListContactsRequest listContactsRequest = ListContactsRequest.builder()
.contactListName(CONTACT_LIST).filter(listContactsFilter).build();
CompletableFuture<ListContactsResponse> listContactsResponseCompletableFuture = client.listContacts(listContactsRequest);
ListContactsResponse listContactsResponse = listContactsResponseCompletableFuture.get();

Firebase access Hackernews

So i wanted to check out Firebase and try connecting to Hackernews Firebase database.
I'm using the com.google.firebase:firebase-server-sdk:3.0.3 sdk.
But I am not sure why i am forced to enter a service account.
#Bean
fun firebase(): DatabaseReference {
val options = FirebaseOptions.Builder()
.setDatabaseUrl("https://hacker-news.firebaseio.com/")
.setServiceAccount(this.javaClass.getResourceAsStream("/account.json"))
.build()
val app = FirebaseApp.initializeApp(options)
val instance = FirebaseDatabase.getInstance(app)
return instance.reference
}
Why is setServiceAccount required in this case ? If i leave it out i get following exception:
Caused by: java.lang.IllegalStateException: Service Account must be provided.
at com.google.firebase.internal.Preconditions.checkState(Preconditions.java:173) ~[firebase-server-sdk-3.0.3.jar:na]
at com.google.firebase.FirebaseOptions.<init>(FirebaseOptions.java:129) ~[firebase-server-sdk-3.0.3.jar:na]
Is there a way to connect to Firebase anonymously with a Java client?
This JsFiddle works without a service account:
http://jsfiddle.net/firebase/cm8ne9nh/
If i connect to my own project, this work perfectly nice. I do have a proper service account for my own projects thought...
Thought i might be able to connect with Java the same way.
Any ideas ? Is there a way to connect to Hackernews with the Firebase Java API?
Unfortunately, the Java SDK is only available in two flavors. Java-Client-Android, and Java-Server. Which means, if you want pure client code, you can only really use it on android. This has always been a strange limitation of the available client libraries.
However, what you can do, is wrap the REST API that firebase provides with Java, using HTTP requests to perform everything like you would in any client library.
An example of a repository that has already implemented this is here: https://github.com/j-fischer/rest-on-fire
You could use that one, or you could use your own. But in order to use firebase without a service account, you will have to either use the REST Api or the official Client Libraries which are only writen for Android, iOS, and Web.
Although in the docs here it is not obvious
https://github.com/HackerNews/API
I found this REST API that does not need authentication:
https://hn.algolia.com/api
It can be used in many ways, including with Retrofit & Moshi and no authentication.
Just one example in Kotlin:
interface HackerNewsService {
#GET("search?tags=(story,show_hn,front_page)&hitsPerPage=500")
fun searchStories(#Query("query") q: String, #Query("numericFilters") filters: String, #Query("page") page: Int): Call<SearchResult>
}
val response = hackerNewsService.searchStories(keyword, "created_at_i>$after", 0).execute()
if (response.isSuccessful) {
val searchResult: SearchResult = response.body()!!
println("results! (${searchResult.hits.size}) $searchResult")
} else {
println("uh oh")
}

Java, Evernote : Revoke access for app on Evernote

I am working on a Java project which has Evernote services integrated into it through an app created on Evernote. Currently, everything is working fine except for access-revocation.
When an user who has already authorized the app, at some point decides not to give this app any access, I would like to also de-authorize the app from the users evernote account.
For this, I am searching for some sample, but came empty handed. One link I found was this, where it was required to call that method with UserStore. I have the access-token, but unfortunately I am only working with NoteStoreClient, rather than UserStore.
Here is the revocation code I have so far.
Person person = this.personService.getCurrentlyAuthenticatedUser();
if (!(person == null)) {
if (person.isEvernoteConsumed()) {
try {
this.evernoteDAO.deleteEvernoteForUser(person.getId());
Evernote evernote = getUsersEvernote(person.getId());
EvernoteAuth evernoteAuth = new EvernoteAuth(EVERNOTE_SERVICE, evernote.getAccessToken());
NoteStoreClient noteStoreClient = new ClientFactory(evernoteAuth).createNoteStoreClient();
}catch (Exception e){
e.printStackTrace();
}
}
}
Nothing fancy in that code, I know. If anyone has any idea of revocation from Evernote, kindly let me know. Thank you.
You're on the right track, that UserStore method will let you revoke your OAuth session. Like you said, you have to use the userstore client instead, you should be able to create it the same way as you did the notestore client:
UserStoreClient userStoreClient =
new ClientFactory(evernoteAuth).createUserStoreClient();
userStoreClient.revokeLongSession(evernoteAuth);

How do you set up a redirect from www to non-www with Play! Java 2.3 running the default server?

I recently set up a website and pushed it to production using Digital Ocean. However, I noticed that for both SEO purposes and to make Facebook Share work appropriately, I should set up my server to redirect www. requests to non-www. I'm running Play! Java 2.3 with a PostgreSQL database and the default Netty server. Any advice would be greatly appreciated.
There are lots of ways of redirecting. I wouldn't say DNS-redirects are the correct and only way of doing it, it's one way. Google is just fine with you doing a 301 redirect with Play.
Here's one way of accomplishing it with Play! filters (scala):
object NonWwwFilter extends Filter {
def apply(f:RequestHeader => Future[Result])(rh: RequestHeader): Future[Result] =
if (rh.host.startsWith("www.")) {
Future.successful(Results.MovedPermanently("https://" + rh.host.substring(4) + rh.uri))
} else {
f(rh)
}
}
The right way to do it is to do in not on the framework/webserver side, but on the DNS-server side.
You can do it in DNS-management area of GoDaddy or any other domain name registrar.

Android – Facebook SDK AppEventsLogger logEvent doesn't work

Googling didn't help me. I'm trying to push data on Facebook dashboard via Facebook app events
My code is:
AppEventsLogger logger = AppEventsLogger.newLogger(this);
logger.activateApp(this, Utility.FACEBOOK_ID);
logger.logEvent(AppEventsConstants.EVENT_NAME_COMPLETED_TUTORIAL);
So, activateApp works fine, but logEvent doesn't.
I've checked app ID and recreated it, but I have the same problem.
Hi you can try add the next row after 'logEvent' method.
logger.flush();
I hope it will be helpful for you.
you need to make sure you have initialized the FB successfully before you calling the logger events:
Facebook.sdkInitilize(Context context);

Categories

Resources