mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
Clean up and fix
This commit is contained in:
parent
0f7f9250c1
commit
82a0681e9f
@ -29,12 +29,13 @@ def process(args_text, ctx_msg):
|
|||||||
ctx_msg['parsed_data'] = most_possible_cmd[3]
|
ctx_msg['parsed_data'] = most_possible_cmd[3]
|
||||||
cmdhub.call(most_possible_cmd[1], most_possible_cmd[2], ctx_msg)
|
cmdhub.call(most_possible_cmd[1], most_possible_cmd[2], ctx_msg)
|
||||||
else:
|
else:
|
||||||
if ctx_msg.get('from_voice'):
|
# if ctx_msg.get('from_voice'):
|
||||||
# Special for voice message
|
# Special for voice message
|
||||||
if _fallback_command:
|
if _fallback_command:
|
||||||
core.echo('暂时无法理解你的意思,下面将使用备用命令 ' + _fallback_command + '……', ctx_msg)
|
core.echo('暂时无法理解你的意思,下面将使用备用命令 ' + _fallback_command + '……', ctx_msg)
|
||||||
cmdhub.call(_fallback_command, sentence, ctx_msg)
|
cmdhub.call(_fallback_command, sentence, ctx_msg)
|
||||||
return
|
return
|
||||||
core.echo('暂时无法理解你的意思。\n'
|
pass
|
||||||
'由于自然语言识别还非常不完善,建议使用命令来精确控制我。\n'
|
# core.echo('暂时无法理解你的意思。\n'
|
||||||
'如需帮助请发送「使用帮助」。', ctx_msg)
|
# '由于自然语言识别还非常不完善,建议使用命令来精确控制我。\n'
|
||||||
|
# '如需帮助请发送「使用帮助」。', ctx_msg)
|
||||||
|
@ -28,13 +28,12 @@ def ip(args_text, ctx_msg):
|
|||||||
resp = requests.get(chinaz_url % query)
|
resp = requests.get(chinaz_url % query)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
html = etree.HTML(resp.text)
|
html = etree.HTML(resp.text)
|
||||||
p_elems = html.xpath('//*[@id="leftinfo"]/div[3]/div[2]/p')
|
p_elems = html.xpath('//p[@class="WhwtdWrap bor-b1s col-gray03"]')
|
||||||
if len(p_elems) > 1:
|
if len(p_elems) > 0:
|
||||||
p_elems = p_elems[1:]
|
reply = 'ChinaZ.com:'
|
||||||
reply = 'ChinaZ:'
|
|
||||||
for p_elem in p_elems:
|
for p_elem in p_elems:
|
||||||
span_elems = p_elem.getchildren()
|
span_elems = p_elem.getchildren()
|
||||||
reply += '\n' + span_elems[1].text.replace('.', '_') + ', ' + span_elems[3].text
|
reply += '\n' + span_elems[1].text + ', ' + span_elems[3].text
|
||||||
core.echo(reply, ctx_msg)
|
core.echo(reply, ctx_msg)
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ def ip(args_text, ctx_msg):
|
|||||||
# Example: 'IP:123.125.114.144 来自:北京市 联通'
|
# Example: 'IP:123.125.114.144 来自:北京市 联通'
|
||||||
items = resp.text.strip().split(':')
|
items = resp.text.strip().split(':')
|
||||||
if len(items) == 3:
|
if len(items) == 3:
|
||||||
reply = 'IP_CN:\n' + items[1].split(' ')[0].replace('.', '_') + ', ' + items[2]
|
reply = 'IP.cn:\n' + items[1].split(' ')[0] + ', ' + items[2]
|
||||||
core.echo(reply, ctx_msg)
|
core.echo(reply, ctx_msg)
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ def ip(args_text, ctx_msg):
|
|||||||
if resp.status_code == 200 and resp.text.strip():
|
if resp.status_code == 200 and resp.text.strip():
|
||||||
# Example: '["中国","江苏","常州","","教育网"]'
|
# Example: '["中国","江苏","常州","","教育网"]'
|
||||||
parts = json.loads(resp.text)
|
parts = json.loads(resp.text)
|
||||||
reply = 'IPIP_NET\n' + query.replace('.', '_') + ' ' + ''.join(parts)
|
reply = 'IPIP.net\n' + query + ' ' + ''.join(parts)
|
||||||
core.echo(reply, ctx_msg)
|
core.echo(reply, ctx_msg)
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
|
@ -18,9 +18,8 @@ class CoolQHttpApiAdapter(Adapter):
|
|||||||
|
|
||||||
def unitize_context(self, ctx_msg: dict):
|
def unitize_context(self, ctx_msg: dict):
|
||||||
# Check token
|
# Check token
|
||||||
if self.token:
|
if flask_req.headers.get('Authorization') != self.session.headers.get('Authorization'):
|
||||||
if flask_req.headers.get('Authorization', '') != 'token ' + self.token:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
new_ctx = {'raw_ctx': ctx_msg, 'post_type': ctx_msg['post_type'], 'via': ctx_msg['via'],
|
new_ctx = {'raw_ctx': ctx_msg, 'post_type': ctx_msg['post_type'], 'via': ctx_msg['via'],
|
||||||
'login_id': ctx_msg['login_id']}
|
'login_id': ctx_msg['login_id']}
|
||||||
|
@ -5,7 +5,7 @@ from nl_processor import as_processor
|
|||||||
_query_lang_matcher = [
|
_query_lang_matcher = [
|
||||||
re.compile('(?:(?:要|[应]?该)?怎么|怎样|如何)?[把将]?[\s,.,。]?(?P<query>.*?)[\s,.,。]?'
|
re.compile('(?:(?:要|[应]?该)?怎么|怎样|如何)?[把将]?[\s,.,。]?(?P<query>.*?)[\s,.,。]?'
|
||||||
'(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?翻译[成为到](?P<lang>\w+?[文语])(?![\s::,,.。])'),
|
'(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?翻译[成为到](?P<lang>\w+?[文语])(?![\s::,,.。])'),
|
||||||
re.compile('(?P<query>.+?)[\s,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?的(?P<lang>\w+?[文语])'),
|
re.compile('(?P<query>.+?)[\s,.,。]?(?:这[个]?(?:词[组]?|句(?:子|话)?|短语))?[的用](?P<lang>\w+?[文语])'),
|
||||||
re.compile('.*?[把将]?(?:(?:[下后][面])?(?:这[个]?|[下后][面]?)(?:词[组]?|句(?:子|话)?|短语))?'
|
re.compile('.*?[把将]?(?:(?:[下后][面])?(?:这[个]?|[下后][面]?)(?:词[组]?|句(?:子|话)?|短语))?'
|
||||||
'翻译[成为到]\s*(?P<lang>\w+?[文语])[\s::,,](?P<query>.*)'),
|
'翻译[成为到]\s*(?P<lang>\w+?[文语])[\s::,,](?P<query>.*)'),
|
||||||
re.compile('.*[用]?(?P<lang>\w+?[文语])\w*?(?:说|讲|表达|表示)'
|
re.compile('.*[用]?(?P<lang>\w+?[文语])\w*?(?:说|讲|表达|表示)'
|
||||||
|
Loading…
Reference in New Issue
Block a user