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