chatbot

package
v0.1.99 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileTypeShellScript - shell script
	FileTypeShellScript = "text/x-script.sh"
	// FileTypePhoto - photo
	FileTypePhoto = "photo/jpeg"
	// FileExcel - excel
	FileExcel = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
View Source
const (
	// PluginTypeNormal - normal plugin
	PluginTypeNormal = 0
	// PluginTypeCommand - command plugin
	PluginTypeCommand = 1
	// PluginTypeWritableCommand - writable command plugin
	PluginTypeWritableCommand = 2
)

Variables

View Source
var (
	// ErrRepeatPlugins - The plugins repeat
	ErrRepeatPlugins = errors.New("The plugins repeat")
	// ErrPluginsEmpty - No plugins
	ErrPluginsEmpty = errors.New("No plugins")
	// ErrRepeatUserID - The userid repeat
	ErrRepeatUserID = errors.New("The userid repeat")
	// ErrMsgNoFrom - Message no from
	ErrMsgNoFrom = errors.New("Message no from")
	// ErrConfigFile - Can't load config file
	ErrConfigFile = errors.New("Can't load config file")
	// ErrInvalidConfigFile - Invalid config file
	ErrInvalidConfigFile = errors.New("Invalid config file")
	// ErrInvalidConfigCfgPath - Invalid config cfgpath
	ErrInvalidConfigCfgPath = errors.New("Invalid config cfgpath")
	// ErrInvalidConfigDownloadPath - Invalid config downloadpath
	ErrInvalidConfigDownloadPath = errors.New("Invalid config downloadpath")
	// ErrInvalidConfigAnkaDB - Invalid config ankaDB
	ErrInvalidConfigAnkaDB = errors.New("Invalid config ankaDB")
	// ErrSameOption - Same option
	ErrSameOption = errors.New("Same option")
	// ErrEmptyOption - Empty option
	ErrEmptyOption = errors.New("Empty option")
	// ErrAlreadySelected - Already selected
	ErrAlreadySelected = errors.New("Already selected")
	// ErrInvalidOption - Invalid option
	ErrInvalidOption = errors.New("Invalid option")
	// ErrInvalidMessageTo - Invalid Message.To
	ErrInvalidMessageTo = errors.New("Invalid Message.To")
	// ErrSameMsgCallback - Same msgcallback
	ErrSameMsgCallback = errors.New("Same msgcallback")
	// ErrNoMsgCallback - Can't find msgcallback
	ErrNoMsgCallback = errors.New("Can't find msgcallback")
	// ErrInvalidPluginType - Invalid plugin type
	ErrInvalidPluginType = errors.New("Invalid plugin type")
	// ErrSameJarvisMsgCallback - Same jarvismsgcallback
	ErrSameJarvisMsgCallback = errors.New("Same jarvismsgcallback")
	// ErrNoJarvisMsgCallback - Can't find jarvismsgcallback
	ErrNoJarvisMsgCallback = errors.New("Can't find jarvismsgcallback")
	// ErrEmptyMsgText - Empty message text
	ErrEmptyMsgText = errors.New("Empty message text")
	// ErrInvalidEventID - Invalid eventid
	ErrInvalidEventID = errors.New("Invalid eventid")
	// ErrSamePluginName - Same plugin name
	ErrSamePluginName = errors.New("Same plugin name")
	// ErrNoPluginName - No plugin name
	ErrNoPluginName = errors.New("No plugin name")
	// ErrNoCommand - No command
	ErrNoCommand = errors.New("No command")
	// ErrInvalidCommandLineItemNums - Invalid command line item nums
	ErrInvalidCommandLineItemNums = errors.New("Invalid command line item nums")
	// ErrMsgNotMine - This message should not be processed by me
	ErrMsgNotMine = errors.New("This message should not be processed by me")
	// ErrInvalidCommandLine - Invalid command line
	ErrInvalidCommandLine = errors.New("Invalid command line")
	// ErrNoJarvisNode - Can't find jarvisnode
	ErrNoJarvisNode = errors.New("Can't find jarvisnode")
	// ErrInvalidParamsNoCurPlugin - Invalid params: no current plugin
	ErrInvalidParamsNoCurPlugin = errors.New("Invalid params: no current plugin")
	// ErrInvalidParamsInvalidCurPlugin - Invalid params: invalid current plugin
	ErrInvalidParamsInvalidCurPlugin = errors.New("Invalid params: invalid current plugin")
	// ErrEmptyArray - Empty array
	ErrEmptyArray = errors.New("Empty array")
)
View Source
var (
	// EventOnStarted - started
	EventOnStarted = "started"

	// UserEventOnChgUserScript - chguserscript
	UserEventOnChgUserScript = "chguserscript"
	// UserEventOnChgUserFileTemplate - chguserfiletemplate
	UserEventOnChgUserFileTemplate = "chguserfiletemplate"
)

