Пример #1
0
import json

import requests
from lxml import etree

from command import CommandRegistry
from commands import core

__registry__ = cr = CommandRegistry()


@cr.register('ip')
def ip(args_text, ctx_msg):
    query = args_text.strip()
    if not query:
        core.echo('请指定要查询的 IP 或域名', ctx_msg)
        return

    core.echo('正在查询,请稍等……', ctx_msg)

    chinaz_url = 'http://ip.chinaz.com/%s'
    ipcn_url = 'http://ip.cn/?ip=%s'
    ipipnet_url = 'http://freeapi.ipip.net/%s'

    found = False

    # Get data from ChinaZ.com
    resp = requests.get(chinaz_url % query)
    if resp.status_code == 200:
        html = etree.HTML(resp.text)
        p_elems = html.xpath('//p[@class="WhwtdWrap bor-b1s col-gray03"]')
Пример #2
0
from command import CommandRegistry
from commands import core
from nl_processor import parse_potential_commands
from little_shit import load_plugins, get_fallback_command_after_nl_processors
from command import hub as cmdhub


def _init():
    load_plugins('nl_processors')


__registry__ = cr = CommandRegistry(init_func=_init)

_fallback_command = get_fallback_command_after_nl_processors()


@cr.register('process')
@cr.restrict(full_command_only=True)
def process(args_text, ctx_msg):
    sentence = args_text.strip()
    if not sentence:
        core.echo('你什么都没说哦~', ctx_msg)
        return

    potential_commands = parse_potential_commands(sentence)
    potential_commands = sorted(filter(lambda x: x[0] > 60, potential_commands), key=lambda x: x[0], reverse=True)
    # If it's a fallback and with empty start flag, then don't send verbose information
    hide_verbose = ctx_msg.get('is_fallback') and ctx_msg.get('start_flag') == ''
    if len(potential_commands) > 0:
        most_possible_cmd = potential_commands[0]
        core.echo(