Git Product home page Git Product logo

bbot's Introduction

BearyBot

一个用在 BearyChat 中的辅助用机器人.

安装

下载本项目代码后,通过 setup.py 来安装:

python setup.py install

或者直接从 github 上安装:

sudo pip install git+https://github.com/Linusp/bbot.git

设置和使用

命令行工具 bbot 使用:

usage: bbot [-h] [-w WORD] [-p PORT]

Start a BearyBot

optional arguments:
  -h, --help            show this help message and exit
  -w WORD, --word WORD  Set trigger word of bot.
  -p PORT, --port PORT  Set port the bot listen, default value is 7428

该命令行工具即集成了两个命令,分别是:

  • /gif: 使用 Giphy API 搜索 gif 图片
  • /img: 使用 Google 搜索图片 (Google 图像搜索 API 已失效)
  • /talk: 聊天

聊天功能使用的是图灵机器人,需要获取相应的 API KEY,将你的 API KEY 写到 HOME 目录下的 .botrc 中去,以 json 格式保存,如:

{
    "turing_bot_key": "sldkfjklsdjf299rejkldjf9"
}

当然你也可以自定义自己的机器人,通过向中心控制模块注册更多的命令响应方法来集成更丰富的功能

from bearybot import BearyBot, Controller

def you_proc(paras, info):
    """description

    :type paras: str
    :param paras: parameter

    :type info: dict
    :param info: internal parameters
    """
    # do something
    # ......
    return {
        '<key>': <content>,
    }


controller = Controller()
controller.register('/new_command', you_proc) # 使用 /new_command 作为 命令

bot = BearyBot('@bot', controller) # 使用 '@bot' 作为触发词
bot.run()

注册新的命令响应方法时有以下几点要注意:

  1. paras 参数是一个 str,包含给自定义命令的参数

    中心控制模块会在得到输入后,去除触发词和命令本身后,将剩下的字符串用来做为命令响应方法的参数。

  2. info 参数是一些内部参数,包含 POST 请求中的请求参数,以及本地的一些配置
  3. 返回结果必须是一个 dict,如果返回结果是文本,那么就返回 {'text': <result>}
  4. 中心控制模块内置了三个命令,通过用相同命令名来注册不同的方法,可以覆盖内置的这三个命令的响应方法。
  5. 通过 Controller.set_default 方法可以设置无命令词时的默认处理方法

bbot's People

Contributors

linusp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.