Septron Posted July 31, 2013 Share Posted July 31, 2013 Ok, so I ripped this out of a chatter-bot-api and made it easier to use and static... /* chatter-bot-api 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 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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("&"); } s.append(URLEncoder.encode(parameter.getKey(), "UTF-8")); s.append("="); 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(); connection .setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0"); connection.setDoOutput(true); connection.setDoInput(true); OutputStreamWriter osw = new OutputStreamWriter( connection.getOutputStream()); osw.write(parametersToWWWFormURLEncoded(parameters)); osw.flush(); osw.close(); Reader r = new BufferedReader(new InputStreamReader( connection.getInputStream())); StringWriter w = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while ((n = r.read(buffer)) != -1) { w.write(buffer, 0, n); } r.close(); return w.toString(); } public static String md5(String input) throws Exception { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(input.getBytes("UTF-8")); 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. 2 Link to comment Share on other sites More sharing options...
GoldenGates Posted July 31, 2013 Share Posted July 31, 2013 First, and more importantly, sweet release, I'll try this out later today. Link to comment Share on other sites More sharing options...
Ande Posted July 31, 2013 Share Posted July 31, 2013 Nice Link to comment Share on other sites More sharing options...
Joseph Posted July 31, 2013 Share Posted July 31, 2013 Ande don't you have something like this on your bot. I tryed it won't it didn't work out so good. Link to comment Share on other sites More sharing options...
naughtyminingbot Posted July 31, 2013 Share Posted July 31, 2013 (edited) 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 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 2) 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) 3) 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. 4) Someone ask you whether you are botting , Hello you bot? You reply : no Instead of saying no you should have multiple replays' etc: No lol no you stfu 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 Notes problems: 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. http://www.youtube.com/watch?v=_x8KIsnsbgA Edited July 31, 2013 by naughtyminingbot Link to comment Share on other sites More sharing options...
Kenneh Posted August 3, 2013 Share Posted August 3, 2013 This seems funny to play with. Link to comment Share on other sites More sharing options...