Skip to content

Commit

Permalink
update smartqq
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed Jul 4, 2017
1 parent 59d44b2 commit 4b15109
Show file tree
Hide file tree
Showing 14 changed files with 637 additions and 674 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## SmartQQ4Eclipse
Eclipse上的SmartQQ插件,防Boss利器,让你可以在eclipse中使用QQ进行聊天
Intellij IDEA上的插件请稳步这里: https://github.com/Jamling/SmartQQ4Intellij

## 功能
- 收发文本消息
Expand Down
2 changes: 1 addition & 1 deletion cn.ieclipse.smartqq.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="cn.ieclipse.smartqq.feature"
label="SmartQQ Feature"
version="1.0.2"
version="1.0.3"
provider-name="ieclipse.cn"
plugin="cn.ieclipse.smartqq">

Expand Down
2 changes: 1 addition & 1 deletion cn.ieclipse.smartqq/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<classpathentry kind="src" path="test"/>
<classpathentry combineaccessrules="false" kind="src" path="/smartqq"/>
<classpathentry kind="lib" path="libs/fastjson-1.2.7.jar" sourcepath="C:/Users/Jamling/.m2/repository/com/alibaba/fastjson/1.2.7/fastjson-1.2.7-sources.jar"/>
<classpathentry kind="lib" path="libs/requests-2.1.5.jar"/>
<classpathentry kind="lib" path="libs/requests-2.1.5.jar" sourcepath="C:/Users/Jamling/.m2/repository/net/dongliu/requests/2.1.5/requests-2.1.5-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion cn.ieclipse.smartqq/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SmartQQ
Bundle-SymbolicName: cn.ieclipse.smartqq;singleton:=true
Bundle-Version: 1.0.2
Bundle-Version: 1.0.3
Bundle-Activator: cn.ieclipse.smartqq.QQPlugin
Bundle-Vendor: ieclipse.cn
Require-Bundle: org.eclipse.ui,
Expand Down
Binary file modified cn.ieclipse.smartqq/libs/smartqq.jar
Binary file not shown.
76 changes: 36 additions & 40 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartqq/QQPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.scienjus.smartqq.callback.LoginCallback;
import com.scienjus.smartqq.callback.MessageCallback2;
import com.scienjus.smartqq.client.SmartClient;
import com.scienjus.smartqq.model.DefaultMessage;
import com.scienjus.smartqq.model.Discuss;
import com.scienjus.smartqq.model.DiscussFrom;
import com.scienjus.smartqq.model.DiscussMessage;
Expand All @@ -24,6 +25,7 @@
import com.scienjus.smartqq.model.GroupFrom;
import com.scienjus.smartqq.model.GroupMessage;
import com.scienjus.smartqq.model.Message;
import com.scienjus.smartqq.model.MessageFrom;
import com.scienjus.smartqq.model.Recent;

