mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-22 10:36:16 +08:00
Add xiaoice command
This commit is contained in:
parent
260878c220
commit
656190e70f
@ -89,5 +89,12 @@ class ApiClient:
|
|||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def wx_consult(self, account, content):
|
||||||
|
if self.wx_api_url:
|
||||||
|
try:
|
||||||
|
return requests.get(self.wx_api_url + '/consult', params={'account': account, 'content': content})
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
client = ApiClient()
|
client = ApiClient()
|
||||||
|
46
commands/ai.py
Normal file
46
commands/ai.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from command import CommandRegistry
|
||||||
|
from commands import core
|
||||||
|
from little_shit import get_source
|
||||||
|
from apiclient import client as api
|
||||||
|
|
||||||
|
__registry__ = cr = CommandRegistry()
|
||||||
|
|
||||||
|
|
||||||
|
@cr.register('tuling123', 'chat', '聊天')
|
||||||
|
def tuling123(args_text, ctx_msg, internal=False):
|
||||||
|
url = 'http://www.tuling123.com/openapi/api'
|
||||||
|
data = {
|
||||||
|
'key': os.environ.get('TURING123_API_KEY'),
|
||||||
|
'info': args_text,
|
||||||
|
'userid': get_source(ctx_msg)
|
||||||
|
}
|
||||||
|
resp = requests.post(url, data=data)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
json = resp.json()
|
||||||
|
if internal:
|
||||||
|
return json
|
||||||
|
if int(json.get('code', 0)) == 100000:
|
||||||
|
reply = json.get('text', '')
|
||||||
|
else:
|
||||||
|
# Is not text type
|
||||||
|
reply = '腊鸡图灵机器人返回了一堆奇怪的东西,就不发出来了'
|
||||||
|
else:
|
||||||
|
if internal:
|
||||||
|
return None
|
||||||
|
reply = '腊鸡图灵机器人出问题了,先不管他,过会儿再玩他'
|
||||||
|
core.echo(reply, ctx_msg)
|
||||||
|
|
||||||
|
|
||||||
|
@cr.register('xiaoice', '小冰')
|
||||||
|
def xiaoice(args_text, ctx_msg, internal=False):
|
||||||
|
resp = api.wx_consult(account='xiaoice-ms', content=args_text)
|
||||||
|
if resp:
|
||||||
|
json = resp.json()
|
||||||
|
if json and json.get('reply'):
|
||||||
|
reply = json['reply']
|
||||||
|
core.echo(reply, ctx_msg, internal)
|
||||||
|
return reply
|
||||||
|
return None
|
@ -1,8 +1,4 @@
|
|||||||
import os
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from command import CommandRegistry
|
from command import CommandRegistry
|
||||||
from little_shit import get_source
|
|
||||||
from apiclient import client as api
|
from apiclient import client as api
|
||||||
|
|
||||||
__registry__ = cr = CommandRegistry()
|
__registry__ = cr = CommandRegistry()
|
||||||
@ -16,31 +12,6 @@ def echo(args_text, ctx_msg, internal=False):
|
|||||||
return api.send_message(args_text, ctx_msg)
|
return api.send_message(args_text, ctx_msg)
|
||||||
|
|
||||||
|
|
||||||
@cr.register('tuling123', 'chat', '聊天')
|
|
||||||
def tuling123(args_text, ctx_msg, internal=False):
|
|
||||||
url = 'http://www.tuling123.com/openapi/api'
|
|
||||||
data = {
|
|
||||||
'key': os.environ.get('TURING123_API_KEY'),
|
|
||||||
'info': args_text,
|
|
||||||
'userid': get_source(ctx_msg)
|
|
||||||
}
|
|
||||||
resp = requests.post(url, data=data)
|
|
||||||
if resp.status_code == 200:
|
|
||||||
json = resp.json()
|
|
||||||
if internal:
|
|
||||||
return json
|
|
||||||
if int(json.get('code', 0)) == 100000:
|
|
||||||
reply = json.get('text', '')
|
|
||||||
else:
|
|
||||||
# Is not text type
|
|
||||||
reply = '腊鸡图灵机器人返回了一堆奇怪的东西,就不发出来了'
|
|
||||||
else:
|
|
||||||
if internal:
|
|
||||||
return None
|
|
||||||
reply = '腊鸡图灵机器人出问题了,先不管他,过会儿再玩他'
|
|
||||||
echo(reply, ctx_msg)
|
|
||||||
|
|
||||||
|
|
||||||
@cr.register('help', '帮助', '用法', '使用帮助', '使用指南', '使用说明', '使用方法', '怎么用')
|
@cr.register('help', '帮助', '用法', '使用帮助', '使用指南', '使用说明', '使用方法', '怎么用')
|
||||||
def help(_, ctx_msg):
|
def help(_, ctx_msg):
|
||||||
echo(
|
echo(
|
||||||
|
@ -4,7 +4,7 @@ import requests
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from command import CommandRegistry
|
from command import CommandRegistry
|
||||||
from commands import core
|
from commands import core, ai
|
||||||
|
|
||||||
__registry__ = cr = CommandRegistry()
|
__registry__ = cr = CommandRegistry()
|
||||||
|
|
||||||
@ -73,14 +73,14 @@ def weather(args_text, ctx_msg):
|
|||||||
core.echo('请在命令后加上要查的城市哦~(命令和城市用空格或逗号隔开)', ctx_msg)
|
core.echo('请在命令后加上要查的城市哦~(命令和城市用空格或逗号隔开)', ctx_msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
data = core.tuling123(city + '天气', ctx_msg, internal=True)
|
data = ai.tuling123(city + '天气', ctx_msg, internal=True)
|
||||||
core.echo(data.get('text', ''), ctx_msg)
|
core.echo(data.get('text', ''), ctx_msg)
|
||||||
|
|
||||||
|
|
||||||
@cr.register('joke')
|
@cr.register('joke')
|
||||||
@cr.register('笑话', '说笑话', '说个笑话')
|
@cr.register('笑话', '说笑话', '说个笑话')
|
||||||
def weather(_, ctx_msg):
|
def weather(_, ctx_msg):
|
||||||
data = core.tuling123('说个笑话', ctx_msg, internal=True)
|
data = ai.tuling123('说个笑话', ctx_msg, internal=True)
|
||||||
core.echo(data.get('text', ''), ctx_msg)
|
core.echo(data.get('text', ''), ctx_msg)
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ def weather(args_text, ctx_msg):
|
|||||||
if not query:
|
if not query:
|
||||||
core.echo('请在命令后加上要查的关键词哦~(命令和关键词用空格或逗号隔开)', ctx_msg)
|
core.echo('请在命令后加上要查的关键词哦~(命令和关键词用空格或逗号隔开)', ctx_msg)
|
||||||
return
|
return
|
||||||
data = core.tuling123('百科 ' + query, ctx_msg, internal=True)
|
data = ai.tuling123('百科 ' + query, ctx_msg, internal=True)
|
||||||
core.echo(data.get('text', ''), ctx_msg)
|
core.echo(data.get('text', ''), ctx_msg)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
config = {
|
config = {
|
||||||
'fallback_command': 'natural_language.process',
|
'fallback_command': 'natural_language.process',
|
||||||
'fallback_command_after_nl_processors': 'core.tuling123',
|
'fallback_command_after_nl_processors': 'ai.tuling123',
|
||||||
'command_start_flags': ('/', '/', '来,', '来,'), # Add '' (empty string) here to allow commands without start flags
|
'command_start_flags': ('/', '/', '来,', '来,'), # Add '' (empty string) here to allow commands without start flags
|
||||||
'command_name_separators': ('->', '::', '/'), # Regex
|
'command_name_separators': ('->', '::', '/'), # Regex
|
||||||
'command_args_start_flags': (',', ':', ',', ', ', ':', ': '), # Regex
|
'command_args_start_flags': (',', ':', ',', ', ', ':', ': '), # Regex
|
||||||
|
Loading…
x
Reference in New Issue
Block a user