-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/top/focess/qq/core/bot/contact/SimpleOtherClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters