Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet authored and ForteScarlet committed Apr 20, 2020
1 parent 7b1534f commit ecc1f17
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 47 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/forte/qqrobot/intercept/BaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,15 @@ public BaseContext(T value, Map<String, Object> globalContextMap){
this.value = value;
this.globalContextMap = globalContextMap;
}
/**
* 构造
* @param value 上下文所对应的值
* @param globalContextMap 全局上下文值。
* */
public BaseContext(T value, Map<String, Object> globalContextMap, Map<String, Object> contextMap){
this.value = value;
this.globalContextMap = globalContextMap;
this.contextMap = contextMap;
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/forte/qqrobot/intercept/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public interface Context<T> {
*/
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
Expand Down
39 changes: 9 additions & 30 deletions src/main/java/com/forte/qqrobot/listener/ListenContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
public class ListenContext extends BaseContext<Void> {


/**
* 单次生效的Map, 使用懒加载,当前域
*/
private Map<String, Object> normalMap;
// /**
// * 单次生效的Map, 使用懒加载,当前域
// */
// private Map<String, Object> normalMap;

public ListenContext(Map<String, Object> globalContext) {
super(null, globalContext);
}


public ListenContext(Map<String, Object> globalContext, Map<String, Object> normalMap) {
super(null, globalContext);
this.normalMap = normalMap;
super(null, globalContext, normalMap);
}

/**
Expand All @@ -48,10 +48,7 @@ public static ListenContext getInstance(Map<String, Object> globalContext, Map<S
* 初始化normalMap
*/
private Map<String, Object> getNormalMap() {
if (normalMap == null) {
normalMap = new HashMap<>(4);
}
return normalMap;
return getContextMap();
}

/**
Expand All @@ -70,7 +67,7 @@ private Map<String, Object> getNormalMap() {
*/
@Override
public Object get(String key) {
Object normalGet = getNormalMap().get(key);
Object normalGet = getContextMap().get(key);
return normalGet == null ? getGlobal(key) : normalGet;
}

Expand Down Expand Up @@ -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();
// }

/**
* 仅清除全局域
Expand All @@ -147,7 +126,7 @@ public void clearGlobal() {
* 当前域keySet
*/
public Set<String> normalKeySet() {
return getNormalMap().keySet();
return getContextMap().keySet();
}

/**
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/com/forte/qqrobot/utils/CQCodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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));
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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");
}
Expand 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);
}
Expand All @@ -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);
}
Expand All @@ -437,7 +427,6 @@ public CQCode getCQCode_Dice(String type) {
* @see #getCQCode_Shake()
* @deprecated
*/
@Deprecated
public String getCQCode_shake() {
return getCQCodeString(CQCodeTypes.shake);
}
Expand All @@ -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));
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# now
- 语言系统中增加模组(module)相关语言加载
- 修复ListenContext对象在使用的时候无法正常依靠`get``set`取值设值的问题,并在Context中追加一个`put`方法,含义与`get`一致。

# 1.11.3
- 修复CQAppendList中出现二次转义的情况。
Expand Down

0 comments on commit ecc1f17

Please sign in to comment.