Documentation ¶
Index ¶
- Constants
- Variables
- func AddEchoCallback(echo string, callback EchoCallback)
- func Init(conf string)
- func InitBackenPlugin()
- func InitBotCtxs()
- func InitDefaultPluginManager(plgId int)
- func InitLogConf()
- func InitPluginList()
- func ParseTextMsg(segs []MsgSeg) string
- func RunBackenPlugin()
- func RunBots()
- func RunEventDispatcher()
- func RunRespDispatcher(poolSize int)
- func Start()
- type ApiPost
- type ApiResp
- type ArrayMsg
- func (am *ArrayMsg) AddAt(uid int64) *ArrayMsg
- func (am *ArrayMsg) AddDice() *ArrayMsg
- func (am *ArrayMsg) AddFace(faceID int) *ArrayMsg
- func (am *ArrayMsg) AddImg(file, url string) *ArrayMsg
- func (am *ArrayMsg) AddRPS() *ArrayMsg
- func (am *ArrayMsg) AddRecord(file, url string) *ArrayMsg
- func (am *ArrayMsg) AddShake() *ArrayMsg
- func (am *ArrayMsg) AddText(text string) *ArrayMsg
- func (am *ArrayMsg) GetMsg() (interface{}, error)
- type BackenUnit
- type BeforeApiOutHook
- type BotContext
- type BotCtxs
- type BotInfo
- type CommandUnit
- func (cp *CommandUnit) AddAliases(aliases ...string) *CommandUnit
- func (cp *CommandUnit) AddToCmdChain()
- func (cp *CommandUnit) SetCommand(cmd string) *CommandUnit
- func (cp *CommandUnit) SetProcessor(f func(e *Event, params []string, bInfo BotInfo)) *CommandUnit
- func (cp *CommandUnit) SetRule(rule *Rule) *CommandUnit
- type Config
- type DisconnectHook
- type EchoCallback
- type Event
- type EventInHook
- type Formatter
- type GroupMsg
- type Judge
- type LogConf
- type MessageUnit
- type MsgBuilder
- type MsgSeg
- type NoticeUnit
- type OnconnectHook
- type Plugin
- func (p *Plugin) AddBackenUnit() *BackenUnit
- func (p *Plugin) AddCommandUnit() *CommandUnit
- func (p *Plugin) AddMessageUnit() *MessageUnit
- func (p *Plugin) AddNoticeUnit() *NoticeUnit
- func (p *Plugin) AddRequestUnit() *RequestUnit
- func (p *Plugin) SetAdminPlugin() *Plugin
- func (p *Plugin) SetHelpInfo(helpInfo string) *Plugin
- func (p *Plugin) SetName(name string) *Plugin
- type PrivateMsg
- type RequestUnit
- type Rule
- type Sender
- type TextMsg
- func (tm *TextMsg) AddAt(uid int64) *TextMsg
- func (tm *TextMsg) AddDice() *TextMsg
- func (tm *TextMsg) AddFace(faceNo int) *TextMsg
- func (tm *TextMsg) AddImg(file, url string) *TextMsg
- func (tm *TextMsg) AddRPS() *TextMsg
- func (tm *TextMsg) AddRecord(file, url string) *TextMsg
- func (tm *TextMsg) AddShake() *TextMsg
- func (tm *TextMsg) AddText(text string) *TextMsg
- func (tm *TextMsg) GetMsg() (interface{}, error)
- func (tm *TextMsg) NewLine() *TextMsg
Constants ¶
View Source
const ( MsgTypeArray = "array" MsgTypeString = "string" )
View Source
const ( GroupMsgAction = "send_group_msg" PrivateMsgAction = "send_private_msg" )
View Source
const ( MsgTypePrivate = "private" MsgTypeGroup = "group" MessageEvent = "message" NoticeEvent = "notice" RequestEvent = "request" MetaEvent = "meta_event" Lifecycle = "lifecycle" Heartbeat = "heartbeat" SendTimeout = "timeout" BotIDMiss = "miss" )
View Source
const ( DefaultLevel = logrus.WarnLevel DefaultFileNameFmt = "./logs/%Y-%m-%d.log" DefaultMaxFiles = uint(15) DefaultRotateDura = time.Hour * 12 )
View Source
const ( TextMsgSeg = "text" FaceMsgSeg = "face" ImageMsgSeg = "image" RecordMsgSeg = "record" VideoMsgSeg = "video" AtMsgSeg = "at" RPSMsgSeg = "rps" DiceMsgSeg = "dice" ShakeMsgSeg = "shake" PokeMsgSeg = "poke" AnonymousMsgSeg = "anonymous" ContactMsgSeg = "contact" LocationMsgSeg = "location" MusicMsgSeg = "music" ReplyMsgSeg = "reply" ForwardMsgSeg = "forward" NodeMsgSeg = "node" XmlMsgSeg = "xml" JsonMsgSeg = "json" )
View Source
const ( QEmojiBabble = 13 QEmojiFrog = 170 QEmojiFirecracker = 137 QEmojiCrab = 184 )
View Source
const ( TokenPrefix = "WhYhAvEsPaCe " ReconnTimes = 3 )
View Source
const ( DefaultTimeout = 10 OffHeartCheck = 0 )
View Source
const AtAll = int64(-1)
View Source
const ConmandPrefix = "~$#"
命令以 ~$#或者@bot 开头
Variables ¶
View Source
var ( BackenChain []BackenUnit MsgChain []MessageUnit CmdChain []CommandUnit NoticeChain []NoticeUnit RequestChain []RequestUnit PluginList []*Plugin )
View Source
var ( // 消息发送者是否是管理员 IsAdmin = func(e *Event, bInfo BotInfo) bool { for _, admin := range bInfo.Admins { if e.UserID == admin { return true } } return false } // 发送者是否是超级管理员 IsSAdmin = func(e *Event, bInfo BotInfo) bool { for _, admin := range Conf.SAdmins { if e.UserID == admin { return true } } return false } IsGroupMsg = func(e *Event, bInfo BotInfo) bool { return e.MessageType == MsgTypeGroup } IsPrivateMsg = func(e *Event, bInfo BotInfo) bool { return e.MessageType == MsgTypePrivate } )
View Source
var (
LBLogger logrus.Logger
)
View Source
var SegRegex = regexp.MustCompile(`\[CQ:[a-z]{2,9}[^\]]*\]`)
Functions ¶
func AddEchoCallback ¶
func AddEchoCallback(echo string, callback EchoCallback)
func InitBackenPlugin ¶
func InitBackenPlugin()
func InitBotCtxs ¶
func InitBotCtxs()
func InitDefaultPluginManager ¶
func InitDefaultPluginManager(plgId int)
func InitLogConf ¶
func InitLogConf()
func InitPluginList ¶
func InitPluginList()
func ParseTextMsg ¶
func RunBackenPlugin ¶
func RunBackenPlugin()
func RunEventDispatcher ¶
func RunEventDispatcher()
func RunRespDispatcher ¶
func RunRespDispatcher(poolSize int)
Types ¶
type ApiPost ¶
type ApiPost struct { Action string `json:"action"` Params interface{} `json:"params"` Echo string `json:"echo"` }
Params: ptr
func MakeGroupMsg ¶
func MakeGroupMsg(msgBuilder MsgBuilder, groupID int64) ApiPost
func MakePrivateMsg ¶
func MakePrivateMsg(msgBuilder MsgBuilder, userID int64) ApiPost
type ArrayMsg ¶
func MakeArrayMsg ¶
type BackenUnit ¶
func (*BackenUnit) AddToBackenChain ¶
func (bp *BackenUnit) AddToBackenChain()
func (*BackenUnit) SetInitFunc ¶
func (bp *BackenUnit) SetInitFunc(f func()) *BackenUnit
func (*BackenUnit) SetStartFunc ¶
func (bp *BackenUnit) SetStartFunc(f func(bInfos []BotInfo)) *BackenUnit
type BeforeApiOutHook ¶
Before send an ApiPost to the CQ server, all of the BeforeApiOutHook will be called. if the hook return a not nil error, this ApiPost will be aborted
func MakeBeforeApiOutHook ¶
func MakeBeforeApiOutHook(task func(apiPost *ApiPost, bInfo BotInfo) error) BeforeApiOutHook
func (BeforeApiOutHook) AddToHookChain ¶
func (hook BeforeApiOutHook) AddToHookChain()
type BotContext ¶
type BotCtxs ¶
type BotCtxs = []BotContext
type CommandUnit ¶
type CommandUnit struct { Plg *Plugin Rule *Rule Cmd string Aliases []string Process func(e *Event, params []string, bInfo BotInfo) }
func (*CommandUnit) AddAliases ¶
func (cp *CommandUnit) AddAliases(aliases ...string) *CommandUnit
func (*CommandUnit) AddToCmdChain ¶
func (cp *CommandUnit) AddToCmdChain()
func (*CommandUnit) SetCommand ¶
func (cp *CommandUnit) SetCommand(cmd string) *CommandUnit
func (*CommandUnit) SetProcessor ¶
func (cp *CommandUnit) SetProcessor(f func(e *Event, params []string, bInfo BotInfo)) *CommandUnit
func (*CommandUnit) SetRule ¶
func (cp *CommandUnit) SetRule(rule *Rule) *CommandUnit
type Config ¶
type Config struct { BotInfos []BotInfo `yaml:"bots"` LogConf LogConf `yaml:"log"` SAdmins []int64 `yaml:"s-admin"` CallbackPoolSize int `yaml:"callback-pool-size"` }
var (
Conf Config
)
type DisconnectHook ¶
type DisconnectHook func(bInfo BotInfo)
When a connect is closed, this hook will be called.
func MakeDisconnectHook ¶
func MakeDisconnectHook(task func(bInfo BotInfo)) DisconnectHook
func (DisconnectHook) AddToHookChain ¶
func (hook DisconnectHook) AddToHookChain()
type EchoCallback ¶
type Event ¶
type Event struct { Font int `json:"font"` GroupID int64 `json:"group_id"` Message interface{} `json:"message"` MessageID int `json:"message_id"` MessageSeq int `json:"message_seq"` MessageType string `json:"message_type"` PostType string `json:"post_type"` RawMessage string `json:"raw_message"` TempSource int `json:"temp_source"` SelfID int64 `json:"self_id"` Sender Sender `json:"sender"` SubType string `json:"sub_type"` Time int `json:"time"` UserID int64 `json:"user_id"` MetaEventType string `json:"meta_event_type"` }
func (*Event) GetArrayMsg ¶
func (*Event) GetTextMsg ¶
type EventInHook ¶
When an event is received from CQ server, all of the EventInHook will be called. If the hook return a not nil error, the event will be aborted.
func MakeEventInHook ¶
func MakeEventInHook(task func(e *Event, bInfo BotInfo) error) EventInHook
func (EventInHook) AddToHookChain ¶
func (hook EventInHook) AddToHookChain()
type Formatter ¶
*
- @description: logrus formatter
- %msg% - messsage, %lvl% - level, %time% - time, %fn% - filename, %fln% - file line number
type MessageUnit ¶
func (*MessageUnit) AddToMsgChain ¶
func (mp *MessageUnit) AddToMsgChain()
func (*MessageUnit) SetProcessor ¶
func (mp *MessageUnit) SetProcessor(f func(e *Event, bInfo BotInfo)) *MessageUnit
func (*MessageUnit) SetRule ¶
func (mp *MessageUnit) SetRule(rule *Rule) *MessageUnit
type MsgBuilder ¶
type MsgBuilder interface {
GetMsg() (interface{}, error)
}
type MsgSeg ¶
func ParseMsgSegs ¶
type NoticeUnit ¶
func (*NoticeUnit) AddToNoticeChain ¶
func (np *NoticeUnit) AddToNoticeChain()
func (*NoticeUnit) SetProcessor ¶
func (np *NoticeUnit) SetProcessor(f func(e *Event, bInfo BotInfo)) *NoticeUnit
func (*NoticeUnit) SetRule ¶
func (np *NoticeUnit) SetRule(rule *Rule) *NoticeUnit
type OnconnectHook ¶
When a bot instance onconnect to a CQ server, all of the OnconnectHook will be called. If the hook return an error which is not nil, this connect will be closed, and then, the Disconnecthooks will be called.
func MakeOnconnectHook ¶
func MakeOnconnectHook(task func(bInfo BotInfo) error) OnconnectHook
func (OnconnectHook) AddToHookChain ¶
func (hook OnconnectHook) AddToHookChain()
type Plugin ¶
func (*Plugin) AddBackenUnit ¶
func (p *Plugin) AddBackenUnit() *BackenUnit
func (*Plugin) AddCommandUnit ¶
func (p *Plugin) AddCommandUnit() *CommandUnit
func (*Plugin) AddMessageUnit ¶
func (p *Plugin) AddMessageUnit() *MessageUnit
func (*Plugin) AddNoticeUnit ¶
func (p *Plugin) AddNoticeUnit() *NoticeUnit
func (*Plugin) AddRequestUnit ¶
func (p *Plugin) AddRequestUnit() *RequestUnit
func (*Plugin) SetAdminPlugin ¶
func (*Plugin) SetHelpInfo ¶
type PrivateMsg ¶
type RequestUnit ¶
func (*RequestUnit) AddToRequestChain ¶
func (rp *RequestUnit) AddToRequestChain()
func (*RequestUnit) SetProcessor ¶
func (rp *RequestUnit) SetProcessor(f func(e *Event, bInfo BotInfo)) *RequestUnit
func (*RequestUnit) SetRule ¶
func (rp *RequestUnit) SetRule(rule *Rule) *RequestUnit
type TextMsg ¶
type TextMsg struct {
// contains filtered or unexported fields
}
func MakeTextMsg ¶
func MakeTextMsg() *TextMsg
Source Files ¶
Click to show internal directories.
Click to hide internal directories.