Functions

func Array2xlsx added in v0.1.99

func Array2xlsx(arr []interface{}) ([]byte, error)

Array2xlsx - array to xlsx

func ArrayMap2xlsx added in v0.1.99

func ArrayMap2xlsx(arr [](map[string]interface{})) ([]byte, error)

ArrayMap2xlsx - array to xlsx

func Debug

func Debug(message string, fields ...zap.Field)

Debug logs a debug message with the given fields

func Error

func Error(message string, fields ...zap.Field)

Error logs a debug message with the given fields

func Fatal

func Fatal(message string, fields ...zap.Field)

Fatal logs a message than calls os.Exit(1)

func FormatJSON

func FormatJSON(str string) (string, error)

FormatJSON - format JSON string

func FormatJSONObj

func FormatJSONObj(obj interface{}) (string, error)

FormatJSONObj - format JSON string

func GetFileNameFromFullPath added in v0.1.5

func GetFileNameFromFullPath(fullname string) string

GetFileNameFromFullPath - get filename from fullpathfilname

func GetFileNameFromFullPathNoExt added in v0.1.5

func GetFileNameFromFullPathNoExt(fullname string) string

GetFileNameFromFullPathNoExt - get filename from fullpathfilname

func GetMD5String added in v0.1.5

func GetMD5String(buf []byte) string

GetMD5String - md5 buf and return string

func Info

func Info(message string, fields ...zap.Field)

Info logs a debug message with the given fields

func InitLogger

func InitLogger(level zapcore.Level, isConsole bool, logpath string)

InitLogger - initializes a thread-safe singleton logger

func JSON

func JSON(key string, obj interface{}) zap.Field

JSON - make json to field

func MakeChatID

func MakeChatID(userid string, msgid string) string

MakeChatID - make chatid

func MakeJarvisMsgCallbackID

func MakeJarvisMsgCallbackID(destAddr string, ctrlid int64) string

MakeJarvisMsgCallbackID - make callbackid with jarvisMsgCallback

func NewEmptyCommandLine added in v0.1.99

func NewEmptyCommandLine(cmd string) proto.Message

NewEmptyCommandLine - new EmptyMessage

func SendFileMsg added in v0.1.5

func SendFileMsg(bot ChatBot, user User, fd *chatbotdbpb.File) error

SendFileMsg - sendmsg

func SendMsgWithOptions

func SendMsgWithOptions(bot ChatBot, user User, text string, options []string, callback FuncMsgCallback) error

SendMsgWithOptions - send msg with options

func SendTextMsg

func SendTextMsg(bot ChatBot, user User, text string, srcmsg Message) error

SendTextMsg - sendmsg

func SyncLogger

func SyncLogger()

SyncLogger - sync logger

func Warn

func Warn(message string, fields ...zap.Field)

Warn logs a debug message with the given fields

func Xlsx2ArrayMap added in v0.1.99

func Xlsx2ArrayMap(data []byte) ([](map[string]interface{}), error)

Xlsx2ArrayMap - xlsx to array, everything is string

Types

type BasicChatBot

type BasicChatBot struct {
	DB         *chatbotdb.ChatBotDB
	Node       jarviscore.JarvisNode
	MgrPlugins PluginsMgr
	Config     *Config
	MgrUser    UserMgr
	// contains filtered or unexported fields
}

