Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fabegabe;
- import java.util.Properties;
- import java.util.concurrent.ExecutionException;
- import pro.beam.api.BeamAPI;
- import pro.beam.api.exceptions.BeamException;
- import pro.beam.api.resource.BeamUser;
- import pro.beam.api.resource.chat.BeamChat;
- import pro.beam.api.resource.chat.events.EventHandler;
- import pro.beam.api.resource.chat.events.IncomingMessageEvent;
- import pro.beam.api.resource.chat.methods.AuthenticateMessage;
- import pro.beam.api.resource.chat.replies.AuthenticationReply;
- import pro.beam.api.resource.chat.replies.ReplyHandler;
- import pro.beam.api.resource.chat.ws.BeamChatConnectable;
- import pro.beam.api.services.impl.ChatService;
- import pro.beam.api.services.impl.UsersService;
- import pro.beam.interactive.net.packet.Protocol.Report;
- import pro.beam.interactive.robot.Robot;
- import pro.beam.interactive.robot.RobotBuilder;
- import com.google.common.util.concurrent.FutureCallback;
- import com.google.common.util.concurrent.Futures;
- import com.google.common.util.concurrent.ListenableFuture;
- public class OSUBot {
- private BeamUser user;
- private ListenableFuture<Robot> robot;
- private BeamChat chat;
- private BeamChatConnectable chatConnectable;
- private BeamAPI api;
- public OSUBot(Properties properties) throws BeamException,
- InterruptedException, ExecutionException {
- this.api = new BeamAPI();
- String username = properties.getProperty("username");
- String password = properties.getProperty("password");
- this.user = api
- .use(UsersService.class)
- .login(username,
- password).checkedGet();
- this.robot = new RobotBuilder().username(username)
- .password(password)
- .channel(user.channel.id).build(api);
- this.chat = api.use(ChatService.class).findOne(user.channel.id).get();
- this.chatConnectable = chat.connectable(api);
- boolean connected = this.chatConnectable.connect();
- if (!connected) {
- System.err
- .println("ERROR >> Could not log in! Invalid login details, maybe?");
- this.chatConnectable.disconnect();
- System.exit(0);
- }
- this.chatConnectable.send(
- AuthenticateMessage.from(user.channel, user, chat.authkey),
- new ReplyHandler<AuthenticationReply>() {
- public void onSuccess(AuthenticationReply e) {
- System.out.println("Connected!");
- }
- });
- this.chatConnectable.on(IncomingMessageEvent.class,
- new EventHandler<IncomingMessageEvent>() {
- @Override
- public void onEvent(IncomingMessageEvent e) {
- // IncomingMessageData data = e.data;
- // TODO: Handle commands for later.
- }
- });
- Futures.addCallback(robot, new FutureCallback<Robot>() {
- @Override
- public void onFailure(Throwable t) {
- System.out.println("Error: " + t.getMessage());
- t.printStackTrace();
- System.exit(1);
- }
- @Override
- public void onSuccess(Robot r) {
- System.out.println("Success connecting to Beam.pro!");
- r.on(Report.class, new ScreenListener());
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment