Package reddit.bot

Source Code of reddit.bot.RedditBot

package reddit.bot;

import reddit.response.RedditMessageDispatcher;
import reddit.response.RedditMessageResponseListener;
import reddit.response.ResponseStrategy;
import reddit.web.RedditClient;
import chatbot.client.ClientConnection;
import chatbot.client.ConnectionListener;
import chatbot.client.MessageChannel;
import chatbot.client.MessageDispatcher;
import chatbot.client.MessageListener;

public class RedditBot implements ConnectionListener {

  private final ClientConnection clientConnection;
  private final String channelName;
  private final ResponseStrategy responseStrategy;

  public RedditBot(ClientConnection connection, String channelName, ResponseStrategy responseStrategy) {
    this.clientConnection = connection;
    this.channelName = channelName;
    this.responseStrategy = responseStrategy;
  }

  public void connect() {
    this.clientConnection.connect(this);
  }

  @Override
  public void onConnectionSuccessful() {
    MessageChannel channel = this.clientConnection.joinChannel(this.channelName);
    MessageDispatcher dispatcher = new RedditMessageDispatcher(channel);
    RedditClient redditClient = new RedditClient(dispatcher);
    MessageListener messageListener = new RedditMessageResponseListener(this.responseStrategy, redditClient);
    channel.registerListener(messageListener);
  }

}
TOP

Related Classes of reddit.bot.RedditBot

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.