Giter Site home page Giter Site logo

ghaoo / rboot Goto Github PK

View Code? Open in Web Editor NEW
68.0 3.0 16.0 407 KB

Rboot 是一个Go语言开发的一个简单、高效的 Chatops bot 框架

License: MIT License

Go 97.96% Batchfile 0.02% Shell 1.71% PHP 0.22% Python 0.09%
chatops chatbot bot chatops-bot

rboot's Introduction

Rboot

Build Status Go Report Card GitHub go.mod Go version GoDoc

rboot 是一个使用 golang 写的,简单、高效的聊天机器人框架,易于扩展,它可以工作在不同的聊天服务上,并通过扩展脚本可实现 聊天工作助手服务监控警报触发 等功能。

golang版本需求

golang v1.13+

快速创建自己的机器人

$ go get github.com/ghaoo/rboot
$ cd $GOPATH/github.com/ghaoo/rboot/robot
$ go build
$ ./robot

关于消息转接器

消息转接器是用来监听消息的传入和传出,通过消息转接器可以将聊天客户端的消息发送到机器人,经过脚本处理后返回消息发送给客户端。

rboot 提供了 命令行cli 微信网页版 企业微信 钉钉 倍洽 聊天转接器的简单实现。

关于插件

Plugin 并没有提供太多开箱即用的插件,除了一个help插件,其他的需要开发者根据自己的需求去开发。

help插件用法

!help <plugin>:查看插件帮助信息,当命令不带插件名称时会列出所有插件帮助信息,带插件名称只列出此插件的帮助信息。

使用golang编写插件

在文件夹 robot/plugins 下有简单的插件案例,开发者可查看插件编写方法。

使用其他语言编写插件

Plugin 不仅可以使用golang编写插件,也可以使用脚本插件来执行系统命令或使用脚本语言编写的插件文件。

脚本插件是用来解析脚本语言的Plugin插件,它是rboot插件的一个扩展。通过yaml配置文件来执行系统命令或脚本。

因为脚本插件是建立在Plugin基础之上的,每个脚本都会被注册到Plugin之中,所以确保插件之间名称不要重叠,否则可能先注册的插件会被后注册的插件替换!

如何编写脚本插件

配置
  • PLUGIN_DIR:脚本插件配置文件存放的文件夹,若不配置默认为scripts
快速开始

我们可以通过创建一个yaml文件来创建一个脚本插件,通过文件中的配置选项来实现对脚本插件的配置。比如我们创建一个 hello.yml 文件,它的内容如下:

name: hello
version: 0.1.0
ruleset:
    hello: "^hello"
usage:
    hi: echo hello world and 你好
description: 脚本插件示例
command:
    -
        cmd:
            - echo hi
            - echo hello world
    -
        dir: plugins
        cmd:
            - echo 你好

这个插件使用的是系统命令 echo。它的意思是:当我们输入“hello”后,脚本会返回 hihello world你好 三条信息。

配置中各个字段的含义:

配置 必须 意义
name 插件名称
ruleset 规则集合
version 插件版本
usage 插件用法
description 插件简介
command 插件命令集
--- --- ---
dir 命令执行文件夹
cmd 插件命令

command可配置多个命令集,执行顺序为从上到下依次执行

cmd可配置多条命令,执行顺序为从上到下依次执行

脚本插件支持系统命令脚本语言。系统命令模式如上面的hello.yml,只需在文件中填写文件夹和系统命令,当你发出命令后,机器人就会从上到下依次执行。

脚本语言是建立在系统命令模式之上的执行方式,我们可以使用系统命令调用语言脚本,从而执行比较复杂的脚本。比如我们使用python输出“hello robot”。

我们的python脚本如下:

#!/usr/bin/env python

print("Hello, robot! i am a python script")

我们的配置文件如下:

name: pyscript
version: 0.1.0
ruleset:
    py: "^hello python"
usage:
    py: execute python script
description: python插件示例
command:
        dir: script
        cmd:
            - ./hello.py

当我们输入 hello python 时,机器人会调用 hello.py 脚本,脚本输出"Hello, robot! i am a python script"并通过机器人展示给我们。

在不同操作系统下请确认 目录分隔符 是否符合当前系统设置。 windows 下请使用 \ unix 下请使用 /

文档

Rboot

GoDoc

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

rboot's People

Contributors

ghaoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rboot's Issues

变量怎么传呢

请问一下,我想执行脚本的时候传参数,有没有办法实现呢。接受消息的时候有没有办法吧参数接受过来呢

.env

配置了.env 文件不生效

脚本支持传入参数

脚本类型的插件怎么支持获取用户传入参数呢?
看了一下注册的脚本的runcommand方法.参数是从yaml文件中获取的.也就是只能写死在yaml文件中.
能否象plugin一样从 incoming message["args"] 中获取呢

Potential import collision: import path should be "gopkg.in/yaml.v2", not "github.com/go-yaml/yaml".

Background

The go-yaml/yaml has already renamed it’s import path from "github.com/go-yaml/yaml" to "gopkg.in/yaml.v2".
As README of go-yaml/yaml v2.1.0 said, downstream repos should use "gopkg.in/yaml.v2" to get or import go-yaml/yaml.

Example
Some more examples can be found in the "examples" folder.

package main
import (
        "fmt"
        "log"
        "gopkg.in/yaml.v2"
)
…

But ghaoo/rboot still used the old path:
https://github.com/ghaoo/rboot/blob/master/go.mod#L11

github.com/go-yaml/yaml v2.1.0+incompatible 

When you use the old path "github.com/go-yaml/yaml" to import the go-yaml/yaml, it will be very easy to reintroduce go-yaml/yaml through the import statements "import gopkg.in/yaml.v2" in the go source file of go-yaml/yaml.
https://github.com/go-yaml/yaml/blob/v2.1.0/decode_test.go#L12

package yaml_test
import (
	…
	. "gopkg.in/check.v1"
	"gopkg.in/yaml.v2"
)

The "gopkg.in/yaml.v2" and "github.com/go-yaml/yaml" are the same repos. This will work in isolation, bring about potential risks and problems.
So, why not get rid of the old import path "github.com/go-yaml/yaml", use "gopkg.in/yaml.v2" instead.

Solution

Replace all the old import paths, change "github.com/go-yaml/yaml" to "gopkg.in/yaml.v2".
Where did you import it: https://github.com/ghaoo/rboot/search?q=github.com%2Fgo-yaml%2Fyaml&unscoped_q=github.com%2Fgo-yaml%2Fyaml

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.