koishi-plugin-game-mini 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +74 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -698,6 +698,79 @@ async function apply(ctx, cfg) {
|
|
|
698
698
|
gameStates.set(key, st);
|
|
699
699
|
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', false);
|
|
700
700
|
};
|
|
701
|
+
const extractHintText = (data) => {
|
|
702
|
+
if (!data)
|
|
703
|
+
return '暂无提示信息';
|
|
704
|
+
try {
|
|
705
|
+
if (typeof data === 'string')
|
|
706
|
+
return data;
|
|
707
|
+
if (data.hint) {
|
|
708
|
+
if (typeof data.hint === 'string')
|
|
709
|
+
return data.hint;
|
|
710
|
+
if (typeof data.hint === 'object') {
|
|
711
|
+
if (data.hint.message)
|
|
712
|
+
return data.hint.message;
|
|
713
|
+
if (data.hint.hint)
|
|
714
|
+
return data.hint.hint;
|
|
715
|
+
if (data.hint.content)
|
|
716
|
+
return data.hint.content;
|
|
717
|
+
return JSON.stringify(data.hint);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (data.message) {
|
|
721
|
+
if (typeof data.message === 'string')
|
|
722
|
+
return data.message;
|
|
723
|
+
if (typeof data.message === 'object') {
|
|
724
|
+
return extractHintText(data.message);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (data.content) {
|
|
728
|
+
if (typeof data.content === 'string')
|
|
729
|
+
return data.content;
|
|
730
|
+
if (typeof data.content === 'object') {
|
|
731
|
+
return extractHintText(data.content);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (data.text) {
|
|
735
|
+
if (typeof data.text === 'string')
|
|
736
|
+
return data.text;
|
|
737
|
+
if (typeof data.text === 'object') {
|
|
738
|
+
return extractHintText(data.text);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (data.description) {
|
|
742
|
+
if (typeof data.description === 'string')
|
|
743
|
+
return data.description;
|
|
744
|
+
if (typeof data.description === 'object') {
|
|
745
|
+
return extractHintText(data.description);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const possibleFields = ['info', 'detail', 'value', 'data', 'result'];
|
|
749
|
+
for (const field of possibleFields) {
|
|
750
|
+
if (data[field]) {
|
|
751
|
+
if (typeof data[field] === 'string')
|
|
752
|
+
return data[field];
|
|
753
|
+
if (typeof data[field] === 'object') {
|
|
754
|
+
const extracted = extractHintText(data[field]);
|
|
755
|
+
if (extracted !== '暂无提示信息')
|
|
756
|
+
return extracted;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
const keys = Object.keys(data);
|
|
761
|
+
if (keys.length > 0) {
|
|
762
|
+
for (const key of keys) {
|
|
763
|
+
if (typeof data[key] === 'string' && data[key].length > 0) {
|
|
764
|
+
return data[key];
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
catch (e) {
|
|
770
|
+
logError('提取提示信息时出错', e);
|
|
771
|
+
}
|
|
772
|
+
return '暂无提示信息';
|
|
773
|
+
};
|
|
701
774
|
ctx.middleware(async (session, next) => {
|
|
702
775
|
if (!session.content)
|
|
703
776
|
return next();
|
|
@@ -826,13 +899,7 @@ async function apply(ctx, cfg) {
|
|
|
826
899
|
logDebug(`[看图猜成语] 获取提示API返回数据:`, r.data);
|
|
827
900
|
const dt = r.data;
|
|
828
901
|
if (dt.success) {
|
|
829
|
-
|
|
830
|
-
if (dt.data.hint && typeof dt.data.hint === 'object') {
|
|
831
|
-
hintText = dt.data.hint.message || dt.data.hint.hint || JSON.stringify(dt.data.hint);
|
|
832
|
-
}
|
|
833
|
-
else {
|
|
834
|
-
hintText = dt.data.hint || dt.message || '未知提示';
|
|
835
|
-
}
|
|
902
|
+
const hintText = extractHintText(dt.data);
|
|
836
903
|
logDebug(`[看图猜成语] 成功获取提示: ${hintText}`);
|
|
837
904
|
await session.send(d.chengyuImage.hintGet.replace('{0}', hintText));
|
|
838
905
|
}
|