BasicChatBot - base chatbot

func NewBasicChatBot

func NewBasicChatBot() *BasicChatBot

NewBasicChatBot - new BasicChatBot

func (*BasicChatBot) AddJarvisMsgCallback

func (base *BasicChatBot) AddJarvisMsgCallback(destAddr string, ctrlid int64, callback FuncJarvisMsgCallback) error

AddJarvisMsgCallback - add jarvisMsgCallback

func (*BasicChatBot) AddMsgCallback

func (base *BasicChatBot) AddMsgCallback(msg Message, callback FuncMsgCallback) error

AddMsgCallback - add msgCallback

func (*BasicChatBot) DelJarvisMsgCallback

func (base *BasicChatBot) DelJarvisMsgCallback(destAddr string, ctrlid int64) error

DelJarvisMsgCallback - del jarvisMsgCallback

func (*BasicChatBot) DelMsgCallback

func (base *BasicChatBot) DelMsgCallback(chatid string) error

DelMsgCallback - del msgCallback

func (*BasicChatBot) GetChatBotDB

func (base *BasicChatBot) GetChatBotDB() *chatbotdb.ChatBotDB

GetChatBotDB - get ChatBotDB

func (*BasicChatBot) GetConfig

func (base *BasicChatBot) GetConfig() *Config

GetConfig - get Config

func (*BasicChatBot) GetFileTemplatesMgr added in v0.1.41

func (base *BasicChatBot) GetFileTemplatesMgr() *FileTemplatesMgr

GetFileTemplatesMgr - get user file template manager

func (*BasicChatBot) GetJarvisNode

func (base *BasicChatBot) GetJarvisNode() jarviscore.JarvisNode

GetJarvisNode - get jarvis node

func (*BasicChatBot) GetJarvisNodeCoreDB

func (base *BasicChatBot) GetJarvisNodeCoreDB() *jarviscore.CoreDB

GetJarvisNodeCoreDB - get jarvis node coredb

func (*BasicChatBot) GetMaster added in v0.1.2

func (base *BasicChatBot) GetMaster() User

GetMaster - get master

func (*BasicChatBot) GetPluginsMgr added in v0.1.36

func (base *BasicChatBot) GetPluginsMgr() PluginsMgr

GetPluginsMgr - get plugins manager

func (*BasicChatBot) GetUser

func (base *BasicChatBot) GetUser(userid string) (User, error)

GetUser - get user with userid

func (*BasicChatBot) GetUserMgr

func (base *BasicChatBot) GetUserMgr() UserMgr

GetUserMgr - get user manager

func (*BasicChatBot) GetUserScriptsMgr added in v0.1.36

func (base *BasicChatBot) GetUserScriptsMgr() *UserScriptsMgr

GetUserScriptsMgr - get user scripts manager

func (*BasicChatBot) GetUserWithUserName added in v0.1.2

func (base *BasicChatBot) GetUserWithUserName(username string) (User, error)

GetUserWithUserName - get user with user name

func (*BasicChatBot) GetVersion

func (base *BasicChatBot) GetVersion() string

GetVersion - get version

func (*BasicChatBot) Init

func (base *BasicChatBot) Init(cfgfilename string, mgr PluginsMgr) error

Init - init

func (*BasicChatBot) IsMaster

func (base *BasicChatBot) IsMaster(user User) bool

IsMaster - is master

func (*BasicChatBot) NewUserFromProto

func (base *BasicChatBot) NewUserFromProto(user *chatbotdbpb.User) User

NewUserFromProto - new user from proto

func (*BasicChatBot) OnEvent added in v0.1.2

func (base *BasicChatBot) OnEvent(ctx context.Context, chatbot ChatBot, eventid string) error

OnEvent - on event

func (*BasicChatBot) OnUserEvent added in v0.1.36

func (base *BasicChatBot) OnUserEvent(ctx context.Context, chatbot ChatBot, eventid string, userID string) error

OnUserEvent - on event

func (*BasicChatBot) ProcJarvisMsgCallback

