MCPcopy Create free account
hub / github.com/Kloping/qqpd-bot-java / At

Class At

src/main/java/io/github/kloping/qqbot/entities/ex/At.java:13–63  ·  view source on GitHub ↗

@author github.kloping

Source from the content-addressed store, hash-verified

11 * @author github.kloping
12 */
13@Data
14public class At implements SendAble {
15 public static final String MEMBER_TYPE = "member";
16 public static final String CHANNEL_TYPE = "channel";
17
18 private String type;
19 private String targetId;
20
21 /**
22 * 参考 <a href="https://bot.q.qq.com/wiki/develop/api-v2/server-inter/message/trans/text-chain.html#%E4%BD%BF%E7%94%A8-%E8%83%BD%E5%8A%9B">官方文档</a>
23 * @param type 成语或子频道
24 * @param targetId 目标
25 * @param old 旧格式
26 */
27 public At(String type, String targetId, boolean old) {
28 this.type = type;
29 this.targetId = targetId;
30 this.old = old;
31 }
32
33 public At(String type, String targetId) {
34 this(type, targetId, false);
35 }
36
37 public At(String targetId) {
38 this(MEMBER_TYPE, targetId);
39 }
40
41
42 private boolean old = false;
43
44 @Override
45 public String toString() {
46 if (CHANNEL_TYPE.equals(type)) {
47 return "<#" + targetId + ">";
48 } else if (MEMBER_TYPE.equals(type)) {
49 return old ? String.format("<@%s>", targetId) : String.format("<qqbot-at-user id=\"%s\" />", targetId);
50 } else return "<@userid>";
51 }
52
53 @Override
54 public Result send(SenderAndCidMidGetter er) {
55 if (er.getEnvType() == EnvType.GUILD) {
56 MessagePacket packet = new MessagePacket();
57 packet.setContent(toString());
58 return er.send(packet);
59 } else {
60 return er.send(toString());
61 }
62 }
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected