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);
}
}