func (base *BasicChatBot) ProcJarvisMsgCallback(ctx context.Context, msg *jarviscorepb.JarvisMsg) error

ProcJarvisMsgCallback - proc jarvisMsgCallback

func (*BasicChatBot) ProcMsgCallback

func (base *BasicChatBot) ProcMsgCallback(ctx context.Context, msg Message, id int) error

ProcMsgCallback - proc msgCallback

func (*BasicChatBot) RegEventFunc added in v0.1.2

func (base *BasicChatBot) RegEventFunc(eventid string, eventfunc FuncEvent) error

RegEventFunc - reg event

func (*BasicChatBot) RegUserEventFunc added in v0.1.36

func (base *BasicChatBot) RegUserEventFunc(eventid string, eventfunc FuncUserEvent) error

RegUserEventFunc - reg event

func (*BasicChatBot) SaveMsg

func (base *BasicChatBot) SaveMsg(msg Message) error

SaveMsg - save message

func (*BasicChatBot) SetMaster added in v0.1.2

func (base *BasicChatBot) SetMaster(userid string, username string)

SetMaster - set master, you can only set userid or username

func (*BasicChatBot) Start

func (base *BasicChatBot) Start(ctx context.Context, node jarviscore.JarvisNode) error

Start - start chatbot

type BasicMessage

type BasicMessage struct {
	Options    []*MsgOption
	IDSelected int
	File       *chatbotdbpb.File
}

BasicMessage - basic Message

func (*BasicMessage) AddOption

func (msg *BasicMessage) AddOption(text string) (int, error)

AddOption - add option

func (*BasicMessage) GetFile

func (msg *BasicMessage) GetFile() *chatbotdbpb.File

GetFile - get file

func (*BasicMessage) GetOption

func (msg *BasicMessage) GetOption(id int) string

GetOption - get option

func (*BasicMessage) GetSelected

func (msg *BasicMessage) GetSelected() int

GetSelected - get selected

func (*BasicMessage) HasOptions

func (msg *BasicMessage) HasOptions() bool

HasOptions - has any options

func (*BasicMessage) SelectOption

func (msg *BasicMessage) SelectOption(id int) error

SelectOption - select option

func (*BasicMessage) SetFile

func (msg *BasicMessage) SetFile(file *chatbotdbpb.File)

SetFile - set file

func (*BasicMessage) ToProto

func (msg *BasicMessage) ToProto() *chatbotdbpb.Message

ToProto - to proto message

type BasicUser

type BasicUser struct {
	User *chatbotdbpb.User
}

BasicUser - basic User

func NewBasicUser

func NewBasicUser(username string, userid string, nickname string, lastMsgID int64) *BasicUser

NewBasicUser - new BasicUser

func (*BasicUser) GetLastMsgID

func (bu *BasicUser) GetLastMsgID() int64

GetLastMsgID - get lastMsgID

func (*BasicUser) GetNickName

func (bu *BasicUser) GetNickName() string

GetNickName - get nickname, composed of first name and last name

func (*BasicUser) GetUserID

func (bu *BasicUser) GetUserID() string

GetUserID - get uid, uid is unique

func (*BasicUser) GetUserName

func (bu *BasicUser) GetUserName() string

GetUserName - get username

func (*BasicUser) ToProto

func (bu *BasicUser) ToProto() *chatbotdbpb.User

ToProto - to proto user

func (*BasicUser) UpdLastMsgID

func (bu *BasicUser) UpdLastMsgID(lastmsgid int64)

UpdLastMsgID - update lastMsgID

type BasicUserMgr

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

BasicUserMgr - default UserMgr

func NewBasicUserMgr

func NewBasicUserMgr() *BasicUserMgr

NewBasicUserMgr - new BasicUserMgr

func (*BasicUserMgr) AddUser

func (mgr *BasicUserMgr) AddUser(user User) error

AddUser - add user

func (*BasicUserMgr) GetMasterUserID added in v0.1.2

func (mgr *BasicUserMgr) GetMasterUserID() string

GetMasterUserID - get master userid

func (*BasicUserMgr) GetMasterUserName added in v0.1.2

