summaryrefslogtreecommitdiff
path: root/ATRI/utils/utils_textcheck
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-11-22 01:01:43 +0800
committerKyomotoi <[email protected]>2020-11-22 01:01:43 +0800
commitf7198e8722f310926cf147bd0b218c5d9ef5d6c3 (patch)
treef4c3d0f2a003695b67e0e2018ec8d88898bcda90 /ATRI/utils/utils_textcheck
parent6c3e4c7f583be0006cd7bb913b7db81b987d2813 (diff)
downloadATRI-f7198e8722f310926cf147bd0b218c5d9ef5d6c3.tar.gz
ATRI-f7198e8722f310926cf147bd0b218c5d9ef5d6c3.tar.bz2
ATRI-f7198e8722f310926cf147bd0b218c5d9ef5d6c3.zip
[Update]
新增: * 舆情检测 * 对涩图加以调用限制 修复: * Pixiv插件全体 * 储存群聊信息时无法创建文件 优化: * 部分代码重构,效率up * 调整插件结构,使其看起来更舒服
Diffstat (limited to 'ATRI/utils/utils_textcheck')
-rw-r--r--ATRI/utils/utils_textcheck/__init__.py60
-rw-r--r--ATRI/utils/utils_textcheck/public_opinion.json1
2 files changed, 61 insertions, 0 deletions
diff --git a/ATRI/utils/utils_textcheck/__init__.py b/ATRI/utils/utils_textcheck/__init__.py
new file mode 100644
index 0000000..531bf69
--- /dev/null
+++ b/ATRI/utils/utils_textcheck/__init__.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+# -*- encoding: utf-8 -*-
+'''
+@File : data_source.py
+@Time : 2020/11/21 19:54:11
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
+
+import json
+from pathlib import Path
+from typing import Optional
+
+PUBLIC_OPINION_PATH = Path('.') / 'ATRI' / 'utils' / 'utils_textcheck' / 'public_opinion.json'
+
+
+class Textcheck:
+ """文字检查,专供舆情"""
+ with open(PUBLIC_OPINION_PATH, 'r+') as f:
+ try:
+ data = json.load(f)
+ except:
+ data = {}
+
+ def check(self, msg: str) -> Optional[str]:
+ wait_list = [keys for keys in self.data.keys()]
+ for word in wait_list:
+ if word in msg:
+ return self.data[word]
+ else:
+ return "False"
+
+ def add_word(self, word: str, repo: str, max_times: int,
+ ban_time: int) -> Optional[str]:
+ if word in self.data:
+ return '相关关键词已经有啦~!'
+ else:
+ self.data[word] = [repo, max_times, ban_time]
+ msg0 = '学習しました!\n'
+ msg0 += f'Key: {word}\n'
+ msg0 += f'Repo: {repo}\n'
+ msg0 += f'Max times: {max_times}\n'
+ msg0 += f'Ban time: {ban_time}'
+ return msg0
+
+ def del_word(self, word: str) -> str:
+ if word in self.data:
+ del self.data[word]
+ return "好叻~!"
+ else:
+ return "未发现相关关键词呢..."
+
+ def get_times(self, word: str) -> Optional[int]:
+ if word not in self.data:
+ return 0
+ else:
+ return self.data[word][1]
diff --git a/ATRI/utils/utils_textcheck/public_opinion.json b/ATRI/utils/utils_textcheck/public_opinion.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/ATRI/utils/utils_textcheck/public_opinion.json
@@ -0,0 +1 @@
+{} \ No newline at end of file