Skip to content

Commit

Permalink
fix: SimpleContact return null
Browse files Browse the repository at this point in the history
  • Loading branch information
MidCoard committed Mar 24, 2022
1 parent 9dbb45d commit 8abcea3
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>A simple QQ Bot framework</description>
<groupId>top.focess</groupId>
<artifactId>focess-qq</artifactId>
<version>4.0.9.3000</version>
<version>4.0.9.4000</version>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/top/focess/qq/api/bot/OtherClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package top.focess.qq.api.bot;

public interface OtherClient extends Contact{

String getDeviceKind();

int getAppId();

default String getDeviceName() {
return this.getName();
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package top.focess.qq.core.bot.contact;

import net.mamoe.mirai.contact.Friend;
import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.Stranger;
import net.mamoe.mirai.contact.*;
import org.jetbrains.annotations.Nullable;
import top.focess.qq.api.bot.Bot;
import top.focess.qq.api.bot.Contact;
Expand All @@ -29,6 +27,10 @@ public static Contact get(Bot bot, net.mamoe.mirai.contact.Contact contact) {
return SimpleMember.get(bot, (Member) contact);
if (contact instanceof Friend)
return SimpleFriend.get(bot, (Friend) contact);
if (contact instanceof Group)
return SimpleGroup.get(bot, (Group) contact);
if (contact instanceof OtherClient)
return SimpleOtherClient.get(bot, (OtherClient) contact);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public static Friend get(Bot bot, @Nullable net.mamoe.mirai.contact.Friend nativ
return null;
if (bot.getId() != nativeFriend.getBot().getId())
return null;
Map<Long, SimpleFriend> map = FRIEND_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap());
return map.computeIfAbsent(nativeFriend.getId(), k -> new SimpleFriend(bot, nativeFriend));
return FRIEND_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap()).computeIfAbsent(nativeFriend.getId(), k -> new SimpleFriend(bot, nativeFriend));
}

public static void remove(Bot bot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static Group get(Bot bot, @Nullable net.mamoe.mirai.contact.Group group)
return null;
if (bot.getId() != group.getBot().getId())
return null;
Map<Long,SimpleGroup> map = GROUP_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap());
return map.computeIfAbsent(group.getId(), k -> new SimpleGroup(bot, group));
return GROUP_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap()).computeIfAbsent(group.getId(), k -> new SimpleGroup(bot, group));
}

public static void remove(Bot bot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static Member get(Group group, @Nullable net.mamoe.mirai.contact.Member m
return null;
if (group.getBot().getId() != member.getBot().getId())
return null;
Map<Long, SimpleMember> map = GROUP_MEMBER_MAP.computeIfAbsent(group.getBot().getId(), k -> Maps.newConcurrentMap());
return map.computeIfAbsent(member.getId(), k -> new SimpleMember(group, member));
return GROUP_MEMBER_MAP.computeIfAbsent(group.getBot().getId(), k -> Maps.newConcurrentMap()).computeIfAbsent(member.getId(), k -> new SimpleMember(group, member));
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package top.focess.qq.core.bot.contact;

import com.google.common.collect.Maps;
import org.jetbrains.annotations.Nullable;
import top.focess.qq.api.bot.Bot;
import top.focess.qq.api.bot.OtherClient;

import java.util.Map;

public class SimpleOtherClient extends SimpleContact implements OtherClient{


private static final Map<Long, Map<Long,SimpleOtherClient>> OTHER_CLIENT_MAP = Maps.newConcurrentMap();
private final net.mamoe.mirai.contact.OtherClient nativeOtherClient;

public SimpleOtherClient(Bot bot, net.mamoe.mirai.contact.OtherClient contact) {
super(bot, contact);
this.nativeOtherClient = contact;
}

@Override
public String getName() {
return this.nativeOtherClient.getInfo().getDeviceName();
}

@Nullable
public static SimpleOtherClient get(Bot bot, @Nullable net.mamoe.mirai.contact.OtherClient otherClient) {
if (otherClient == null)
return null;
if (otherClient.getBot().getId() != bot.getId())
return null;
return OTHER_CLIENT_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap()).computeIfAbsent(otherClient.getId(), k -> new SimpleOtherClient(bot, otherClient));
}

@Override
public String getDeviceKind() {
return this.nativeOtherClient.getInfo().getDeviceKind();
}

@Override
public int getAppId() {
return this.nativeOtherClient.getInfo().getAppId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static SimpleStranger get(Bot bot, net.mamoe.mirai.contact.Stranger stran
return null;
if (bot.getId() != stranger.getBot().getId())
return null;
Map<Long, SimpleStranger> map = STRANGER_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap());
return map.computeIfAbsent(stranger.getId(), k -> new SimpleStranger(bot, stranger));
return STRANGER_MAP.computeIfAbsent(bot.getId(), k -> Maps.newConcurrentMap()).computeIfAbsent(stranger.getId(), k -> new SimpleStranger(bot, stranger));
}

private SimpleStranger(Bot bot, net.mamoe.mirai.contact.Stranger stranger) {
Expand Down

0 comments on commit 8abcea3

Please sign in to comment.