func (mgr *BasicUserMgr) GetMasterUserName() string

GetMasterUserName - get master username

func (*BasicUserMgr) GetUser

func (mgr *BasicUserMgr) GetUser(uid string) User

GetUser - get user with userid

func (*BasicUserMgr) IsMaster added in v0.1.2

func (mgr *BasicUserMgr) IsMaster(user User) bool

IsMaster - is master

func (*BasicUserMgr) SetMaster added in v0.1.2

func (mgr *BasicUserMgr) SetMaster(userid string, username string)

SetMaster - set master, you can only set userid or username

type ChatBot

type ChatBot interface {
	// Init -
	Init(cfgfilename string, mgr PluginsMgr) error
	// Start -
	Start(ctx context.Context, node jarviscore.JarvisNode) error
	// SendMsg -
	SendMsg(msg Message) (Message, error)
	// SaveMsg -
	SaveMsg(msg Message) error
	// NewMsg -
	NewMsg(chatid string, msgid string, from User, to User, text string, curtime int64) Message
	// NewMsgFromProto -
	NewMsgFromProto(msg *chatbotdbpb.Message) Message
	// GetMsg -
	GetMsg(chatid string) (Message, error)
	// GetPluginsMgr - get plugins manager
	GetPluginsMgr() PluginsMgr
	// GetUserScriptsMgr - get user scripts manager
	GetUserScriptsMgr() *UserScriptsMgr
	// GetFileTemplatesMgr - get user file template manager
	GetFileTemplatesMgr() *FileTemplatesMgr

	// GetJarvisNodeCoreDB - get jarvis node coredb
	GetJarvisNodeCoreDB() *jarviscore.CoreDB
	// GetJarvisNode - get jarvis node
	GetJarvisNode() jarviscore.JarvisNode

	// GetConfig - get Config
	GetConfig() *Config
	// GetChatBotDB - get ChatBotDB
	GetChatBotDB() *chatbotdb.ChatBotDB

	// IsMaster - is master
	IsMaster(user User) bool
	// GetUserMgr - get user manager
	GetUserMgr() UserMgr
	// NewUserFromProto - new user from proto
	NewUserFromProto(user *chatbotdbpb.User) User
	// GetUser - get user with userid
	GetUser(userid string) (User, error)
	// GetUserWithUserName - get user with user name
	GetUserWithUserName(username string) (User, error)
	// GetMaster - get master
	GetMaster() User
	// SetMaster - set master, you can only set userid or username
	SetMaster(userid string, username string)

	// OnJarvisCtrlResult - event handle
	OnJarvisCtrlResult(ctx context.Context, msg *jarviscorepb.JarvisMsg) error

	// AddMsgCallback - add msgCallback
	AddMsgCallback(msg Message, callback FuncMsgCallback) error
	// ProcMsgCallback - proc msgCallback
	ProcMsgCallback(ctx context.Context, msg Message, id int) error
	// DelMsgCallback - del msgCallback
	DelMsgCallback(chatid string) error

	// AddJarvisMsgCallback - add jarvisMsgCallback
	AddJarvisMsgCallback(destAddr string, ctrlid int64, callback FuncJarvisMsgCallback) error
	// ProcJarvisMsgCallback - proc jarvisMsgCallback
	ProcJarvisMsgCallback(ctx context.Context, msg *jarviscorepb.JarvisMsg) error
	// DelJarvisMsgCallback - del jarvisMsgCallback
	DelJarvisMsgCallback(destAddr string, ctrlid int64) error

	// GetVersion - get version
	GetVersion() string

	// // NewEventMgr - new EventMgr
	// //	Because chatbot is an interface that is not fully implemented,
	// //	it can only be implemented like this.
	// NewEventMgr(chatbot ChatBot)
	// RegEventFunc - reg event
	RegEventFunc(eventid string, eventfunc FuncEvent) error
	// OnEvent - on event
	OnEvent(ctx context.Context, chatbot ChatBot, eventid string) error
	// RegUserEventFunc - reg event
	RegUserEventFunc(eventid string, eventfunc FuncUserEvent) error
	// OnUserEvent - on event
	OnUserEvent(ctx context.Context, chatbot ChatBot, eventid string, userID string) error
}

