Pircbot, problems with retrieving a full userList - java

Doing a twitchbot as a little hobby project and stumble om a little problem.
I want to make a viewer list where it automatically shows when viewers enter my channel. The problem i got is that the list that is being retrieved only shows the bot. I have read through the javadocs and i thought that i did everything correctly but i just cant get it to work.
So when the bot connects to a server the onuserlist() method is called and retrieves a userlist, but the only user it gets is the bot. Even if i got 5, 10, 100 people in my channel.
#Override
protected void onUserList(String channel, User[] users) {
for (User user1 : users) {
System.out.println(user1);
model.addElement(user1.getNick());
}
super.onUserList(channel, users);
}
The onjoin() method should update the userlist with the following piece of code and it is called everytime someone joins. But even here it is the same problem, the only user that it can find is the bot. I wonder know if someone has got a better knowledge about pircbots and knows what i might be doing wrong?
User[] user=bot.getUsers("#mychannel");
for(int i =0; i<user.length;i++){
System.out.println(user[i]);
}
According to the java doc it should give me a User array of all the people in my channel, but it only gives me one.
http://www.jibble.org/javadocs/pircbot/

User[] user=bot.getUsers("#mychannel");
for (User usr : user){
System.out.println(usr.toString());
}
}

So I just figured this problem out today, if you are using the JOIn/Part system, you need to request permission from the server when you connect using
bot_Object.sendRawLine("CAP REQ :twitch.tv/membership");
This lets Twitch know that you want to use the Join/Part capabilities.
If you want to know more, here is their help guide for setting up different IRC clients, I just pulled the command for permission and used it in my bot.
http://help.twitch.tv/customer/portal/articles/1302780-twitch-irc

Related

Online Multipler Games in Java

In Java, is there a way to make a client/server system for a game without having to enter ips (like in Minecraft).
But instead, have it automatically connect the user to a game when he requests to join one (like in Fortnite, or surviv.io).
The only method I current know for client/server is having to give each user a server ip to connect to (like in Minecraft), so I was wondering if I could do it this way.
Thanks in advance.
IMHO, I think in all ".io" games, they are only hiding the registration processing. In my case, the previous game I made had a feature calls "Quick Play".
When a player uses that playing method and first time joins the game, I get his device's ID (for example in Android) then use it as a unique ID for that player in-game (I'm not sure about iOS but you can get that unique value in Android).
You can see the example below:
_on(TEvent.CONNECTION_SUCCESS, args -> {
var connection = Connection.convert(args[0]);
var message = TObject.convert(args[1]);
info("CONNECTION", connection.getAddress());
// Allow the connection login into server (become a player)
String username = message.getString("u");
// Should confirm that credentials by data from database or other services, here
// is only for testing
_playerApi.login(new PlayerLogin(username), connection);
return null;
});
Now when a new user login, he will send his device's ID and I can treat him a new player and make that ID as his name (or making a randomized name for him)
You can see more detail in the link below:
Login Example

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 to provide other members’ information to users through Facebook Graph API

I’m making a dating application that provides ‘members’ information (Facebook profile) to a user’ just like other dating applications. And I used Facebook Graph API below but I would like someone to tell me about ‘how to provide other members’ information to a user’.
Firstly, I registered my application in Facebook developers
I was approved with functions I need to use through 'Submit Items for Approval' (my Approved Items: email, public_profile, User_photo, User_like, user_work_history, user_education_history)
Then, I created member DB through a server and as a result, I can check all users’ ID with interlocked Facebook login.
So if a user logs in with her/his account in my application, (s)he can call her/his detail information in the account. (User_photo, User_like, user_work_history, user_education_history)
But the problem is, the user needs to receive members’ information around him/her (User_photo) but it doesn’t seem to work. (public_profile information can be provided)
It means, after receiving the user’s ID, it is forwarded to a server to use {user-id}/albums and {user-id}/photos call source. But it still says there is no result for both. (Brings GraphUser information through Facebook login and brings user_id through GraphUser.getId() )
So I am wondering if only the information in the ID section of logged in account is visible, but it seems an application called highli*** is using the service.
I would like to request someone to help me to solve the problem of # 5,6? Please help me (Please see the source)
Bring album_id through the method below by using user_id information
new Request(Session.getActiveSession(), "/user_id/albums", null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
} }).executeAsync();
Bring photo information through the method below by using album_id information
new Request(Session.getActiveSession(), "/album_id/photos", null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
} }).executeAsync();
If the Facebook Graph API is returning no results (an empty array) then more than likely it is a permissions issue.
In order for you to access another user’s information, the other user must also have given the required permissions.
For example:
User A is requesting the information of User B. Both users must grant the permissions below for the following requests:
user_friends, user_photos
{UserB-Id}/albums
{UserB-Id}/photos
{Album-Id}/photos
I suggest using the Graph API Explorer to test your requests. Here you can mock a token for your app and also apply different permissions, even before Facebook gives you approval to use them.
You can find more info on permissions here.

