mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 11:42:46 +00:00
groupcloud 默认禁用 AI 分词,使用参数启用。
This commit is contained in:
parent
ca45d6d587
commit
7ad2f5663b
17
groupword.py
17
groupword.py
@ -27,8 +27,12 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=True, outgoing=True, command=alias_command("groupword"),
|
@listener(is_plugin=True, outgoing=True, command=alias_command("groupword"),
|
||||||
description="拉取最新 300 条消息生成词云。")
|
description="拉取最新 300 条消息生成词云。",
|
||||||
|
parameters="[任意内容启用AI分词]")
|
||||||
async def group_word(context):
|
async def group_word(context):
|
||||||
|
imported_1 = False
|
||||||
|
if len(context.parameter) >= 1:
|
||||||
|
imported_1 = True
|
||||||
if not imported:
|
if not imported:
|
||||||
try:
|
try:
|
||||||
await context.edit("支持库 `jieba` `paddlepaddle-tiny` 未安装...\n正在尝试自动安装...")
|
await context.edit("支持库 `jieba` `paddlepaddle-tiny` 未安装...\n正在尝试自动安装...")
|
||||||
@ -44,7 +48,7 @@ async def group_word(context):
|
|||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
if not imported_:
|
if not imported_ and imported_1:
|
||||||
try:
|
try:
|
||||||
await context.edit("支持库 `paddlepaddle-tiny` 未安装...\n正在尝试自动安装...")
|
await context.edit("支持库 `paddlepaddle-tiny` 未安装...\n正在尝试自动安装...")
|
||||||
await execute(f'{executable} -m pip install paddlepaddle-tiny')
|
await execute(f'{executable} -m pip install paddlepaddle-tiny')
|
||||||
@ -73,14 +77,17 @@ async def group_word(context):
|
|||||||
words = defaultdict(int)
|
words = defaultdict(int)
|
||||||
count = 0
|
count = 0
|
||||||
try:
|
try:
|
||||||
if imported_:
|
if imported_ and imported_1:
|
||||||
jieba.enable_paddle()
|
try:
|
||||||
|
jieba.enable_paddle()
|
||||||
|
except:
|
||||||
|
imported_1 = False
|
||||||
async for msg in context.client.iter_messages(context.chat, limit=500):
|
async for msg in context.client.iter_messages(context.chat, limit=500):
|
||||||
if msg.id == context.id:
|
if msg.id == context.id:
|
||||||
continue
|
continue
|
||||||
if msg.text and not msg.text.startswith('/') and not msg.text.startswith('-') and not '//' in msg.text:
|
if msg.text and not msg.text.startswith('/') and not msg.text.startswith('-') and not '//' in msg.text:
|
||||||
try:
|
try:
|
||||||
if imported_:
|
if imported_ and imported_1:
|
||||||
for word in jieba.cut(msg.text.translate(punctuation), use_paddle=True):
|
for word in jieba.cut(msg.text.translate(punctuation), use_paddle=True):
|
||||||
word = word.lower()
|
word = word.lower()
|
||||||
words[word] += 1
|
words[word] += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user