ChatBot - chat bot interface

type Command added in v0.1.36

type Command interface {
	// // Parse - parse command line
	// Parse(lstcmdfield []string) (proto.Message, error)
	// RunCommand - run command
	RunCommand(ctx context.Context, params *MessageParams) bool
	// ParseCommandLine - parse command line
	ParseCommandLine(params *MessageParams) (proto.Message, error)
}

Command - command

type CommandMap

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

CommandMap - command list

func NewCommandMap

func NewCommandMap() *CommandMap

NewCommandMap - new CommandMap

func (*CommandMap) AddCommand added in v0.1.36

func (m *CommandMap) AddCommand(cmd string, c Command)

AddCommand - add command with cmd

func (*CommandMap) HasCommand added in v0.1.8

func (m *CommandMap) HasCommand(cmd string) bool

HasCommand - has command

func (*CommandMap) ParseCommandLine added in v0.1.36

func (m *CommandMap) ParseCommandLine(cmd string, params *MessageParams) (proto.Message, error)

ParseCommandLine - run func with cmd

func (*CommandMap) Run

func (m *CommandMap) Run(ctx context.Context, cmd string, params *MessageParams) bool

Run - run func with cmd

type Config

type Config struct {
	CfgPath      string
	DownloadPath string

	AnkaDB struct {
		DBPath   string
		Engine   string
		HTTPAddr string
	}
}

Config - config

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig - load config

type FileTemplates added in v0.1.41

type FileTemplates struct {
	Templates []string
}

FileTemplates - file template

type FileTemplatesMgr added in v0.1.41

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

FileTemplatesMgr - user's file template manager

func (*FileTemplatesMgr) Get added in v0.1.41

func (mgr *FileTemplatesMgr) Get(db *chatbotdb.ChatBotDB, userID string) (*FileTemplates, error)

Get - load user's scripts

func (*FileTemplatesMgr) Load added in v0.1.41

func (mgr *FileTemplatesMgr) Load(db *chatbotdb.ChatBotDB, userID string) (*FileTemplates, error)

Load - load user's scripts

type FuncEvent added in v0.1.2

type FuncEvent func(ctx context.Context, chatbot ChatBot, eventid string) error

FuncEvent - func event

type FuncJarvisMsgCallback

type FuncJarvisMsgCallback func(ctx context.Context, msg *jarviscorepb.JarvisMsg) error

FuncJarvisMsgCallback - func(ctx, msg) error

type FuncMsgCallback

type FuncMsgCallback func(ctx context.Context, msg Message, id int) error

FuncMsgCallback - func(ctx, msg, id) error

type FuncNewPlugin added in v0.1.5

type FuncNewPlugin func(cfgPath string) (Plugin, error)

FuncNewPlugin - func newPlugin(cfgPath string) (Plugin, error)

type FuncUserEvent added in v0.1.36

type FuncUserEvent func(ctx context.Context, chatbot ChatBot, eventid string, userID string) error

FuncUserEvent - user func event

type Message

type Message interface {
	// GetFrom - get message sender
	GetFrom() User
	// GetTo - get user recive this msg
	GetTo() User
	// GetText - get message text
	GetText() string
	// GetTimeStamp - get timestamp
	GetTimeStamp() int64
	// GetChatID - get chatID
	GetChatID() string
	// GetMsgID - get message id
	GetMsgID() string
	// SetMsgID - set message id
	SetMsgID(msgid string)
	// SetChatID - set chat id
	SetChatID(chatid string)
	// SetText - set text
	SetText(text string)

	// SetGroupID - set groupID
	SetGroupID(groupID string)
	// GetGroupID - get groupID
	GetGroupID() string
	// InGroup - this message is from a group
	InGroup() bool

	// AddOption - add option
	AddOption(text string) (int, error)
	// HasOptions - has any options
	HasOptions() bool
	// SelectOption - select option
	SelectOption(id int) error
	// GetSelected - get selected
	GetSelected() int
	// GetOption - get option
	GetOption(id int) string

	// GetFile - get file
	GetFile() *chatbotdbpb.File
	// SetFile - set file
	SetFile(file *chatbotdbpb.File)

	// ToProto - to proto message
	ToProto() *chatbotdbpb.Message
}