UserEmailAddressException when calling login() function in Liferay

I want to have LinkedIn authentication in my website. Their API returns the desired information, the create account function is working. However, I seem to have some problems when I try to login on the site.
It seems that I get a UserEmailAddressException when I call the LoginUtil.login method.
at com.liferay.portal.service.impl.UserLocalServiceImpl.authenticate(UserLocalServiceImpl.java:2480).
It fails at
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
if (!Validator.isEmailAddress(login)) {
throw new UserEmailAddressException();
}
}
Here is my code :
boolean rememberMe = true;
String authType = CompanyConstants.AUTH_TYPE_EA;
try {
LoginUtil.login(request, response,
String.valueOf(user.getUserId()), user.getPassword(), rememberMe, authType);
}
catch (UserEmailAddressException ueae) {
ueae.printStackTrace();
}
The users authenticate via email address, so I guess that should be the correct authentication type?
I have added company.security.auth.type=emailAddress in portal-ext.properties, but I get the same error as without this setting.
Because Liferay documentation is unsatisfying, I would like to know how to do a proper call to the login() function so that my user will login with its LinkedIn account.
It's hard to answer this question from the amount of code that you give.
First of all: About documentation. Judging by the use of LoginUtil, you seem to be modifying Liferay's internal code in order to implement your functionality. This is an internal API that is not guaranteed to be stable and will most likely be documented last (the API documentation has improved a lot, but it's mostly about the external, public API).
You might want to look into the implementation of ServletFilters that Liferay uses for implementing other external single sign on systems. Many customers/users have implemented these successfully (I haven't looked at the state of that documentation though, but there are several SSO implementations that you can find)
Further, it will probably help, which email address is supposed to be invalid - from your code it looks like you're calling with user.getUserId() (this is numeric), but you state that you demanded the login to be through email.
Lastly, if you have configured the login method through the UI, it is saved to the database - and that setting would win. So please check ControlPanel/Portal/Portal Settings/Authentication/"How do users authenticate?" to make sure that the setting is actually asking for the email address.

problems with session handling - HttpSession and a Session been created by Websockets

i hope someone has an answer to my problem.
In our gwt-webapp we use normally the HttpSession to create a user session. So if someone wants to log into our game, we set a session via HttpSession
public void setSessionID(String id) {HttpSession httpSession = getThreadLocalRequest().getSession(true); httpSession.setAttribute("id", id); }
The order of the views is:
LoginView-> HomeView -> LobbyView
Now when going into the lobby, he will be connected with the chat via a websocket Connection. The problem now is, that the websocketConnection will also create a sessionObject i think.
Testing the app on a jetty v-8.1.2.v20120308 shows:
if the first user log into the game and join directly the lobby with chatfunction and another user do it the same way, they can chat with each other- so everything looks fine...
but if the two users log into the game at the same time before someone joined the lobby, and then join the lobby, the second one who has entered the lobby gets all the parameters of the first user who has entered, so that there are both user with the same identity... dont know whats going wrong there.
It seems that the websocketSession from the first user overrides the httpSession from the login of the second player...
thanks for any solutions or ideas which problem this could might be.
This is a bug in Jetty which clear/destroy everything after the handshake. The solution is to close the session at that moment and wrap the request with that fake session. You can also use the Atmosphere Framework[1], which transparently fixes that for you (and much more.
-- Jeanfrancois
[1] https://github.com/Atmosphere/atmosphere

Categories

Resources