hyper-bot 0.72__tar.gz → 0.741__tar.gz
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.
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Network.py +8 -1
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Segments.py +8 -3
- hyper-bot-0.741/Hyper/WordSafety.py +40 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/PKG-INFO +1 -1
- {hyper-bot-0.72 → hyper-bot-0.741}/hyper_bot.egg-info/PKG-INFO +1 -1
- {hyper-bot-0.72 → hyper-bot-0.741}/setup.py +1 -1
- hyper-bot-0.72/Hyper/WordSafety.py +0 -68
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Adapters/OneBot.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Adapters/OneBotLib/Manager.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Configurator.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/DataBase.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Errors.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Events.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Listener.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Logger.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Logic.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/Manager.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/Hyper/ModuleClass.py +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/LICENSE +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/hyper_bot.egg-info/SOURCES.txt +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/hyper_bot.egg-info/top_level.txt +0 -0
- {hyper-bot-0.72 → hyper-bot-0.741}/setup.cfg +0 -0
|
@@ -41,7 +41,9 @@ class HTTPConnection:
|
|
|
41
41
|
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
|
42
42
|
self.reports = queue.Queue()
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
self.listener_started = False
|
|
45
|
+
|
|
46
|
+
def __start_listener(self) -> None:
|
|
45
47
|
@self.app.route("/", methods=["POST"])
|
|
46
48
|
def listener():
|
|
47
49
|
self.reports.put(flask.request.json)
|
|
@@ -50,6 +52,11 @@ class HTTPConnection:
|
|
|
50
52
|
# self.app.run(host=self.listener_url, port=self.port)
|
|
51
53
|
|
|
52
54
|
threading.Thread(target=lambda: self.app.run(host=self.listener_url, port=self.port)).start()
|
|
55
|
+
self.listener_started = True
|
|
56
|
+
|
|
57
|
+
def connect(self) -> None:
|
|
58
|
+
if not self.listener_started:
|
|
59
|
+
self.__start_listener()
|
|
53
60
|
httpx.post(self.url)
|
|
54
61
|
traceback.print_exc()
|
|
55
62
|
|
|
@@ -21,7 +21,10 @@ def segment_builder(sg_type: str, summary_tmp: str = None):
|
|
|
21
21
|
|
|
22
22
|
if len(kwargs) > 0:
|
|
23
23
|
for i in kwargs:
|
|
24
|
-
|
|
24
|
+
try:
|
|
25
|
+
arg[i] = anns[i](kwargs[i])
|
|
26
|
+
except TypeError:
|
|
27
|
+
arg[i] = kwargs[i]
|
|
25
28
|
new_arg = arg.copy()
|
|
26
29
|
|
|
27
30
|
if len(anns) > len(arg):
|
|
@@ -30,7 +33,10 @@ def segment_builder(sg_type: str, summary_tmp: str = None):
|
|
|
30
33
|
if i not in var.keys():
|
|
31
34
|
new_arg[i] = None
|
|
32
35
|
continue
|
|
33
|
-
|
|
36
|
+
try:
|
|
37
|
+
new_arg[i] = anns[i](var[i])
|
|
38
|
+
except TypeError:
|
|
39
|
+
new_arg[i] = var[i]
|
|
34
40
|
|
|
35
41
|
for i in new_arg:
|
|
36
42
|
setattr(self, i, new_arg[i])
|
|
@@ -41,7 +47,6 @@ def segment_builder(sg_type: str, summary_tmp: str = None):
|
|
|
41
47
|
base = {"type": sg_type, "data": {}}
|
|
42
48
|
for i in anns:
|
|
43
49
|
base["data"][i] = getattr(self, i)
|
|
44
|
-
|
|
45
50
|
return base
|
|
46
51
|
|
|
47
52
|
cls.to_json = to_json
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from jieba import lcut, set_dictionary
|
|
3
|
+
|
|
4
|
+
from Hyper import Logic
|
|
5
|
+
|
|
6
|
+
logging.getLogger("jieba").setLevel(logging.ERROR)
|
|
7
|
+
try:
|
|
8
|
+
set_dictionary("./assets/jieba.dict.txt.small")
|
|
9
|
+
except OSError:
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Result:
|
|
14
|
+
def __init__(self, message: str, result: bool):
|
|
15
|
+
self.message = message
|
|
16
|
+
self.result = result
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
with open("assets/dict.txt", "r", encoding="utf-8") as f:
|
|
20
|
+
words: list[dict[str, str]] = []
|
|
21
|
+
word = f.read()
|
|
22
|
+
word = word.split("\n")
|
|
23
|
+
for i in word:
|
|
24
|
+
temp = i.split(" ")
|
|
25
|
+
words.append({"word": temp[0], "type": temp[1]})
|
|
26
|
+
|
|
27
|
+
del i
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@Logic.Cacher().cache
|
|
31
|
+
def check(text: str) -> Result:
|
|
32
|
+
texts = lcut(text)
|
|
33
|
+
for j in words:
|
|
34
|
+
if j["word"] in texts:
|
|
35
|
+
ret = Result(f"检测到类型为{j['type']}的敏感用词", False)
|
|
36
|
+
del j
|
|
37
|
+
return ret
|
|
38
|
+
del j
|
|
39
|
+
ret = Result("未检出敏感词", True)
|
|
40
|
+
return ret
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import jieba
|
|
2
|
-
import logging
|
|
3
|
-
import asyncio
|
|
4
|
-
|
|
5
|
-
from Hyper import Logic
|
|
6
|
-
|
|
7
|
-
logging.getLogger("jieba").setLevel(logging.ERROR)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Result:
|
|
11
|
-
def __init__(self, message: str, result: bool):
|
|
12
|
-
self.message = message
|
|
13
|
-
self.result = result
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class AsyncChecker:
|
|
17
|
-
def __init__(self, hot_words: list[dict[str, str]]):
|
|
18
|
-
self.hot_words = hot_words
|
|
19
|
-
|
|
20
|
-
async def check(self, text: list) -> Result:
|
|
21
|
-
for j in self.hot_words:
|
|
22
|
-
if j["word"] in text:
|
|
23
|
-
ret = Result(f"检测到类型为{j['type']}的敏感用词", False)
|
|
24
|
-
return ret
|
|
25
|
-
|
|
26
|
-
ret = Result("未检出敏感词", True)
|
|
27
|
-
return ret
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
with open("assets/dict.txt", "r", encoding="utf-8") as f:
|
|
31
|
-
words: list[dict[str, str]] = []
|
|
32
|
-
word = f.read()
|
|
33
|
-
word = word.split("\n")
|
|
34
|
-
inner_words: list[AsyncChecker] = []
|
|
35
|
-
tmp: list[dict[str, str]] = []
|
|
36
|
-
for i in word:
|
|
37
|
-
temp = i.split(" ")
|
|
38
|
-
words.append({"word": temp[0], "type": temp[1]})
|
|
39
|
-
tmp.append({"word": temp[0], "type": temp[1]})
|
|
40
|
-
if len(tmp) == 50:
|
|
41
|
-
inner_words.append(AsyncChecker(tmp))
|
|
42
|
-
tmp = []
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@Logic.Cacher().cache
|
|
46
|
-
def check(text: str) -> Result:
|
|
47
|
-
texts = jieba.lcut(text)
|
|
48
|
-
for j in words:
|
|
49
|
-
if j["word"] in texts:
|
|
50
|
-
ret = Result(f"检测到类型为{j['type']}的敏感用词", False)
|
|
51
|
-
return ret
|
|
52
|
-
|
|
53
|
-
ret = Result("未检出敏感词", True)
|
|
54
|
-
return ret
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
@Logic.Cacher().cache
|
|
58
|
-
async def check_async(text: str) -> Result:
|
|
59
|
-
texts = jieba.lcut(text)
|
|
60
|
-
__tasks: list[asyncio.Task] = []
|
|
61
|
-
for j in inner_words:
|
|
62
|
-
__tasks.append(asyncio.create_task(j.check(texts)))
|
|
63
|
-
await asyncio.gather(*__tasks)
|
|
64
|
-
for j in __tasks:
|
|
65
|
-
if not j.result().result:
|
|
66
|
-
return j.result()
|
|
67
|
-
ret = Result("未检出敏感词", True)
|
|
68
|
-
return ret
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|