ubot

package module
v0.0.0-...-095811d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: BSD-3-Clause Imports: 17 Imported by: 1

README

About UBot

UBot is an open source platform for developing chat bots. It provides consistent apis for different platforms (telegram, discord and more!) in a language-independent way, making bot development WORA-able (Write once, Run anywhere).

About UBot.Common.Go

This library provides a lot of helper functions for writing UBot Components (Account / App).

Usage

import (
	ubot "github.com/UBotPlatform/UBot.Common.Go"
)

License

This library is licensed under BSD 3-Clause License.
Please see LICENSE for licensing details.
You can use TLDRLegal to see a summary first. (!!!NOT LEGAL ADVICE!!!)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MsgTypePattern = regexp.MustCompile(`^[a-z0-9_\.]+$`)

Functions

func AssertNoError

func AssertNoError(err error)

func DialRouter

func DialRouter(operator string, urlStr string, registerClient ClientRegistrar) (*websocket.Conn, error)

func HostAccount

func HostAccount(id string, creater func(*AccountEventEmitter) *Account) error

func HostApp

func HostApp(id string, creater func(*AppApi) *App) error

func HostClient

func HostClient(registerClient ClientRegistrar, configRPC RPCConfigurator) error

func IsValidMsgType

func IsValidMsgType(msgType string) bool

Types

type Account

type Account struct {
	GetGroupName    func(id string) (string, error)
	GetUserName     func(id string) (string, error)
	SendChatMessage func(msgType MsgType, source string, target string, message string) error
	RemoveMember    func(source string, target string) error
	ShutupMember    func(source string, target string, duration int) error
	ShutupAllMember func(source string, shutupSwitch bool) error
	GetMemberName   func(source string, target string) (string, error)
	GetUserAvatar   func(id string) (string, error)
	GetSelfID       func() (string, error)
	GetPlatformID   func() (string, error)
	GetGroupList    func() ([]string, error)
	GetMemberList   func(id string) ([]string, error)
}

func (*Account) Register

func (a *Account) Register(rpc *wsrpc.WebsocketRPC)

type AccountEventEmitter

type AccountEventEmitter struct {
	OnReceiveChatMessage     func(msgType MsgType, source string, sender string, message string, info MsgInfo) error
	OnMemberJoined           func(source string, sender string, inviter string) error
	OnMemberLeft             func(source string, sender string) error
	ProcessGroupInvitation   func(sender string, target string, reason string) (EventResultType, *string, error)
	ProcessFriendRequest     func(sender string, reason string) (EventResultType, *string, error)
	ProcessMembershipRequest func(source string, sender string, inviter string, reason string) (EventResultType, *string, error)
}

func (*AccountEventEmitter) Get

func (a *AccountEventEmitter) Get(rpcConn *wsrpc.WebsocketRPCConn)

type App

type App struct {
	OnReceiveChatMessage     func(bot string, msgType MsgType, source string, sender string, message string, info MsgInfo) (EventResultType, error)
	OnMemberJoined           func(bot string, source string, sender string, inviter string) (EventResultType, error)
	OnMemberLeft             func(bot string, source string, sender string) (EventResultType, error)
	ProcessGroupInvitation   func(bot string, sender string, target string, reason string) (EventResultType, *string, error)
	ProcessFriendRequest     func(bot string, sender string, reason string) (EventResultType, *string, error)
	ProcessMembershipRequest func(bot string, source string, sender string, inviter string, reason string) (EventResultType, *string, error)
}

func (*App) Register

func (a *App) Register(rpc *wsrpc.WebsocketRPC)

type AppApi

type AppApi struct {
	GetGroupName    func(bot string, id string) (string, error)
	GetUserName     func(bot string, id string) (string, error)
	SendChatMessage func(bot string, msgType MsgType, source string, target string, message string) error
	RemoveMember    func(bot string, source string, target string) error
	ShutupMember    func(bot string, source string, target string, duration int) error
	ShutupAllMember func(bot string, source string, shutupSwitch bool) error
	GetMemberName   func(bot string, source string, target string) (string, error)
	GetUserAvatar   func(bot string, id string) (string, error)
	GetSelfID       func(bot string) (string, error)
	GetPlatformID   func(bot string) (string, error)
	GetGroupList    func(bot string) ([]string, error)
	GetMemberList   func(bot string, id string) ([]string, error)
	GetBotList      func() ([]string, error)
}

func (*AppApi) Get

func (a *AppApi) Get(rpcConn *wsrpc.WebsocketRPCConn)

type ClientRegistrar

type ClientRegistrar func(managerUrl *url.URL, manager *Manager) (string, error)

type EventResultType

type EventResultType int
const AcceptRequest EventResultType = 10
const CompleteEvent EventResultType = 2
const ContinueEvent EventResultType = 1
const IgnoreEvent EventResultType = 0
const RejectRequest EventResultType = 20

type Manager

type Manager struct {
	RegisterApp     func(id string) (string, error)
	RegisterAccount func(id string) (string, error)
}

func (*Manager) Get

func (a *Manager) Get(rpcConn *wsrpc.WebsocketRPCConn)

type MsgBuilder

type MsgBuilder struct {
	// contains filtered or unexported fields
}

func (*MsgBuilder) String

func (b *MsgBuilder) String() string

func (*MsgBuilder) WriteEntity

func (b *MsgBuilder) WriteEntity(e MsgEntity) *MsgBuilder

func (*MsgBuilder) WriteRaw

func (b *MsgBuilder) WriteRaw(s []byte) *MsgBuilder

func (*MsgBuilder) WriteRawString

func (b *MsgBuilder) WriteRawString(s string) *MsgBuilder

func (*MsgBuilder) WriteString

func (b *MsgBuilder) WriteString(s string) *MsgBuilder

WriteString is similar to writeArgString

type MsgEntity

type MsgEntity struct {
	Type      string
	Args      []string
	NamedArgs map[string]string
}

func ParseMsg

func ParseMsg(content string) []MsgEntity

func (*MsgEntity) ArgOr

func (e *MsgEntity) ArgOr(i int, defaultValue string) string

func (*MsgEntity) FirstArgOrEmpty

func (e *MsgEntity) FirstArgOrEmpty() string

func (*MsgEntity) NamedArgOr

func (e *MsgEntity) NamedArgOr(name string, defaultValue string) string

type MsgInfo

type MsgInfo struct {
	ID string `json:"id"`
}

type MsgType

type MsgType int
const GroupMsg MsgType = 0
const PrivateMsg MsgType = 1

type RPCConfigurator

type RPCConfigurator func(rpc *wsrpc.WebsocketRPC, rpcConn *wsrpc.WebsocketRPCConn) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL