So I have been working on JDA for a while now and I wanted to create a quiz system in which people can answer using reactions. The problem is: I am stuck on how to check who voted which reaction. I have my code here:
public void onMessageReactionAdd(MessageReactionAddEvent event) {
MessageReaction reaction = event.getReaction();
ReactionEmote emote = reaction.getReactionEmote();
//if user reaction = certain emote then ...
}
I am stuck on that because I can't seem to find any API regarding a user's reaction. Any help will be appreaciated!
You need to save every single vote with the voting user in a Database.
Use MongoDB or MySQL for example.
Related
I am creating a bot for Discord using JDA (Java). I am facing a problem while trying to get my bot to play music in my voice channel.
The problem is in the following code
public static void startPlaying(net.dv8tion.jda.core.entities.Guild guild) {
//Player player = getMyURLPlayer(guild.getJDA());
FilePlayer player = getMyFilePlayer();
//DiscordBot.bot.getAudioManager(guild).setSendingHandler(player);
guild.setSendingHandler(player);
System.out.println("Player.play is getting executed...");
player.play();
}
In the above code, the following line is incorrect according to eclipse
guild.setSendingHandler(player);
It says that
The method setSendingHandler(FilePlayer) is undefined for the type Guild
I am assuming that you are referencing http://jda.readthedocs.io/en/latest/pages/audio.html based on the code you've posted. The documentation on that site is beyond out of date. Not only is it incomplete and slightly incorrect, it is also for JDA 1.x. JDA is currently in 3.x and has undergone significant changes.
Additionally, FilePlayer (and URLPlayer) have been removed from JDA completely as they were incomplete and slightly buggy examples. For a proper implementation of an AudioSendHandler and player system, consider using Lavaplayer.
Lavaplayer has an example directory for JDA here
If you have any questions, feel free to join the JDA Discord Guild and ask. There is also a channel especially for Lavaplayer support.
Can someone please explain what is the difference between CreateUser(String) and CreateUser(User,Credential) in confluence. I want to create one user for confluence, if user is not there in the group. There is no information in confluence documentation. :(
I wrote code like this, but not sure whetehr it will accept createUser method twice in same line.
userAccessor.createUser(userAccessor.createUser(username), Credential.encrypted(password));
I am guesing, if inside createUser is executed,then it will throw an exception at outside parent createUser as it is trying to create same user again?
Please give me your thoughts
Thanks
Samuel.
The new createUser(User, Credential) method replaces the old createUser(String) method, so you should use the former and construct a user with all the details:
User user = userAccessor.createUser(new DefaultUser("mryall", "Matt Ryall", "matt#mattryall.net"),
Credential.unencrypted("secret"));
The reason for having this API was to reduce the number of calls needed to create a user, and fix the potential race condition where you're creating a user with a username but with otherwise empty fields (name, email, password).
This entire API is very poorly documented. I work on the Confluence team at Atlassian - so mea culpa! We'll try to get this fixed.
I am having a hell of a time figuring this out. I want to make a basic search engine in my Play-Framework 2.1 Java app. The app has a list of video game records stored in a MySQL database. The UI lets you type in a video game title and search for it. The Play app should return a list of all games that match the query that the user entered. If the user searches for "Mario", it should return a list of all games that contain that text.
Currently what I have in my Controller is:
public class Games extends controller {
//NOTE: instance fields omitted
public static Result search() {
DynamicForm form = form().bindFromRequest();
//Query is now stored in form.get("q"), though I can't figure out how to use it
List<Game> games = new Model.Finder(String.class, Game.class).all();
//This returns every game currently in the database
return ok(search.render(games);
}
}
I looked all throughout the Play 2.0.3 documentation (NOTE: I could not find documentation for 2.1 that covers this, which is the version I'm using) for the Model.Finder class and could not find out how to search custom queries, or how to build a SQL query that I want. I am quite lost and intermediate at Java. HELP! :-(
This is specific question for ebean not for Play.
You may do like this:
List<Game> games = new Model.Finder(String.class, Game.class)
.where().like("name", "foo%").findList();
I am looking for simple way to connect information about requirement/release and source code.
The case is that developer should be able to find any artifacts created given release or CR in easy way.
The idea I have is to introduce some new annotation to mark any new class ( I am not sure if it is good for any new method) for example:
#ArtifactInfo(release="1.2" cr="cr123")
Do you have any other ideas? Maybe you use already something similar?
Take care,
Marcin
IMO the code is the wrong place for that kind of information.
Take a look at the imaginary code below.
class Authenticator {
login(String username, String password){
User user = retrieveUserFromDatabase(username);
throwIfWrongpassword(user, password);
verifyUserAge(user)
}
void throwIfWrongpassword(User user, String password){
//throws AuthenticationException if password is wrong
}
void verifyUserAge(User user){
//verify that user is above 18 or account is authorized by a parent
}
void biometricLogin(String username, BiometricImage bioimg){
User user = retrieveUserFromDatabase(username);
verifyBiometricImage(user, password);
verifyUserAge(user);
}
}
This is the result of a few requirements:
Users must authenticate to have acces to the system
Users can use biometric authentication instead on password auth
Underaged users must be authorized be parents or something like that.
All those requirements were added in different poins of time, on different versions of the software.
A class-level, or even a method-level annotation won't suffice to effectively map requirements to code.
You'd have to use a "line of code"-level annotation.
Of course, that's impractical.
The right way to do that is to follow a few best practices when using the source code repository and the bug tracker:
1) Every requirement corresponds to one or more issues on the bug tracker
2) Every commit message starts with a corresponding issue key, like "PROJ-123 - a nice feature"
3) When you do a release (meaning, incrementing your software version), you tell the bug tracker that those issues were fixed in that version.
If you need to know what requirements were implemented in what version, ask your bug tracker.
If you need to know all the code that was produced for a given requirement, ask your source code repository (filter commits by log message)
If you need to know what is the requirement for a given line of code, ask your source code repository. GIT and SVN have a "blame" command that will tell you, for a given file, for each line of code, who commited it, when, and the commit message (which will have the issue number if everyone on the team is a good boy) - So this will work as that hypothetical "line-of-code"-level annotation.
Using "commit hooks" can help you enforce rule 2) in an organization.
Maven has some degree of integration with JIRA and other bug trackers, and maybe it can help automate #3. But I haven't really used it like that. But if it doesn't do what you need, you can always ask for more :-)
I have looked in vain for a good example or starting point to write a java based facebook application... I was hoping that someone here would know of one. As well, I hear that facebook will no longer support their java API is this true and if yes does that mean that we should no longer use java to write facebook apps??
There's a community project which is intended to keep the Facebook Java API up to date, using the old official Facebook code as a starting point.
You can find it here along with a Getting Started guide and a few bits of sample code.
Facebook stopped supporting the official Java API on 5 May 2008 according to their developer wiki.
In no way does that mean you shouldn't use Java any more to write FB apps. There are several alternative Java approaches outlined on the wiki.
You might also want to check this project out; however, it only came out a few days ago so YMMV.
I write an example using facebook java api
It use FacebookXmlRestClient in order to make client request and print
all user infos
http://programmaremobile.blogspot.com/2009/01/facebook-java-apieng.html
BatchFB provides a modern Java API that lets you easily optimize your Facebook calls down to a minimum set:
http://code.google.com/p/batchfb/
Here's the example taken from the main page of what you can effectively do in a single FB request:
/** You write your own Jackson user mapping for the pieces you care about */
public class User {
long uid;
#JsonProperty("first_name") String firstName;
String pic_square;
String timezone;
}
Batcher batcher = new FacebookBatcher(accessToken);
Later<User> me = batcher.graph("me", User.class);
Later<User> mark = batcher.graph("markzuckerberg", User.class);
Later<List<User>> myFriends = batcher.query(
"SELECT uid, first_name, pic_square FROM user WHERE uid IN" +
"(SELECT uid2 FROM friend WHERE uid1 = " + myId + ")", User.class);
Later<User> bob = batcher.queryFirst("SELECT timezone FROM user WHERE uid = " + bobsId, User.class);
PagedLater<Post> feed = batcher.paged("me/feed", Post.class);
// No calls to Facebook have been made yet. The following get() will execute the
// whole batch as a single Facebook call.
String timezone = bob.get().timezone;
// You can just get simple values forcing immediate execution of the batch at any time.
User ivan = batcher.graph("ivan", User.class).get();
You might want to try Spring Social. It might be limited in terms of Facebook features, but lets you also connect to Twitter, LinkedIn, TripIt, GitHub, and Gowalla.
The other side of things is that as Facebook adds features some of the old API's might break, so using a simpler pure FB api (that you can update when things don't work) might be a good idea.
This tutorial will literally step you through everything you need to do: http://ocpsoft.org/opensource/creating-a-facebook-app-setup-and-tool-installation/
It comes in 3 parts. The other 2 are linked from there.