Coder Social home page Coder Social logo

nanobot-test's Introduction

东云名乃

NanoBot

类 ZeroBot 的官方 QQ 频道适配器


Instructions

Note: This framework is built mainly for Chinese users thus may display hard-coded Chinese prompts during the interaction.

参见 QQ 官方文档

快速开始(基于插件)

查看example文件夹以获取更多信息

开始响应 服务列表 查看用法

启用禁用

package main

import (
	_ "github.com/fumiama/NanoBot/example/echo"

	nano "github.com/fumiama/NanoBot"
	log "github.com/sirupsen/logrus"
)

func main() {
	log.SetLevel(log.DebugLevel)
	nano.OpenAPI = nano.SandboxAPI
	nano.OnMessageFullMatch("help").SetBlock(true).
		Handle(func(ctx *nano.Ctx) {
			_, _ = ctx.SendPlainMessage(false, "echo string")
		})
	nano.Run(nil, &nano.Bot{
		AppID:      "你的AppID",
		Token:      "你的Token",
		Secret:     "你的Secret, 目前没用到, 可以不填",
		Intents:    nano.IntentPublic,
		SuperUsers: []string{"用户ID1", "用户ID2"},
	})
}

更多选择(传统的事件驱动)

如果声明了 Handler, 所有插件将被禁用

event-based example

package main

import (
	"strings"

	nano "github.com/fumiama/NanoBot"
	log "github.com/sirupsen/logrus"
)

func main() {
	log.SetLevel(log.DebugLevel)
	nano.OpenAPI = nano.SandboxAPI
	nano.Run(nil, &nano.Bot{
		AppID:   "你的AppID",
		Token:   "你的Token",
		Secret:  "你的Secret, 目前没用到, 可以不填",
		Intents: nano.IntentPublic,
		Handler: &nano.Handler{
			OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) {
				u := ""
				if len(d.Attachments) > 0 {
					u = d.Attachments[0].URL
					if !strings.HasPrefix(u, "http") {
						u = "http://" + u
					}
				}
				_, err := bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
					Content:        "您发送了: " + d.Content,
					Image:          u,
					ReplyMessageID: d.ID,
					MessageReference: &nano.MessageReference{
						MessageID: d.ID,
					},
				})
				if err != nil {
					bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{
						Content:        "[ERROR]: " + err.Error(),
						ReplyMessageID: d.ID,
					})
				}
			},
		},
	})
}

Thanks

nanobot-test's People

Contributors

fumiama avatar bat-chatillon25t 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.