import java.sql.*;
import java.*;
import rath.msnm.*;
import rath.msnm.MSNMesnger;
import rath.msnm.SwitchboardSession;
import rath.msnm.UrStatus;
import ity.Group;
import ity.MsnFriend;
import rath.msnm.event.MsnAdapter;
import rath.msnm.msg.MimeMessage;
import java.util.*;
le.soap.arch.*;
le.soap.arch.GoogleSearch;
le.soap.arch.GoogleSearchResult;
import java.io.*;
/
**
* MSN消息事件处理类
* @author 瞄瞄,wensi
*/
public class MSNAdapter
extends MsnAdapter {
MsnIn msnin = new MsnIn();
static String archcon;
static String firstfriend;
static String friendlist;
String rewa = "";
String msg3;
MSNMesnger mesnger;
String url = "jdbc:odbc:chat"; ////数据源
String login = ""; //用户名
String password = ""; //密码
Connection connection = null; // 声明Connection接口对象connection
ResultSet rSet = null; // 定义数据库查询的结果集
ResultSet keySet = null;
Statement statement = null; // 定义查询数据库的Statement对象
public MSNAdapter(MSNMesnger mesnger) {
snger = mesnger;
}
public void msnmsg(String msg) {
msg3 = msg;
Area2.append(msg3 + "\n");
}
/**
* 某人正在输入信息
*/
public void progressTyping(
SwitchboardSession ss,
MsnFriend friend,
String typingUr) {
System.out.LoginName() + "正在输入信息...");
}
/**
* 收到消息的时候执行该方法
*/
public void instantMessageReceived(
SwitchboardSession ss,
MsnFriend friend,
MimeMessage mime) {
System.out.print("接收到消息:" + FriendlyName() + "->");
System.out.Message());
FriendlyName() + "说:" + Message());
int first = 0;
if (firstfriend != null) {
StringTokenizer stt = new StringTokenizer(firstfriend, "$");
傲娇的意思 String[] subStrt2 = new untTokens()];
int a = 0;
for (int i = 0; i < subStrt2.length; i++) {
subStrt2[i] = Token();
if (subStrt2[i].LoginName())) {
a = 1;
break;
}
}
if (a == 0) {
firstfriend = firstfriend + "$" + LoginName();
first = 1;
try {
mime.tMessage("|0_0| 我是机器人瞄,如果想问我问题请尽管问\r\n(co) 如果你想告诉我些知识请按照: study,问题内容,答案内容 的格式告诉我\r\n(I) 如果想使用google搜索请输入: google,搜索内容\r\n:-D 帮助请输入: help或?\r\n(M) 想和我的开发人员说话请加:,wensi_");
mesnger.LoginName(), mime);
msnmsg("#机器人回答:" + FriendlyName() + ",内容:帮助");
}
catch (IOException ex1) {}
}
}
el {
firstfriend = firstfriend + "$" + LoginName();
first = 1;
try {
mime.tMessage("|0_0| 我是机器人瞄,如果想问我问题请尽管问\r\n(co) 如果你想告诉我些知识请按照: study,问题内容,答案内容 的格式告诉我\r\n(I) 如果想使用google搜索请输入: google,搜索内容\r\n:-D 帮助请输入: help或?\r\n(M) 想和我的开发人员说话请加:,wensi_");
mesnger.LoginName(), mime);
msnmsg("#机器人回答:" + FriendlyName() + ",内容:帮助");
}
catch (IOException ex1) {}
}
if (first == 0) { //对话开始
if (Message().equals("help") || Message().equals("帮助") ||
Message().equals("?")) { //是否帮助
mime.tMessage("|0_0| 我是机器人瞄,如果想问我问题请尽管问\r\n(co) 如果你想告诉我些知识请按照: study,问题内容,答案内容 的格式告诉我\r\n(I) 如果想使用google搜索请输入: google,搜索内容\r\n:-D 帮助请输入: help或?\r\n(M) 想和我的开发人员说话请加:,wensi_");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:帮助");
}
el { //是否帮助
if (Message().indexOf(",") > 0) { //判断模式开始
StringTokenizer ms = new Message(), ",");
int mspart;
mspart = ms.countTokens();
String[] message = new untTokens()];
for (int i = 0; i < message.length; i++) {
message[i] = ms.nextToken();
}
if ( (mspart == 3) && (message[0].equals("学习")) ||
(message[0].equals("study")) || (message[0].equals("STUDY"))) { //学习模式
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = Connection(url);
statement = ateStatement();
String sql1 =
"inrt into holophra (question,answer) values ('" +
message[1] +
"','" + message[2] + "')";
uteUpdate(sql1);
mime.tMessage("学习完毕,在问问我啊。帮助请输入:? 或 help");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:学习完毕");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
el if ( (mspart == 2) && (message[0].equals("google")) ||
(message[0].equals("GOOGLE"))) { //学习模式结束google搜索模式
String titleall = "";
if (archcon != null) {
String archcon2 = archcon;
archcon = "";
StringTokenizer stt = new StringTokenizer(archcon2, "$");
String[] subStrt2 = new untTokens()];
int a = 0;
int b = 0;
for (int i = 0; i < subStrt2.length; i++) {
subStrt2[i] = Token();
b++;
if (subStrt2[i].LoginName())) {
a = 1;
break;
}
}
if (a == 0) {
archcon2 = archcon2 + "$" + LoginName() + "$" +
message[1];
archcon = archcon2;
}
el {
subStrt2[b + 1] = message[1];
for (int i = 0; i < subStrt2.length; i++) {
archcon = archcon + "$" + subStrt2[i];
}
}
}
el {
archcon = archcon + "$" + LoginName() + "$" +
message[1];
}
try {
GoogleSearch arch = new GoogleSearch();
arch.tKey("AhGBLehQFHICcFbB5lYF9lDTZ4G71AzH");
arch.tQueryString(message[1]);
GoogleSearchResult result = arch.doSearch();
int numResults = EstimatedTotalResultsCount();
int numResults2 = numResults / 10;
GoogleSearchResultElement[] resultElements = result.
getResultElements();
int startIndex = StartIndex() - 1;
int endIndex = EndIndex() - 1;
for (int i = startIndex; i <= endIndex; i++) {
GoogleSearchResultElement resultElement = resultElements[ (i)];
String title = Title();
英语指示代词 StringTokenizer st2 = new StringTokenizer(title, "<b>");
String[] subStr2 = new untTokens()];
String title2 = "";
for (int i2 = 0; i2 < subStr2.length; i2++) {
subStr2[i2] = Token();
title2 = title2 + subStr2[i2];
}
StringTokenizer st3 = new StringTokenizer(title2, "</b>");
String[] subStr3 = new untTokens()];
String title3 = "";
郭峰移情别恋 for (int i3 = 0; i3 < subStr3.length; i3++) {
subStr3[i3] = Token();
title3 = title3 + subStr3[i3];
}
String url = URL();
titleall = titleall + title3 + "\r\n" + url + "\r\n";
System.out.println(title);
System.out.println(url);
}
if (startIndex == 0) {
mime.tMessage(titleall + "\r\n搜索结果共" + numResults2 +
"页\r\n当前页:0\r\n看其他纪录输入:go->页数");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索成功");
}
el {
mime.tMessage(titleall + "\r\n搜索结果共" + numResults2 +
"页\r\n当前页:0\r\n看其他页纪录输入:go->页数;看第一页纪录输入:go->0");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索成功");
}
}
catch (Exception gsf) {
mime.tMessage("Google Search Fault: " + gsf); //.getMessage());
System.out.println("Google Search Fault: " + gsf); //.getMessage());
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索失败");
}
}
el { //google搜索模式结束数据库查询开始
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = Connection(url);
statement = ateStatement();
String sqlStr1 =
"SELECT question,answer FROM holophra WHERE question like '%" +
Message() + "%'";
rSet = uteQuery(sqlStr1);
if (() == fal) { //分词开始
int br = 0; //比较有结果为1
String key = Message();
for (int i = key.length(); i > 1; i--) {
if (br == 1) {
break;
}
for (int num = 0; num + i <= key.length(); num++) {
if (br == 1) {
break;
}
String subS = key.substring(num, num + i);
String sqlKey = "lect * from pivotal order by pivotalid";
rSet = uteQuery(sqlKey);
while (()) {
if (br == 1) {
break;
}
String pivotal = String("pivotal");
StringTokenizer pivotal1 = new StringTokenizer(pivotal,
"/");
String[] pivotal2 = new untTokens()];
for (int i3 = 0; i3 < pivotal2.length; i3++) {
pivotal2[i3] = Token();
if (pivotal2[i3].equals(subS)) {
String p = String("content");
System.out.println("分词选择:" + p + "\n");
mime.tMessage(p);
msnmsg("#机器人回答:" + FriendlyName() + ",内容:" +
p);
br = 1;
break;
}
}
}
}
}
if (br == 0) { //如果比较没结果
int count = (int) (Math.random() * 78);
String sqlStr2 = "SELECT * FROM cope WHERE copeid =" + count +
"";
ResultSet rs = uteQuery(sqlStr2);
rs.next();
String returnInfo1 = rs.getString(2);
mime.tMessage(returnInfo1 + "\r\n" +
"[如果你想告诉我正确的答案,请按照 study,问题,答案 的格式教我!-_-!]");
System.out.print(returnInfo1 + "\n");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:" +
returnInfo1);
}
statement.clo();
connection.clo();
} //分词结束
el {
String s = "";
String s2 = String(2);
int a = 0;
while (()) {
s = s + "$" + String(2);
a++;
}
if (a != 0) {
StringTokenizer stt = new StringTokenizer(s, "$");
String[] subStrt2 = new untTokens()];
for (int i = 0; i < subStrt2.length; i++) {
subStrt2[i] = Token();
}
int count;
count = (int) (Math.random() * a);
s = subStrt2[count];
}
el {
s = s2;
}
String returnInfo2 = "";
if (s.indexOf("$n") > 0) { //换行
StringTokenizer st = new StringTokenizer(s,
"$n");
String[] subStr = new untTokens()];
铃声歌曲
for (int i = 0; i < subStr.length; i++) {
subStr[i] = st.nextToken();
returnInfo2 = returnInfo2 + subStr[i] + "\r\n";
}
mime.tMessage(returnInfo2);
System.out.print(returnInfo2 + "\n");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:" +
returnInfo2);
}
el {
mime.tMessage(s);
System.out.print(s + "\n");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:" + s);
}
statement.clo();
connection.clo();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
el if (Message().indexOf("->") >= 0) { //判断模式结束 google搜索换页开始
String titleall = "";
StringTokenizer st2 = new StringTokenizer(archcon, "$");
String[] subStr2 = new untTokens()];
for (int i = 0; i < subStr2.length; i++) {
subStr2[i] = Token();
}
int a = 0;
while (!subStr2[a].LoginName())) {
每一个梦 a++;
}
StringTokenizer stk = new Message(), "->");
String[] subStrk = new untTokens()];
for (int i = 0; i < subStrk.length; i++) {
subStrk[i] = Token();
}
try {
GoogleSearch arch = new GoogleSearch();
arch.tKey("AhGBLehQFHICcFbB5lYF9lDTZ4G71AzH");
arch.tQueryString(subStr2[a + 1]);
int aa = Integer.parInt(subStrk[1]);
if (aa * 10 < 0) {
mime.tMessage("错误,无法翻页");
芦字组词 msnmsg("#机器人回答:" + FriendlyName() + ",内容:翻页错误");
}
el {
int startResult = aa * 10;
arch.tStartResult(startResult);
int maxResult = 10;
arch.tMaxResults(maxResult);
GoogleSearchResult result = arch.doSearch();
int numResults = EstimatedTotalResultsCount();
int numResults2 = numResults / 10;
GoogleSearchResultElement[] resultElements = result.
getResultElements();
int startIndex = StartIndex() - 1 - startResult;
int endIndex = EndIndex() - 1 - startResult;
for (int i = startIndex; i <= endIndex; i++) {
GoogleSearchResultElement resultElement = resultElements[ (i)];
String title = Title();
StringTokenizer st3 = new StringTokenizer(title, "<b>");
String[] subStr3 = new untTokens()];
String title2 = "";
for (int i2 = 0; i2 < subStr3.length; i2++) {
subStr3[i2] = Token();
title2 = title2 + subStr3[i2];
}
StringTokenizer st4 = new StringTokenizer(title2, "</b>");
String[] subStr4 = new untTokens()];
String title3 = "";
for (int i3 = 0; i3 < subStr4.length; i3++) {
subStr4[i3] = Token();
title3 = title3 + subStr4[i3];
}
String url = URL();
titleall = titleall + title3 + "\r\n" + url + "\r\n";
System.out.println(title);
System.out.println(url);
}
if (startResult == 0) {
mime.tMessage(titleall + "\r\n搜索结果共" + numResults2 +
"页\r\n当前页:" + aa + "\r\n看其他纪录输入:go->页数");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索成功");
}
七年级古诗大全 el {
mime.tMessage(titleall + "\r\n搜索结果共" + numResults2 +
"页\r\n当前页:" + aa +
"\r\n看其他页纪录输入:go->页数;看第一页纪录输入:go->0");
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索成功");
}
}
}
catch (Exception gsf) {
mime.tMessage("Google Search Fault: " + gsf); //.getMessage());
System.out.println("Google Search Fault: " + gsf); //.getMessage());
msnmsg("#机器人回答:" + FriendlyName() + ",内容:google搜索失败");
}
}
el { //google搜索换页结束
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = Connection(url);
statement = ateStatement();
String sqlStr1 =
"SELECT question,answer FROM holophra WHERE question like '%" +
Message() + "%'";
rSet = uteQuery(sqlStr1);
if (() == fal) { //分词开始
int br = 0; //比较有结果为1
String key = Message();
for (int i = key.length(); i > 1; i--) {
if (br == 1) {
break;
}
for (int num = 0; num + i <= key.length(); num++) {
if (br == 1) {
break;
}
String subS = key.substring(num, num + i);
等待黎明 String sqlKey = "lect * from pivotal order by pivotalid";
rSet = uteQuery(sqlKey);
while (()) {
if (br == 1) {
break;
}
String pivotal = String("pivotal");