mirror of
https://github.com/zhongshmx/JX3BOT.git
synced 2025-09-05 06:24:51 +00:00
0
This commit is contained in:
73
plugin/random/__init__.py
Normal file
73
plugin/random/__init__.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*
|
||||
|
||||
"""
|
||||
@Software : PyCharm
|
||||
@File : __init__.py
|
||||
@Author : 梦影
|
||||
@Time : 2021/04/27 22:22:13
|
||||
"""
|
||||
|
||||
from plugin.common import bot, robot, common
|
||||
from plugin.random.content import seasun
|
||||
from plugin.random.config import extend
|
||||
from nonebot.log import logger
|
||||
from nonebot import aiocqhttp
|
||||
|
||||
command = f"{list(bot.config.NICKNAME)[0]}说"
|
||||
|
||||
func = {command: seasun.content}
|
||||
|
||||
|
||||
@bot.on_message('group') # 聊天功能
|
||||
async def nlpchat(event: aiocqhttp.Event):
|
||||
message = str(event['message'])
|
||||
value = await common.tencent(message)
|
||||
if value:
|
||||
if value[0] == str(event.self_id):
|
||||
message = message.replace(f"[CQ:at,qq={value[0]}]", list(bot.config.NICKNAME)[0])
|
||||
if list(bot.config.NICKNAME)[0] in message and message[0:3] != command:
|
||||
print(message)
|
||||
if not await common.token(event['group_id']):
|
||||
result = await seasun.nlpchat(message)
|
||||
else:
|
||||
result = await common.token(event['group_id'])
|
||||
logger.info(result)
|
||||
await robot.event(event, result)
|
||||
return
|
||||
|
||||
|
||||
@bot.on_message('group') # 语音合成
|
||||
async def voice(event: aiocqhttp.Event):
|
||||
message = str(event['message'])
|
||||
if func.get(message[0:3], None):
|
||||
if not await common.token(event['group_id']):
|
||||
result = await func[message[0:3]](message[0:3])
|
||||
else:
|
||||
result = await common.token(event['group_id'])
|
||||
logger.info(result)
|
||||
await robot.event(event, result)
|
||||
return
|
||||
|
||||
|
||||
@bot.on_message('group') # 随机骚话
|
||||
async def random(event: aiocqhttp.Event):
|
||||
message = str(event['message'])
|
||||
if len(message) >= 5 and 'CQ' not in message and await extend.rand():
|
||||
switch = await common.table('switch', 'Value', event['group_id'], 'random')
|
||||
if switch and not await common.token(event['group_id']):
|
||||
result = await seasun.random(event)
|
||||
logger.info(result)
|
||||
await robot.event(event, result)
|
||||
return
|
||||
|
||||
|
||||
@bot.on_message('group') # 自由聊天
|
||||
async def randchat(event: aiocqhttp.Event):
|
||||
message = str(event['message'])
|
||||
if len(message) >= 2 and 'CQ' not in message and await extend.chat():
|
||||
switch = await common.table('switch', 'Value', event['group_id'], 'nlpchat')
|
||||
if switch and not await common.token(event['group_id']):
|
||||
result = await seasun.nlpchat(message)
|
||||
logger.info(result)
|
||||
await robot.event(event, result)
|
||||
return
|
29
plugin/random/config.py
Normal file
29
plugin/random/config.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*
|
||||
|
||||
"""
|
||||
@Software : PyCharm
|
||||
@File : config.py
|
||||
@Author : 梦影
|
||||
@Time : 2021/04/28 19:56:08
|
||||
"""
|
||||
|
||||
from plugin.common import bot
|
||||
import random
|
||||
|
||||
|
||||
class extend:
|
||||
@staticmethod
|
||||
async def rand(): # 文字触发几率 # 随机模块
|
||||
if random.randint(1, 100) <= bot.config.RANDOM_MAX_VALUE:
|
||||
result = True
|
||||
else:
|
||||
result = False
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def chat(): # 聊天触发几率 # 随机模块
|
||||
if random.randint(1, 100) <= bot.config.NLPCHAT_MAX_VALUE:
|
||||
result = True
|
||||
else:
|
||||
result = False
|
||||
return result
|
61
plugin/random/content.py
Normal file
61
plugin/random/content.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*
|
||||
|
||||
"""
|
||||
@Software : PyCharm
|
||||
@File : content.py
|
||||
@Author : 梦影
|
||||
@Time : 2021/04/28 19:56:13
|
||||
"""
|
||||
|
||||
from plugin.common import bot, robot, submit
|
||||
import random
|
||||
|
||||
|
||||
class seasun:
|
||||
@staticmethod
|
||||
async def nlpchat(message):
|
||||
data = {'question': message, 'appid': bot.config.NLPCHAT_APPID, 'appkey': bot.config.NLPCHAT_APPKEY,
|
||||
'name': list(bot.config.NICKNAME)[0]}
|
||||
data = await submit.connect(url=f"{bot.domain}/extend/getnlpchat", data=data)
|
||||
if data['code'] == 200:
|
||||
result = data['data']['answer']
|
||||
else:
|
||||
result = None
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def content(message): # 语音合成中转
|
||||
result = await seasun.voice(message)
|
||||
if result:
|
||||
result = f"[CQ:record,file={result}]"
|
||||
else:
|
||||
result = "找不到相关信息!"
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def random(event):
|
||||
text = await seasun.text()
|
||||
if random.randint(1, 2) == 1:
|
||||
return f"{await robot.sender(event)} {text}"
|
||||
else:
|
||||
result = await seasun.voice(text)
|
||||
result = f"[CQ:record,file={result}]"
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def text():
|
||||
data = await submit.connect(url=f"{bot.domain}/app/getrandom")
|
||||
if data['code'] == 200:
|
||||
return data['data']['text']
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
async def voice(text: str):
|
||||
data = {'appkey': bot.config.ALIYUN_APPKEY, 'access': bot.config.ALIYUN_ACCESS,
|
||||
'secret': bot.config.ALIYUN_SECRET, 'text': text}
|
||||
data = await submit.connect(url=f"{bot.domain}/extend/getaliyun", data=data)
|
||||
if data['code'] == 200:
|
||||
return data['data']['url']
|
||||
else:
|
||||
return None
|
Reference in New Issue
Block a user