import cn.ieclipse.smartqq.console.ChatConsole;
Expand Down Expand Up @@ -96,7 +98,7 @@ public static ImageDescriptor getImageDescriptor(String path) {
private SmartClient client;

public SmartClient getClient() {
if (client == null) {
if (client == null || client.isClose()) {
client = new SmartClient();
}
return client;
Expand All @@ -113,54 +115,29 @@ public void login(LoginCallback callback) {
public void start() {
MessageCallback2 callback = new MessageCallback2() {

private ChatConsole lastConsole;
@Override
public void onMessage(final Message message,
final FriendFrom from) {
public void onReceiveMessage(DefaultMessage message,
MessageFrom from) {
ChatConsole console = QQPlugin.getDefault()
.findConsole(from.getFriend(), false);
Recent r = getClient().getRecent(0, message.getUserId());

if (console != null) {
console.write(String.format("%s %s: %s",
new SimpleDateFormat("HH:mm:ss")
.format(message.getTime()),
from.getName(), message.getContent()));
}
Robot.answer(from, message, console);
}

@Override
public void onGroupMessage(final GroupMessage message,
final GroupFrom from) {
Group g = getClient().getGroup(message.getGroupId());
String name = from.getName();

ChatConsole console = QQPlugin.getDefault().findConsole(g,
false);
.findConsole(from.getFrom(), false);
if (console != null) {
console.write(String.format("%s %s: %s",
new SimpleDateFormat("HH:mm:ss")
.format(message.getTime()),
name, message.getContent()));
String time = new SimpleDateFormat("HH:mm:ss")
.format(message.getTime());
String name = from.getName();
String msg = String.format("%s %s: %s", time, name,
message.getContent());
console.write(msg);
lastConsole = console;
}
Robot.answer(from, message, console);
}

@Override
public void onDiscussMessage(final DiscussMessage message,
final DiscussFrom from) {
Discuss g = getClient().getDiscuss(message.getDiscussId());
String name = from.getName();

ChatConsole console = QQPlugin.getDefault().findConsole(g,
false);
if (console != null) {
console.write(String.format("%s %s: %s",
new SimpleDateFormat("HH:mm:ss")
.format(message.getTime()),
name, message.getContent()));
public void onReceiveError(Throwable e) {
if (lastConsole != null){
lastConsole.error(e);
}
Robot.answer(from, message, console);
}
};
getClient().setCallback(callback);
Expand All @@ -173,6 +150,25 @@ public ContactView getContactView() {
return (ContactView) view;
}

public ChatConsole getChatConsole(boolean show) {
IConsoleManager manager = ConsolePlugin.getDefault()
.getConsoleManager();

IConsole[] existing = manager.getConsoles();

ChatConsole console = null;
for (int i = 0; i < existing.length; i++) {
if (existing[i] instanceof ChatConsole) {
console = (ChatConsole) existing[i];
break;
}
}
if (console != null && show) {
manager.showConsoleView(console);
}
return console;
}

public ChatConsole findConsole(Object obj, boolean add) {
IConsoleManager manager = ConsolePlugin.getDefault()
.getConsoleManager();
Expand Down
139 changes: 60 additions & 79 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartqq/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import org.eclipse.jface.preference.IPreferenceStore;

import com.alibaba.fastjson.JSONObject;
import com.scienjus.smartqq.model.DefaultMessage;
import com.scienjus.smartqq.model.DiscussFrom;
import com.scienjus.smartqq.model.DiscussInfo;
import com.scienjus.smartqq.model.DiscussMessage;
import com.scienjus.smartqq.model.DiscussUser;
import com.scienjus.smartqq.model.FriendFrom;
import com.scienjus.smartqq.model.Group;
import com.scienjus.smartqq.model.GroupFrom;
import com.scienjus.smartqq.model.GroupInfo;
import com.scienjus.smartqq.model.GroupMessage;
import com.scienjus.smartqq.model.GroupUser;
import com.scienjus.smartqq.model.Message;
import com.scienjus.smartqq.model.MessageFrom;
import com.scienjus.smartqq.model.UserInfo;

import cn.ieclipse.smartqq.console.ChatConsole;
Expand All @@ -29,48 +31,47 @@ public static boolean isEnable() {
return (store.getBoolean(RobotPreferencePage.ROBOT_ENABLE));
}

public static boolean atMe(GroupMessage m) {
if (m.at != null && !m.at.isEmpty()) {
try {
Group g = QQPlugin.getDefault().getClient()
.getGroup(m.getGroupId());
GroupInfo info = QQPlugin.getDefault().getClient()
.getGroupInfo(g);
public static boolean atMe(MessageFrom from, DefaultMessage m) {
if (m.getAts() != null) {
if (m instanceof GroupMessage) {
GroupInfo info = ((GroupFrom) from).getGroup();
UserInfo me = QQPlugin.getDefault().getClient()
.getAccountInfo();
if (info != null && me != null) {
long uin = Long.parseLong(me.getUin());
GroupUser me2 = info.getGroupUser(uin);
if (me2 != null) {
if (m.at.equals("@" + me2.getName())) {
return true;
}
}
long uin = Long.parseLong(me.getUin());
GroupUser me2 = info.getGroupUser(uin);
if (m.hasAt(me2.getName()) || m.hasAt(me.getNick())) {
return true;
}

else if (me != null) {
if (m.at.equals("@" + me.getNick())) {
return true;
}
}

else if (m instanceof DiscussMessage) {
DiscussInfo info = ((DiscussFrom) from).getDiscuss();
UserInfo me = QQPlugin.getDefault().getClient()
.getAccountInfo();
long uin = Long.parseLong(me.getUin());
DiscussUser me2 = info.getDiscussUser(uin);
if (m.hasAt(me2.getName()) || m.hasAt(me.getNick())) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}

public static void answer(FriendFrom from, Message m, ChatConsole console) {
public static void answer(MessageFrom from, DefaultMessage m,
ChatConsole console) {
if (!isEnable()) {
return;
}

IPreferenceStore store = QQPlugin.getDefault().getPreferenceStore();
if (store.getBoolean(RobotPreferencePage.FRIEND_REPLY_ANY)) {
String robotName = store.getString(RobotPreferencePage.ROBOT_NAME);
// auto reply friend
if (from instanceof FriendFrom
&& store.getBoolean(RobotPreferencePage.FRIEND_REPLY_ANY)) {
String reply = getTuringReply(String.valueOf(m.getUserId()),
m.getContent());
if (reply != null) {
String robotName = store
.getString(RobotPreferencePage.ROBOT_NAME);
String input = robotName + reply;
if (console == null) {
QQPlugin.getDefault().getClient()
Expand All @@ -81,25 +82,14 @@ public static void answer(FriendFrom from, Message m, ChatConsole console) {
}
}
}
}

public static void answer(GroupFrom from, GroupMessage m,
ChatConsole console) {
if (!isEnable()) {
return;
}

IPreferenceStore store = QQPlugin.getDefault().getPreferenceStore();
String robotName = store.getString(RobotPreferencePage.ROBOT_NAME);
if (from.isNewbie()) {
// newbie
if (from.isNewbie() && from instanceof GroupFrom) {
GroupFrom gf = (GroupFrom) from;
String welcome = store.getString(RobotPreferencePage.GROUP_WELCOME);
if (welcome != null && !welcome.isEmpty()) {
Group g = QQPlugin.getDefault().getClient()
.getGroup(m.getGroupId());
GroupInfo info = QQPlugin.getDefault().getClient()
.getGroupInfo(g);
GroupUser gu = QQPlugin.getDefault().getClient()
.getGroupUser(m);
GroupInfo info = gf.getGroup();
GroupUser gu = gf.getGroupUser();
String input = welcome;
if (gu != null) {
input = input.replaceAll("{user}", gu.getName());
Expand All @@ -112,65 +102,56 @@ public static void answer(GroupFrom from, GroupMessage m,
}
else {
QQPlugin.getDefault().getClient().sendMessageToGroup(
m.getGroupId(), robotName + input);
gf.getGroup().getGid(), robotName + input);
}
}
return;
}
if (atMe(m)) {
String msg = m.getContent().replace(m.at, "");
// @
if (atMe(from, m)) {
String msg = m.getContent(true);
String reply = getTuringReply(String.valueOf(m.getUserId()), msg);
if (reply != null) {
String input = robotName + "@" + from.getName() + SEP + reply;
if (console != null) {
console.post(input);
}
else {
QQPlugin.getDefault().getClient()
.sendMessageToGroup(m.getGroupId(), input);
if (m instanceof GroupMessage) {
QQPlugin.getDefault().getClient().sendMessageToGroup(
((GroupMessage) m).getGroupId(), input);
}
else if (m instanceof DiscussMessage) {
QQPlugin.getDefault().getClient().sendMessageToDiscuss(
((DiscussMessage) m).getDiscussId(), input);
}
}
}
return;
}
// replay any
if (store.getBoolean(RobotPreferencePage.GROUP_REPLY_ANY)) {
if (from.isNewbie() || from.isUnknow() || isMySend(m.getUserId())) {
if (from.isNewbie() || isMySend(m.getUserId())) {
return;
}
if (console == null) {
return;
}
String reply = getTuringReply(String.valueOf(m.getUserId()),
m.getContent());
if (reply != null) {
String input = robotName + "@" + from.getName() + SEP + reply;
if (console != null) {
console.post(input);
}
}
}
}

public static void answer(DiscussFrom from, DiscussMessage m,
ChatConsole console) {
if (!isEnable()) {
return;
}

IPreferenceStore store = QQPlugin.getDefault().getPreferenceStore();
String robotName = store.getString(RobotPreferencePage.ROBOT_NAME);
// if (atMe(m)) {
// String msg = m.getContent().replace(m.at, "");
// reply(store, console, String.valueOf(m.getUserId()), msg,
// robotName + "@" + from.getName());
// return;
// }
if (store.getBoolean(RobotPreferencePage.GROUP_REPLY_ANY)) {
if (from.isNewbie() || from.isUnknow() || isMySend(m.getUserId())) {

if (from instanceof FriendFrom) {
return;
}
if (console == null) {
return;
else if (from instanceof GroupFrom) {
if (((GroupFrom) from).getGroupUser().isUnknown()) {
return;
}
}
else if (from instanceof DiscussFrom) {
if (((DiscussFrom) from).getDiscussUser().isUnknown()) {
return;
}
}

String reply = getTuringReply(String.valueOf(m.getUserId()),
m.getContent());
if (reply != null) {
Expand Down
7 changes: 0 additions & 7 deletions cn.ieclipse.smartqq/src/cn/ieclipse/smartqq/SWTQQClient.java

This file was deleted.

Loading

0 comments on commit 4b15109

Please sign in to comment.