From ecc1f17ae922af3da5204a45ae4f4b77aa764621 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Mon, 20 Apr 2020 13:14:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forte/qqrobot/intercept/BaseContext.java | 10 +++++ .../com/forte/qqrobot/intercept/Context.java | 10 +++++ .../forte/qqrobot/listener/ListenContext.java | 39 +++++-------------- .../com/forte/qqrobot/utils/CQCodeUtil.java | 17 -------- update.md | 1 + 5 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/forte/qqrobot/intercept/BaseContext.java b/src/main/java/com/forte/qqrobot/intercept/BaseContext.java index 1e780c1..a3ebb0f 100644 --- a/src/main/java/com/forte/qqrobot/intercept/BaseContext.java +++ b/src/main/java/com/forte/qqrobot/intercept/BaseContext.java @@ -106,5 +106,15 @@ public BaseContext(T value, Map globalContextMap){ this.value = value; this.globalContextMap = globalContextMap; } + /** + * 构造 + * @param value 上下文所对应的值 + * @param globalContextMap 全局上下文值。 + * */ + public BaseContext(T value, Map globalContextMap, Map contextMap){ + this.value = value; + this.globalContextMap = globalContextMap; + this.contextMap = contextMap; + } } diff --git a/src/main/java/com/forte/qqrobot/intercept/Context.java b/src/main/java/com/forte/qqrobot/intercept/Context.java index 223b8e9..a3f566f 100644 --- a/src/main/java/com/forte/qqrobot/intercept/Context.java +++ b/src/main/java/com/forte/qqrobot/intercept/Context.java @@ -19,6 +19,16 @@ public interface Context { */ Object get(String key); + /** + * 含义与{@link #set(String, Object)}相同。 + * @param key + * @param value + * @return + */ + default Object put(String key, Object value){ + return set(key, value); + } + /** * 记录一个当前上下文参数 * @param key key diff --git a/src/main/java/com/forte/qqrobot/listener/ListenContext.java b/src/main/java/com/forte/qqrobot/listener/ListenContext.java index 4118df4..608cdd4 100644 --- a/src/main/java/com/forte/qqrobot/listener/ListenContext.java +++ b/src/main/java/com/forte/qqrobot/listener/ListenContext.java @@ -16,18 +16,18 @@ public class ListenContext extends BaseContext { - /** - * 单次生效的Map, 使用懒加载,当前域 - */ - private Map normalMap; +// /** +// * 单次生效的Map, 使用懒加载,当前域 +// */ +// private Map normalMap; public ListenContext(Map globalContext) { super(null, globalContext); } + public ListenContext(Map globalContext, Map normalMap) { - super(null, globalContext); - this.normalMap = normalMap; + super(null, globalContext, normalMap); } /** @@ -48,10 +48,7 @@ public static ListenContext getInstance(Map globalContext, Map getNormalMap() { - if (normalMap == null) { - normalMap = new HashMap<>(4); - } - return normalMap; + return getContextMap(); } /** @@ -70,7 +67,7 @@ private Map getNormalMap() { */ @Override public Object get(String key) { - Object normalGet = getNormalMap().get(key); + Object normalGet = getContextMap().get(key); return normalGet == null ? getGlobal(key) : normalGet; } @@ -117,24 +114,6 @@ public Object setNormal(String key, Object value) { return set(key, value); } -// /** -// * 记录一个全局域值 -// * @param key 键 -// * @param value 值 -// */ -// @Override -// public Object setGlobal(String key, Object value) { -// return globalContext.put(key, value); -// } - - -// /** -// * 清除域。默认为清除当前域 -// */ -// @Override -// public void clear() { -// getNormalMap().clear(); -// } /** * 仅清除全局域 @@ -147,7 +126,7 @@ public void clearGlobal() { * 当前域keySet */ public Set normalKeySet() { - return getNormalMap().keySet(); + return getContextMap().keySet(); } /** diff --git a/src/main/java/com/forte/qqrobot/utils/CQCodeUtil.java b/src/main/java/com/forte/qqrobot/utils/CQCodeUtil.java index d2ab1bb..d0e7add 100644 --- a/src/main/java/com/forte/qqrobot/utils/CQCodeUtil.java +++ b/src/main/java/com/forte/qqrobot/utils/CQCodeUtil.java @@ -205,7 +205,6 @@ public CQCode getCQCode(CQCodeTypes type, String... params) { * @see #getCQCode_Face(String) * @deprecated */ - @Deprecated public String getCQCode_face(String id) { return getCQCodeString(CQCodeTypes.face, id); } @@ -228,7 +227,6 @@ public CQCode getCQCode_Face(String id) { * @see #getCQCode_Bface(String) * @deprecated */ - @Deprecated public String getCQCode_bface(String id) { return getCQCodeString(CQCodeTypes.bface, id); } @@ -251,7 +249,6 @@ public CQCode getCQCode_Bface(String id) { * @see #getCQCode_Sface(String) * @deprecated */ - @Deprecated public String getCQCode_sface(String id) { return getCQCodeString(CQCodeTypes.sface, id); } @@ -274,7 +271,6 @@ public CQCode getCQCode_Sface(String id) { * @see #getCQCode_Image(String) * @deprecated */ - @Deprecated public String getCQCode_image(String file) { return getCQCodeString(CQCodeTypes.image, file); } @@ -299,7 +295,6 @@ public CQCode getCQCode_Image(String file) { * @see #getCQCode_Record(String, Boolean) * @deprecated */ - @Deprecated public String getCQCode_record(String file, Boolean magic) { return getCQCodeString(CQCodeTypes.record, file, Optional.ofNullable(magic).map(Object::toString).orElse(null)); } @@ -323,7 +318,6 @@ public CQCode getCQCode_Record(String file, Boolean magic) { * @see #getCQCode_Record(String) * @deprecated */ - @Deprecated public String getCQCode_record(String file) { return getCQCodeString(CQCodeTypes.record, file, null); } @@ -347,7 +341,6 @@ public CQCode getCQCode_Record(String file) { * @see #getCQCode_At(String) * @deprecated */ - @Deprecated public String getCQCode_at(String qq) { return getCQCodeString(CQCodeTypes.at, qq); } @@ -369,7 +362,6 @@ public CQCode getCQCode_At(String qq) { * @see #getCQCode_At(String) * @deprecated */ - @Deprecated public String getCQCode_atAll() { return getCQCodeString(CQCodeTypes.at, "all"); } @@ -392,7 +384,6 @@ public CQCode getCQCode_AtAll() { * @see #getCQCode_Rps(String) * @deprecated */ - @Deprecated public String getCQCode_rps(String type) { return getCQCodeString(CQCodeTypes.rps, type); } @@ -415,7 +406,6 @@ public CQCode getCQCode_Rps(String type) { * @see #getCQCode_Dice(String) * @deprecated */ - @Deprecated public String getCQCode_dice(String type) { return getCQCodeString(CQCodeTypes.dice, type); } @@ -437,7 +427,6 @@ public CQCode getCQCode_Dice(String type) { * @see #getCQCode_Shake() * @deprecated */ - @Deprecated public String getCQCode_shake() { return getCQCodeString(CQCodeTypes.shake); } @@ -461,7 +450,6 @@ public CQCode getCQCode_Shake() { * @see #getCQCode_Anonymous(Boolean) * @deprecated */ - @Deprecated public String getCQCode_anonymous(Boolean ignore) { return getCQCodeString(CQCodeTypes.anonymous, Optional.ofNullable(ignore).map(Object::toString).orElse(null)); } @@ -487,7 +475,6 @@ public CQCode getCQCode_Anonymous(Boolean ignore) { * @see #getCQCode_Anonymous() * @deprecated */ - @Deprecated public String getCQCode_anonymous() { return getCQCodeString(CQCodeTypes.anonymous, (String) null); } @@ -514,7 +501,6 @@ public CQCode getCQCode_Anonymous() { * @see #getCQCode_Music(String, String) * @deprecated */ - @Deprecated public String getCQCode_music(String type, String id) { return getCQCodeString(CQCodeTypes.music, type, id); } @@ -543,7 +529,6 @@ public CQCode getCQCode_Music(String type, String id) { * @see #getCQCode_Music_Custom(String, String, String, String, String) * @deprecated */ - @Deprecated public String getCQCode_music_custom(String url, String audio, String title, String content, String image) { return getCQCodeString(CQCodeTypes.music_custom, "custom", url, audio, title, content, image); } @@ -574,7 +559,6 @@ public CQCode getCQCode_Music_Custom(String url, String audio, String title, Str * @see #getCQCode_Share(String, String, String, String) * @deprecated */ - @Deprecated public String getCQCode_share(String url, String title, String content, String image) { return getCQCodeString(CQCodeTypes.share, url, title, content, image); } @@ -601,7 +585,6 @@ public CQCode getCQCode_Share(String url, String title, String content, String i * @see #getCQCode_Emoji(String) * @deprecated */ - @Deprecated public String getCQCode_emoji(String id) { return getCQCodeString(CQCodeTypes.emoji, id); } diff --git a/update.md b/update.md index c7ca4f3..41f5ae8 100644 --- a/update.md +++ b/update.md @@ -2,6 +2,7 @@ # now - 语言系统中增加模组(module)相关语言加载 +- 修复ListenContext对象在使用的时候无法正常依靠`get`与`set`取值设值的问题,并在Context中追加一个`put`方法,含义与`get`一致。 # 1.11.3 - 修复CQAppendList中出现二次转义的情况。