aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/example
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-11-15 09:40:59 +0800
committerGitHub <noreply@github.com>2023-11-15 09:40:59 +0800
commita0a3e741a52391b0692563111bd5e5ebbd2937e8 (patch)
treee99e0dc8651ff0df6bc03f655072734667573e3e /example
parent32f1a4f749b3cbb8d631c2f389ec91dbbded1ce8 (diff)
downloadHydroRoll-a0a3e741a52391b0692563111bd5e5ebbd2937e8.tar.gz
HydroRoll-a0a3e741a52391b0692563111bd5e5ebbd2937e8.zip
fix: 在输入流时间内无法进行全匹配 (#80)
* chore(deps): add dingtalk * chore: upgrade iamai version to 3.2.9
Diffstat (limited to 'example')
-rw-r--r--example/config.toml14
-rw-r--r--example/plugins/HydroRoll/__init__.py46
-rw-r--r--example/plugins/show.py7
3 files changed, 44 insertions, 23 deletions
diff --git a/example/config.toml b/example/config.toml
index 19e1e5f..32ca3cd 100644
--- a/example/config.toml
+++ b/example/config.toml
@@ -3,7 +3,11 @@ plugins = []
plugin_dirs = ["plugins"]
rules = []
rule_dirs = ["rules"]
-adapters = ["iamai.adapter.cqhttp","iamai.adapter.apscheduler"]
+adapters = [
+ "iamai.adapter.cqhttp",
+ "iamai.adapter.apscheduler",
+ "iamai.adapter.dingtalk"
+]
[bot.log]
level = "INFO"
@@ -16,6 +20,14 @@ port = 8080
url = "/cqhttp/ws"
show_raw = false
+[adapter.dingtalk]
+adapter_type = "stream"
+host = "127.0.0.1"
+port = 8081
+url = "/dingtalk"
+app_secret = "FnQU_a88xRpmcs3oPNXSgoQgm4TidGduVqKhLHR7_NgF6MLBUUbwYdE6MkOFWZFb"
+app_key = "dingo7xu5djthkxpoick"
+
[adapter.apscheduler]
scheduler_config = { "apscheduler.timezone" = "Asia/Shanghai" }
diff --git a/example/plugins/HydroRoll/__init__.py b/example/plugins/HydroRoll/__init__.py
index 151a58a..e667969 100644
--- a/example/plugins/HydroRoll/__init__.py
+++ b/example/plugins/HydroRoll/__init__.py
@@ -12,6 +12,7 @@ from .utils import *
from .models.Transformer import query
from .command import Set, Get
from iamai.exceptions import GetEventTimeout
+from iamai.adapter.cqhttp.event import GroupMessageEvent, PrivateMessageEvent
BASE_DIR = dirname(abspath("__file__"))
HYDRO_DIR = dirname(abspath(__file__))
@@ -48,29 +49,31 @@ class HydroRoll(Plugin):
@TODO: HydroRollCore should be able to handle all signals and tokens from Psi.
@BODY: HydroRollCore actives the rule-packages.
"""
+ global flag
+
args = self.event.get_plain_text().split(" ")
command_list = [".root", ".roots", ".core", ".set", ".get", ".test"]
- for cmd in command_list:
- if cmd.startswith(args[0]):
- logger.info(cmd)
- if args[0] != cmd:
- try:
- flag = True
- current_cmd = args[0]
- while flag:
- flag = False
- event = await self.ask(ask_text=None, timeout=3)
- current_cmd = current_cmd + event.get_plain_text()
- if cmd.startswith(current_cmd):
- if current_cmd != cmd:
- flag = True
- else:
- await self.event.reply(f"{cmd}")
- flag = False
- except GetEventTimeout:
- continue
+ current_cmd = args[0]
+ flag = True in [cmd.startswith(current_cmd) for cmd in command_list]
+ logger.info(f"Command {current_cmd} not found with flag {flag}")
+ try:
+ while flag:
+ flag = False
+ if current_cmd not in command_list:
+ event = await self.ask(ask_text="", timeout=3)
+ if event.get_plain_text() not in command_list:
+ await self.event.reply(f"{event.get_plain_text()}")
+ flag = False
+ break
+ current_cmd = current_cmd + event.get_plain_text()
+ if current_cmd not in command_list:
+ flag = True
else:
- await self.event.reply(cmd)
+ await self.event.reply(f"{current_cmd}")
+ flag = False
+ break
+ except GetEventTimeout:
+ return
# if args[0] in [".root", ".roots"]:
# import requests
@@ -101,6 +104,7 @@ class HydroRoll(Plugin):
and self.event.type == "message"
and self.event.message_type == "private"
and not os.path.exists(join(BASE_DIR, "HydroRoll"))
+ and self.event.adapter.name in ["cqhttp", "kook", "console", "mirai"]
):
# hola = self.models["hola"]
# _, max_similarity = find_max_similarity(
@@ -112,7 +116,7 @@ class HydroRoll(Plugin):
self.bot.global_state["HydroRoll"]["hola"] = True
await self.event.reply("验证成功√ 正在初始化水系目录...")
logger.info(GlobalConfig._copyright)
- return self.event.adapter.name in ["cqhttp", "kook", "console", "mirai"]
+ return issubclass(PrivateMessageEvent, self.event.__class__) # or issubclass(GroupMessageEvent, self.event.__class__)
def _init_directory(self, _prefix: str = ""):
"""初始化水系目录"""
diff --git a/example/plugins/show.py b/example/plugins/show.py
index 289e141..e43a241 100644
--- a/example/plugins/show.py
+++ b/example/plugins/show.py
@@ -1,5 +1,9 @@
from iamai import Plugin
from numpy.random import Generator
+from iamai.adapter.cqhttp.message import CQHTTPMessage, CQHTTPMessageSegment
+
+ms = CQHTTPMessageSegment
+
@@ -21,7 +25,8 @@ class Exec(Plugin):
"data": {
"text": f"{eval(self.event.message.get_plain_text()[6:])}"
}
- }
+ },
+ # eval(self.event.message.get_plain_text()[6:])
]
}
}