Jump to content
Sign in to follow this  

Cleverbot Autoresponder

Recommended Posts

Ok, so I ripped this out of a chatter-bot-api and made it easier to use and static...

Copyright (C) 2011 pierredavidbelanger@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

package me.linus.chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.LinkedHashMap;
import java.util.Map;

public class Cleverbot {

    private static final String url = "http://www.cleverbot.com/webservicemin";

    private static final Map<String, String> vars;

    static {
        vars = new LinkedHashMap<String, String>();
        vars.put("start", "y");
        vars.put("icognoid", "wsf");
        vars.put("fno", "0");
        vars.put("sub", "Say");
        vars.put("islearning", "1");
        vars.put("cleanslate", "false");

    public static String parametersToWWWFormURLEncoded(
            Map<String, String> parameters) throws Exception {
        StringBuilder s = new StringBuilder();
        for (Map.Entry<String, String> parameter : parameters.entrySet()) {
            if (s.length() > 0) {
            s.append(URLEncoder.encode(parameter.getKey(), "UTF-8"));
            s.append(URLEncoder.encode(parameter.getValue(), "UTF-8"));
        return s.toString();

    public static String post(String url, Map<String, String> parameters)
            throws Exception {
        URLConnection connection = new URL(url).openConnection();
                        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
        OutputStreamWriter osw = new OutputStreamWriter(
        Reader r = new BufferedReader(new InputStreamReader(
        StringWriter w = new StringWriter();
        char[] buffer = new char[1024];
        int n = 0;
        while ((n = r.read(buffer)) != -1) {
            w.write(buffer, 0, n);
        return w.toString();

    public static String md5(String input) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BigInteger hash = new BigInteger(1, md5.digest());
        return String.format("%1$032X", hash);

    public static String stringAtIndex(String[] strings, int index) {
        if (index >= strings.length)
            return "";
        return strings[index];

    public static String think(String message) throws Exception {
        vars.put("stimulus", message);
        String formData = parametersToWWWFormURLEncoded(vars);
        String formDataToDigest = formData.substring(9, 29);
        String formDataDigest = md5(formDataToDigest);
        vars.put("icognocheck", formDataDigest);
        String response = post(url, vars);
        String[] responseValues = response.split("\r");
        vars.put("sessionid", stringAtIndex(responseValues, 1));
        vars.put("logurl", stringAtIndex(responseValues, 2));
        vars.put("vText8", stringAtIndex(responseValues, 3));
        vars.put("vText7", stringAtIndex(responseValues, 4));
        vars.put("vText6", stringAtIndex(responseValues, 5));
        vars.put("vText5", stringAtIndex(responseValues, 6));
        vars.put("vText4", stringAtIndex(responseValues, 7));
        vars.put("vText3", stringAtIndex(responseValues, 8));
        vars.put("vText2", stringAtIndex(responseValues, 9));
        vars.put("prevref", stringAtIndex(responseValues, 10));
        vars.put("emotionalhistory", stringAtIndex(responseValues, 12));
        vars.put("ttsLocMP3", stringAtIndex(responseValues, 13));
        vars.put("ttsLocTXT", stringAtIndex(responseValues, 14));
        vars.put("ttsLocTXT3", stringAtIndex(responseValues, 15));
        vars.put("ttsText", stringAtIndex(responseValues, 16));
        vars.put("lineRef", stringAtIndex(responseValues, 17));
        vars.put("lineURL", stringAtIndex(responseValues, 18));
        vars.put("linePOST", stringAtIndex(responseValues, 19));
        vars.put("lineChoices", stringAtIndex(responseValues, 20));
        vars.put("lineChoicesAbbrev", stringAtIndex(responseValues, 21));
        vars.put("typingData", stringAtIndex(responseValues, 22));
        vars.put("divert", stringAtIndex(responseValues, 23));
        return stringAtIndex(responseValues, 16);

Example usage:

package me.linus;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import me.linus.chat.Cleverbot;

public class Chat {

    public static void main(String... a) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Me: ");
        while(true) {
            String console = br.readLine();
            console = Cleverbot.think(console);
            System.out.println("CB: " + console);
            System.out.print("Me: ");

Example output:

Me: Hello
CB: How are you?
Me: Good, you?
CB: I'm doing alright.
Me: That's good to hear!
CB: How are you doing?
Me: Like I just said, I'm doing good
CB: How am I confusing?
Me: I didn't say you were confusing
CB: Yes you did.
Me: No, no I didn't
CB: Yes, you did.
Me: Fuck you
CB: Yes, please.
  • Like 2

Share this post

Link to post
Share on other sites

I was thinking about a auto respond here's what I came up with.



1) Someone asks you your   wc lvl,

 (You will be named player a)



How ever there is someone else using same bot, (This fellow botter we shall name player cool.png


So your clients both respond at same time 


(Looks kinda bottish lol)




So both player a and b, respond at same time.


So a random answering delay would be needed to overcome this bug






Pretty obvious but if some asks you your wc lvl, you can only respond once every certain couple of mins


As people ask you again and your just reply 99 etc

(Looks kinda buggish if they try trick you into saying your level over and over)





Some people will try catch out autoreply's buying mixing up there question example:


hello hows  you today woodcutting im bored level today




(Note how they mix up the woodcutting level question in there statement)



A badly scripted auto respond would reply because it catch's the woodcutting and level text.





Someone ask you whether you are botting ,


Hello you bot?


You reply :  no


Instead of saying no you should have multiple replays' etc:




no you


I don't bot

I hate bots



Because you look more human giving a short human like reply,


Problem is you don't want to being saying no over and over,

so you would have client pick from list and make sure it  picks a  random response ..



I.e  choose from list , answer 1-10










Legit no lifers might still seeing patterns in auto repleys so try keep answer short and sweet.




Again you would need a failsafe to make sure it dosnt keep picking a same reply.














Edited by naughtyminingbot

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...