Message - other user info

type MessageParams

type MessageParams struct {
	ChatBot     ChatBot
	MgrPlugins  PluginsMgr
	Msg         Message
	LstStr      []string
	CommandLine proto.Message
	CurPlugin   Plugin
}

MessageParams - Message func params

type MsgOption

type MsgOption struct {
	Text string
	ID   int
}

MsgOption - option

type Plugin

type Plugin interface {
	// OnMessage - get message
	OnMessage(ctx context.Context, params *MessageParams) (bool, error)

	// ParseMessage - If this message is what I can process,
	//	it will return to the command line, otherwise it will return an error.
	ParseMessage(params *MessageParams) (proto.Message, error)

	// OnStart - on start
	OnStart(ctx context.Context) error

	// GetPluginType - get pluginType
	GetPluginType() int

	// GetPluginName - get plugin name
	GetPluginName() string
}

Plugin - chat bot plugin interface

type PluginsMgr

type PluginsMgr interface {
	// SetDefaultPlugin - set default plugin
	SetDefaultPlugin(pluginName string) error
	// NewPlugin - New a plugin
	NewPlugin(pluginName string) error

	// OnMessage
	OnMessage(ctx context.Context, bot ChatBot, msg Message) error
	// SetCurPlugin
	SetCurPlugin(plugin Plugin)
	// GetCurPlugin
	GetCurPlugin() Plugin
	// OnStart - on start
	OnStart(ctx context.Context) error

	// RegPlugin - Registered a new plugin
	RegPlugin(pluginName string, funcNewPlugin FuncNewPlugin) error
	// CanNewPlugin - can new this plugin
	CanNewPlugin(pluginName string) bool

	// HasPlugin - has a plugin
	HasPlugin(pluginName string) bool
	// FindPlugin - find a plugin
	FindPlugin(pluginName string) Plugin

	// GetPlugins - get plugins
	GetPlugins() []string
}

PluginsMgr - chat bot plugins interface

func NewPluginsMgr

func NewPluginsMgr(cfgPath string) PluginsMgr

NewPluginsMgr - new default plugins mgr

type User

type User interface {
	// GetNickName - get nickname, composed of first name and last name
	GetNickName() string
	// GetUserName - get username
	GetUserName() string
	// GetUserID - get uid, uid is unique
	GetUserID() string
	// // IsMaster - is master
	// IsMaster() bool
	// ToProto - to proto user
	ToProto() *chatbotdbpb.User
	// GetLastMsgID - get lastMsgID
	GetLastMsgID() int64
	// UpdLastMsgID - update lastMsgID
	UpdLastMsgID(lastmsgid int64)
}

User - other user info

type UserMgr

type UserMgr interface {
	// GetUser - get user with userid
	GetUser(uid string) User
	// AddUser - add user
	AddUser(user User) error
	// IsMaster - is master
	IsMaster(user User) bool
	// SetMaster - set master, you can only set userid or username
	SetMaster(userid string, username string)
	// GetMasterUserID - get master userid
	GetMasterUserID() string
	// GetMasterUserName - get master username
	GetMasterUserName() string
}

UserMgr - other user info

type UserScripts added in v0.1.36

type UserScripts struct {
	Scripts []string
}

UserScripts - user's scripts

type UserScriptsMgr added in v0.1.36

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

UserScriptsMgr - user's scripts manager

func (*UserScriptsMgr) Get added in v0.1.36

func (mgr *UserScriptsMgr) Get(db *chatbotdb.ChatBotDB, userID string) (*UserScripts, error)

Get - load user's scripts

func (*UserScriptsMgr) Load added in v0.1.36

func (mgr *UserScriptsMgr) Load(db *chatbotdb.ChatBotDB, userID string) (*UserScripts, error)

Load - load user's scripts

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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