gonebot

package module
v0.0.0-...-498e85d Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 15 Imported by: 0

README

GoneBot

QQ群 MIT OneBot GoneBot

使用方法

package main

import (
	"fmt"

	"github.com/2mf8/GoneBot"
	"github.com/2mf8/GoneBot/onebot"
	"github.com/gin-gonic/gin"
)

func main() {

	gonebot.HandleConnect = func(bot *gonebot.Bot) {
		fmt.Printf("新机器人已连接:%d\n", bot.BotId)
		fmt.Println("所有机器人列表:")
		for botId, _ := range gonebot.Bots {
			println(botId)
		}
	}

	gonebot.HandleGroupMessage = func(bot *gonebot.Bot, event *onebot.GroupMessageEvent) {
		rawMsg := event.RawMessage
		groupId := event.GroupId
		userId := event.UserId
		display := event.Sender.Card
		replyMsg := gonebot.NewMsg().Text("hello world").At(userId, display).Text("你发送了:" + rawMsg)
		_, _ = bot.SendGroupMessage(groupId, replyMsg, false)
	}

	router := gin.Default()
	router.GET("/", func(c *gin.Context) {
		if err := gonebot.UpgradeWebsocket(c.Writer, c.Request); err != nil {
			fmt.Println("创建机器人失败")
		}
	})

	if err := router.Run(":8081"); err != nil {
		panic(err)
	}
	select {}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bots = make(map[int64]*Bot)
View Source
var HandleConnect = func(bot *Bot) {

}

HandleConnect 机器人连接

View Source
var HandleDisconnect = func(bot *Bot) {

}

HandleDisconnect 机器人断开

View Source
var HandleFriendAddNotice = func(bot *Bot, event *onebot.FriendAddNoticeEvent) {

}

HandleFriendAddNotice 新好友添加

View Source
var HandleFriendRecallNotice = func(bot *Bot, event *onebot.FriendMsgRecallNoticeEvent) {

}

HandleFriendRecallNotice 好友消息撤回

View Source
var HandleFriendRequest = func(bot *Bot, event *onebot.FriendAddRequestEvent) {

}

HandleFriendRequest 收到好友请求

View Source
var HandleGroupAdminNotice = func(bot *Bot, event *onebot.GroupAdminChangeNoticeEvent) {

}

HandleGroupAdminNotice 群管理员变动

View Source
var HandleGroupBanNotice = func(bot *Bot, event *onebot.GroupBanNoticeEvent) {

}

HandleGroupBanNotice 有人被禁言

View Source
var HandleGroupDecreaseNotice = func(bot *Bot, event *onebot.GroupMemberDecreaseNoticeEvent) {

}

HandleGroupDecreaseNotice 群人数减少 有人退群或被踢

View Source
var HandleGroupIncreaseNotice = func(bot *Bot, event *onebot.GroupMemberIncreaseNoticeEvent) {

}

HandleGroupIncreaseNotice 群人数增加

View Source
var HandleGroupLuckyKingNotify = func(bot *Bot, event *onebot.GroupLuckyKingNoticeEvent) {

}
View Source
var HandleGroupMemberHonorChangeNotify = func(bot *Bot, event *onebot.GroupMemberHonorChangeNoticeEvent) {

}

HandleGroupNotify 收到群通知

View Source
var HandleGroupMessage = func(bot *Bot, event *onebot.GroupMsgEvent) {

}

HandleGroupMessage 收到群聊消息

View Source
var HandleGroupPokeNotify = func(bot *Bot, event *onebot.GroupPokeNoticeEvent) {

}
View Source
var HandleGroupRecallNotice = func(bot *Bot, event *onebot.GroupMsgRecallNoticeEvent) {

}

HandleGroupRecallNotice 群消息撤回

View Source
var HandleGroupRequest = func(bot *Bot, event *onebot.GroupAddOrInviteRequestEvent) {

}

HandleGroupRequest 收到加群请求

View Source
var HandleGroupUploadNotice = func(bot *Bot, event *onebot.GroupUploadNoticeEvent) {

}

HandleGroupUploadNotice 有人上传群文件

View Source
var HandleHeartBeat = func(bot *Bot, event *onebot.BotHeartBeat) {

}

HandleHeartBeat 收到机器人心跳

View Source
var HandleLifeTime = func(bot *Bot, event *onebot.LifeTime) {

}

HandleLifeTime 收到生命周期

View Source
var HandlePrivateMessage = func(bot *Bot, event *onebot.PrivateMsgEvent) {

}

HandlePrivateMessage 收到私聊消息

Functions

func UpgradeWebsocket

func UpgradeWebsocket(w http.ResponseWriter, r *http.Request) error

Types

type Bot

type Bot struct {
	BotId   int64
	Session *SafeWebSocket

	WaitingFrames map[string]*promise.Promise
	// contains filtered or unexported fields
}

func NewBot

func NewBot(botId int64, conn *websocket.Conn) *Bot

func (*Bot) CanSendImage

func (bot *Bot) CanSendImage() (*onebot.CanSendImageResp, error)

func (*Bot) CleanCache

func (bot *Bot) CleanCache() (*onebot.CleanCacheResp, error)

func (*Bot) DeleteMsg

func (bot *Bot) DeleteMsg(msgId int64) (*onebot.DeleteMsgResp, error)

func (*Bot) GetForwardMsg

func (bot *Bot) GetForwardMsg(id string) (*onebot.GetForwardMsgResp, error)

func (*Bot) GetGroupInfo

func (bot *Bot) GetGroupInfo(groupId int64, noCache bool) (*onebot.GetGroupInfoResp, error)

func (*Bot) GetGroupMemberInfo

func (bot *Bot) GetGroupMemberInfo(groupId, userId int64, noCache bool) (*onebot.GetGroupMemberInfoResp, error)

func (*Bot) GetLoginInfo

func (bot *Bot) GetLoginInfo() (*onebot.GetLoginInfoResp, error)

func (*Bot) GetMsg

func (bot *Bot) GetMsg(msgId int64) (*onebot.GetMsgResp, error)

func (*Bot) SendForwardMsg

func (bot *Bot) SendForwardMsg(groupId int64, forwardMsg *onebot.ForwardParams) (*onebot.SendMsgResponse, error)

func (*Bot) SendGroupMessage

func (bot *Bot) SendGroupMessage(groupId int64, msg *Msg, autoEscape bool) (*onebot.SendMsgResponse, error)

func (*Bot) SendLike

func (bot *Bot) SendLike(userId int64, times int32) (*onebot.SendLikeResp, error)

times 赞的次数,每个好友每天最多 10 次

func (*Bot) SendMarkdownAndKeyboardAtMsg

func (bot *Bot) SendMarkdownAndKeyboardAtMsg(groupId, userId int64, markdown *markdown.MarkDown, keyboard *keyboard.CustomKeyboard) (*onebot.SendMsgResponse, error)

带 @效果

func (*Bot) SendMarkdownAndKeyboardMsg

func (bot *Bot) SendMarkdownAndKeyboardMsg(groupId, userId int64, markdown *markdown.MarkDown, keyboard *keyboard.CustomKeyboard) (*onebot.SendMsgResponse, error)

func (*Bot) SendMarkdownAtMsg

func (bot *Bot) SendMarkdownAtMsg(groupId, userId int64, markdown *markdown.MarkDown) (*onebot.SendMsgResponse, error)

带 @效果

func (*Bot) SendMarkdownMsg

func (bot *Bot) SendMarkdownMsg(groupId, userId int64, markdown *markdown.MarkDown) (*onebot.SendMsgResponse, error)

func (*Bot) SendMsg

func (bot *Bot) SendMsg(msgType string, userId, groupId int64, msg *Msg, autoEscape bool) (*onebot.SendMsgResponse, error)

func (*Bot) SendPrivateMsg

func (bot *Bot) SendPrivateMsg(userId int64, msg *Msg, autoEscape bool) (*onebot.SendMsgResponse, error)

func (*Bot) SetFriendAddRequest

func (bot *Bot) SetFriendAddRequest(flag, remark string, approve bool) (*onebot.SetFriendAddRequestResp, error)

func (*Bot) SetGroupAddRequest

func (bot *Bot) SetGroupAddRequest(flag, subType, reason string, approve bool) (*onebot.SetGroupAddRequestResp, error)

func (*Bot) SetGroupAdmin

func (bot *Bot) SetGroupAdmin(groupId, userId int64, enable bool) (*onebot.SetGroupAdminResp, error)

func (*Bot) SetGroupAnonymous

func (bot *Bot) SetGroupAnonymous(groupId int64, enable bool) (*onebot.SetGroupAnonymousResp, error)

func (*Bot) SetGroupAnonymousBan

func (bot *Bot) SetGroupAnonymousBan(groupId int64, anonymous *onebot.Anonymous, anonymousFlag string, duration int64) (*onebot.SetGroupAnonymousBanResp, error)

func (*Bot) SetGroupBan

func (bot *Bot) SetGroupBan(groupId int64, userId int64, duration int64) (*onebot.SetGroupBanResp, error)

func (*Bot) SetGroupCard

func (bot *Bot) SetGroupCard(groupId, userId int64, card string) (*onebot.SetGroupCardResp, error)

func (*Bot) SetGroupKick

func (bot *Bot) SetGroupKick(groupId int64, userId int64, rejectAddRequest bool) (*onebot.SetGroupKickResp, error)

func (*Bot) SetGroupLeave

func (bot *Bot) SetGroupLeave(groupId int64, isDismiss bool) (*onebot.SetGroupLeaveResp, error)

func (*Bot) SetGroupName

func (bot *Bot) SetGroupName(groupId int64, groupName string) (*onebot.SetGroupNameResp, error)

func (*Bot) SetGroupSpecialTitle

func (bot *Bot) SetGroupSpecialTitle(groupId, userId, duration int64, specialTitle string) (*onebot.SetGroupSpecialTitleResp, error)

func (*Bot) SetGroupWholeBan

func (bot *Bot) SetGroupWholeBan(groupId int64, enable bool) (*onebot.SetGroupWholeBanResp, error)

type Msg

type Msg struct {
	IMessageList []*onebot.IMessage
}

func NewMsg

func NewMsg() *Msg

func (*Msg) AnyMsg

func (msg *Msg) AnyMsg(anyMsg []*onebot.IMessage) *Msg

func (*Msg) At

func (msg *Msg) At(qq int64, display string) *Msg

func (*Msg) AtAll

func (msg *Msg) AtAll() *Msg

func (*Msg) Dice

func (msg *Msg) Dice(value int64) *Msg

func (*Msg) Face

func (msg *Msg) Face(id int) *Msg

func (*Msg) Flash

func (msg *Msg) Flash(url string) *Msg

func (*Msg) Forward

func (msg *Msg) Forward(id string) *Msg

func (*Msg) Image

func (msg *Msg) Image(url string) *Msg

func (*Msg) Json

func (msg *Msg) Json(content string) *Msg

func (*Msg) LightApp

func (msg *Msg) LightApp(content string) *Msg

func (*Msg) LongMsg

func (msg *Msg) LongMsg(id string) *Msg

func (*Msg) Node

func (msg *Msg) Node(id string) *Msg

func (*Msg) Poke

func (msg *Msg) Poke(qq int64) *Msg

func (*Msg) Record

func (msg *Msg) Record(url string) *Msg

func (*Msg) Reply

func (msg *Msg) Reply(msgId int32) *Msg

GMC专用

func (*Msg) Share

func (msg *Msg) Share(url string, title string, content string, image string) *Msg

func (*Msg) SignIn

func (msg *Msg) SignIn() *Msg

func (*Msg) Sleep

func (msg *Msg) Sleep(time int64) *Msg

func (*Msg) TTS

func (msg *Msg) TTS(text string) *Msg

func (*Msg) Text

func (msg *Msg) Text(text string) *Msg

func (*Msg) Video

func (msg *Msg) Video(url string, cover string, cache bool) *Msg

func (*Msg) Xml

func (msg *Msg) Xml(content string) *Msg

type MutiMsg

type MutiMsg struct {
	IMutiMsgList []*onebot.ForwardMsg
}

func NewForwardMsg

func NewForwardMsg() *MutiMsg

func (*MutiMsg) Add

func (mutiMsg *MutiMsg) Add(fMsg *onebot.ForwardMsg) *MutiMsg

type SafeWebSocket

type SafeWebSocket struct {
	Conn          *websocket.Conn
	SendChannel   chan *WebSocketSendingMessage
	OnRecvMessage func(messageType int, data []byte)
	OnClose       func(int, string)
}

safe websocket

func NewSafeWebSocket

func NewSafeWebSocket(conn *websocket.Conn, OnRecvMessage func(messageType int, data []byte), onClose func(int, string)) *SafeWebSocket

func (*SafeWebSocket) Send

func (ws *SafeWebSocket) Send(messageType int, data []byte)

type WebSocketSendingMessage

type WebSocketSendingMessage struct {
	MessageType int
	Data        []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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