Guest User

full code.

a guest
May 17th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package com.fabegabe;
  2.  
  3. import java.util.Properties;
  4. import java.util.concurrent.ExecutionException;
  5.  
  6. import pro.beam.api.BeamAPI;
  7. import pro.beam.api.exceptions.BeamException;
  8. import pro.beam.api.resource.BeamUser;
  9. import pro.beam.api.resource.chat.BeamChat;
  10. import pro.beam.api.resource.chat.events.EventHandler;
  11. import pro.beam.api.resource.chat.events.IncomingMessageEvent;
  12. import pro.beam.api.resource.chat.methods.AuthenticateMessage;
  13. import pro.beam.api.resource.chat.replies.AuthenticationReply;
  14. import pro.beam.api.resource.chat.replies.ReplyHandler;
  15. import pro.beam.api.resource.chat.ws.BeamChatConnectable;
  16. import pro.beam.api.services.impl.ChatService;
  17. import pro.beam.api.services.impl.UsersService;
  18. import pro.beam.interactive.net.packet.Protocol.Report;
  19. import pro.beam.interactive.robot.Robot;
  20. import pro.beam.interactive.robot.RobotBuilder;
  21.  
  22. import com.google.common.util.concurrent.FutureCallback;
  23. import com.google.common.util.concurrent.Futures;
  24. import com.google.common.util.concurrent.ListenableFuture;
  25.  
  26. public class OSUBot {
  27.  
  28. private BeamUser user;
  29. private ListenableFuture<Robot> robot;
  30. private BeamChat chat;
  31. private BeamChatConnectable chatConnectable;
  32. private BeamAPI api;
  33.  
  34. public OSUBot(Properties properties) throws BeamException,
  35. InterruptedException, ExecutionException {
  36. this.api = new BeamAPI();
  37. String username = properties.getProperty("username");
  38. String password = properties.getProperty("password");
  39. this.user = api
  40. .use(UsersService.class)
  41. .login(username,
  42. password).checkedGet();
  43. this.robot = new RobotBuilder().username(username)
  44. .password(password)
  45. .channel(user.channel.id).build(api);
  46. this.chat = api.use(ChatService.class).findOne(user.channel.id).get();
  47. this.chatConnectable = chat.connectable(api);
  48. boolean connected = this.chatConnectable.connect();
  49. if (!connected) {
  50. System.err
  51. .println("ERROR >> Could not log in! Invalid login details, maybe?");
  52. this.chatConnectable.disconnect();
  53. System.exit(0);
  54. }
  55. this.chatConnectable.send(
  56. AuthenticateMessage.from(user.channel, user, chat.authkey),
  57. new ReplyHandler<AuthenticationReply>() {
  58. public void onSuccess(AuthenticationReply e) {
  59. System.out.println("Connected!");
  60. }
  61. });
  62. this.chatConnectable.on(IncomingMessageEvent.class,
  63. new EventHandler<IncomingMessageEvent>() {
  64. @Override
  65. public void onEvent(IncomingMessageEvent e) {
  66. // IncomingMessageData data = e.data;
  67. // TODO: Handle commands for later.
  68. }
  69. });
  70. Futures.addCallback(robot, new FutureCallback<Robot>() {
  71.  
  72. @Override
  73. public void onFailure(Throwable t) {
  74. System.out.println("Error: " + t.getMessage());
  75. t.printStackTrace();
  76. System.exit(1);
  77. }
  78.  
  79. @Override
  80. public void onSuccess(Robot r) {
  81. System.out.println("Success connecting to Beam.pro!");
  82. r.on(Report.class, new ScreenListener());
  83. }
  84.  
  85. });
  86. }
  87.  
  88. }
Add Comment
Please, Sign In to add comment