Skip to content

Instantly share code, notes, and snippets.

@jan-krueger
Last active August 29, 2015 13:58
Show Gist options
  • Save jan-krueger/10019679 to your computer and use it in GitHub Desktop.
Save jan-krueger/10019679 to your computer and use it in GitHub Desktop.
package <your-package>;
import java.util.HashMap;
import org.bukkit.entity.Player;
import com.google.code.chatterbotapi.ChatterBot;
import com.google.code.chatterbotapi.ChatterBotFactory;
import com.google.code.chatterbotapi.ChatterBotSession;
import com.google.code.chatterbotapi.ChatterBotType;
public class ChatterBotManager {
private ChatterBotFactory factory;
private HashMap<String, ChatterBotSession> players;
public ChatterBotManager() {
this.factory = new ChatterBotFactory();
this.players = new HashMap<String, ChatterBotSession>();
}
public boolean addPlayer(Player player, ChatterBotType type, boolean force) {
try {
if(players.containsKey(player.getName()) && !(force)) {
return true;
}
players.put(player.getName(), createBot(type).createSession());
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean contains(Player player) {
return players.containsKey(player.getName());
}
public String getMessage(Player player, String message) {
try {
return players.get(player.getName()).think(message);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private ChatterBot createBot(ChatterBotType type) throws Exception {
return factory.create(type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment