bot

package
v0.9.25-0...-7aecb6b Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSliderNeeded                 = errors.New("需要滑条验证")
	ErrSMSNeeded                    = errors.New("需要短信验证码")
	ErrCaptchaNeeded                = errors.New("需要验证码")
	ErrSMSOrVerifyNeeded            = errors.New("设备锁需要验证")
	ErrUnsafeDevice                 = errors.New("设备锁需要验证")
	ErrWrongPasswordOrAccountFreeze = errors.New("密码错误或账号冻结")
	ErrAbnormal                     = errors.New("上网环境异常")
)
View Source
var IgnoreInvalidCQCode = false
View Source
var JsonAPI = map[string]func(*CoreBot, gjson.Result) MSG{
	"get_login_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetLoginInfo()
	},
	"get_friend_list": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetFriendList()
	},
	"get_group_list": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupList(p.Get("no_cache").Bool())
	},
	"get_group_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
	},
	"get_group_member_list": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
	},
	"get_group_member_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupMemberInfo(
			p.Get("group_id").Int(), p.Get("user_id").Int(),
		)
	},
	"send_msg": func(bot *CoreBot, p gjson.Result) MSG {
		autoEscape := utils.EnsureBool(p.Get("auto_escape"), false)
		if p.Get("message_type").Str == "private" {
			return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
		}
		if p.Get("message_type").Str == "group" {
			return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
		}
		if p.Get("group_id").Int() != 0 {
			return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
		}
		if p.Get("user_id").Int() != 0 {
			return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
		}
		return MSG{}
	},
	"send_group_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), utils.EnsureBool(p.Get("auto_escape"), false))
	},
	"send_group_forward_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return Failed(-1, "not support yet")
	},
	"send_private_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), utils.EnsureBool(p.Get("auto_escape"), false))
	},
	"delete_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return Failed(-1, "not support yet")
	},
	"set_friend_add_request": func(bot *CoreBot, p gjson.Result) MSG {
		apr := true
		if p.Get("approve").Exists() {
			apr = p.Get("approve").Bool()
		}
		return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
	},
	"set_group_add_request": func(bot *CoreBot, p gjson.Result) MSG {
		subType := p.Get("sub_type").Str
		apr := true
		if subType == "" {
			subType = p.Get("type").Str
		}
		if p.Get("approve").Exists() {
			apr = p.Get("approve").Bool()
		}
		return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
	},
	"set_group_card": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
	},
	"set_group_special_title": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
	},
	"set_group_kick": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
	},
	"set_group_ban": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
			if p.Get("duration").Exists() {
				return uint32(p.Get("duration").Int())
			}
			return 1800
		}())
	},
	"set_group_whole_ban": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
			if p.Get("enable").Exists() {
				return p.Get("enable").Bool()
			}
			return true
		}())
	},
	"set_group_name": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
	},
	"set_group_admin": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
			if p.Get("enable").Exists() {
				return p.Get("enable").Bool()
			}
			return true
		}())
	},
	"_send_group_notice": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str)
	},
	"set_group_leave": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupLeave(p.Get("group_id").Int())
	},
	"get_image": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetImage(p.Get("file").Str)
	},
	"get_forward_msg": func(bot *CoreBot, p gjson.Result) MSG {
		id := p.Get("message_id").Str
		if id == "" {
			id = p.Get("id").Str
		}
		return bot.CQGetForwardMessage(id)
	},
	"get_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return Failed(-1, "not support yet")
	},
	"download_file": func(bot *CoreBot, p gjson.Result) MSG {
		headers := map[string]string{}
		headersToken := p.Get("headers")
		if headersToken.IsArray() {
			for _, sub := range headersToken.Array() {
				str := strings.SplitN(sub.String(), "=", 2)
				if len(str) == 2 {
					headers[str[0]] = str[1]
				}
			}
		}
		if headersToken.Type == gjson.String {
			lines := strings.Split(headersToken.String(), "\r\n")
			for _, sub := range lines {
				str := strings.SplitN(sub, "=", 2)
				if len(str) == 2 {
					headers[str[0]] = str[1]
				}
			}
		}
		return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
	},
	"get_group_honor_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
	},
	"set_restart": func(c *CoreBot, p gjson.Result) MSG {
		return Failed(-1, "not support yet")
	},
	"can_send_image": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQCanSendImage()
	},
	"can_send_record": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQCanSendRecord()
	},
	"get_stranger_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetStrangerInfo(p.Get("user_id").Int())
	},
	"get_status": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetStatus()
	},
	"get_version_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetVersionInfo()
	},
	"get_group_system_msg": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupSystemMessages()
	},
	"get_group_file_system_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
	},
	"get_group_root_files": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
	},
	"get_group_files_by_folder": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupFilesByFolderId(p.Get("group_id").Int(), p.Get("folder_id").Str)
	},
	"get_group_file_url": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupFileUrl(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
	},
	"get_group_msg_history": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
	},
	"_get_vip_info": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetVipInfo(p.Get("user_id").Int())
	},
	"reload_event_filter": func(bot *CoreBot, p gjson.Result) MSG {
		return Failed(-1, "not support yet")
	},
	".ocr_image": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQOcrImage(p.Get("image").Str)
	},
	"ocr_image": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQOcrImage(p.Get("image").Str)
	},
	"get_group_at_all_remain": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetAtAllRemain(p.Get("group_id").Int())
	},
	"get_online_clients": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
	},
	".get_word_slices": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQGetWordSlices(p.Get("content").Str)
	},
	"set_group_portrait": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
	},
	"set_group_anonymous_ban": func(bot *CoreBot, p gjson.Result) MSG {
		obj := p.Get("anonymous")
		flag := p.Get("anonymous_flag")
		if !flag.Exists() {
			flag = p.Get("flag")
		}
		if !flag.Exists() && !obj.Exists() {
			return Failed(100, "FLAG_NOT_FOUND", "flag未找到")
		}
		if !flag.Exists() {
			flag = obj.Get("flag")
		}
		return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
	},
	".handle_quick_operation": func(bot *CoreBot, p gjson.Result) MSG {
		return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
	},
}
View Source
var SplitUrl = false
View Source
var Version = "unknown"

Functions

func CQCodeEscapeText

func CQCodeEscapeText(raw string) string

func CQCodeEscapeValue

func CQCodeEscapeValue(value string) string

func CQCodeUnescapeText

func CQCodeUnescapeText(content string) string

func CQCodeUnescapeValue

func CQCodeUnescapeValue(content string) string

func ToGlobalId

func ToGlobalId(code int64, msgId int32) int32

func ToStringMessage

func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r string)

func XmlEscape

func XmlEscape(c string) string

Types

type CoreBot

type CoreBot struct {
	Client          *client.QQClient
	ForceFragmented bool
	MessageFormat   string

	EventChannel chan MSG
	// contains filtered or unexported fields
}

func NewCoreBot

func NewCoreBot(uin int64, password string, deviceJson []byte) (*CoreBot, error)

func (*CoreBot) CQCanSendImage

func (bot *CoreBot) CQCanSendImage() MSG

func (*CoreBot) CQCanSendRecord

func (bot *CoreBot) CQCanSendRecord() MSG

func (*CoreBot) CQDownloadFile

func (bot *CoreBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG

func (*CoreBot) CQGetAtAllRemain

func (bot *CoreBot) CQGetAtAllRemain(groupId int64) MSG

func (*CoreBot) CQGetForwardMessage

func (bot *CoreBot) CQGetForwardMessage(resId string) MSG

func (*CoreBot) CQGetGroupFileSystemInfo

func (bot *CoreBot) CQGetGroupFileSystemInfo(groupId int64) MSG

func (*CoreBot) CQGetGroupFileUrl

func (bot *CoreBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) MSG

func (*CoreBot) CQGetGroupFilesByFolderId

func (bot *CoreBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG

func (*CoreBot) CQGetGroupMessageHistory

func (bot *CoreBot) CQGetGroupMessageHistory(groupId int64, seq int64) MSG

func (*CoreBot) CQGetGroupRootFiles

func (bot *CoreBot) CQGetGroupRootFiles(groupId int64) MSG

func (*CoreBot) CQGetGroupSystemMessages

func (bot *CoreBot) CQGetGroupSystemMessages() MSG

func (*CoreBot) CQGetImage

func (bot *CoreBot) CQGetImage(file string) MSG

func (*CoreBot) CQGetOnlineClients

func (bot *CoreBot) CQGetOnlineClients(noCache bool) MSG

func (*CoreBot) CQGetVersionInfo

func (bot *CoreBot) CQGetVersionInfo() MSG

func (*CoreBot) CQGetVipInfo

func (bot *CoreBot) CQGetVipInfo(userId int64) MSG

func (*CoreBot) CQGetWordSlices

func (bot *CoreBot) CQGetWordSlices(content string) MSG

func (*CoreBot) CQOcrImage

func (bot *CoreBot) CQOcrImage(imageId string) MSG

func (*CoreBot) CQSendGroupMessage

func (bot *CoreBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG

https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF

func (*CoreBot) CQSetGroupAnonymousBan

func (bot *CoreBot) CQSetGroupAnonymousBan(groupId int64, flag string, duration int32) MSG

func (*CoreBot) CQSetGroupMemo

func (bot *CoreBot) CQSetGroupMemo(groupId int64, msg string) MSG

func (*CoreBot) CQSetGroupName

func (bot *CoreBot) CQSetGroupName(groupId int64, name string) MSG

func (*CoreBot) CQSetGroupPortrait

func (bot *CoreBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG

func (*CoreBot) ConvertObjectMessage

func (bot *CoreBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.IMessageElement)

func (*CoreBot) ConvertStringMessage

func (bot *CoreBot) ConvertStringMessage(msg string, group bool) (r []message.IMessageElement)

func (*CoreBot) SendGroupMessage

func (bot *CoreBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int32

func (*CoreBot) SendPrivateMessage

func (bot *CoreBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32

func (*CoreBot) Start

func (bot *CoreBot) Start() error

func (*CoreBot) ToElement

func (bot *CoreBot) ToElement(t string, d map[string]string, group bool) (m interface{}, err error)

ToElement 将解码后的CQCode转换为Element. 返回 interface{} 存在三种类型 message.IMessageElement []message.IMessageElement nil

func (*CoreBot) ToFormattedMessage

func (bot *CoreBot) ToFormattedMessage(e []message.IMessageElement, id int64, raw ...bool) (r interface{})

ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式

func (*CoreBot) UploadLocalImageAsGroup

func (bot *CoreBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElement) (*message.GroupImageElement, error)

func (*CoreBot) UploadLocalImageAsPrivate

func (bot *CoreBot) UploadLocalImageAsPrivate(userId int64, img *LocalImageElement) (*message.FriendImageElement, error)

func (*CoreBot) UploadLocalVideo

func (bot *CoreBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error)

type GiftElement

type GiftElement struct {
	Target int64
	GiftId message.GroupGift
}

func (*GiftElement) Type

func (e *GiftElement) Type() message.ElementType

type LocalImageElement

type LocalImageElement struct {
	message.ImageElement
	Stream io.ReadSeeker
	File   string
}

type LocalVideoElement

type LocalVideoElement struct {
	message.ShortVideoElement
	File string
	// contains filtered or unexported fields
}

type LocalVoiceElement

type LocalVoiceElement struct {
	message.VoiceElement
	Stream io.ReadSeeker
}

type MSG

type MSG map[string]interface{}

func Failed

func Failed(code int, messages ...string) MSG

func OK

func OK(data interface{}) MSG

func ToArrayMessage

func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []MSG)

func (MSG) ToJson

func (m MSG) ToJson() string

type PokeElement

type PokeElement struct {
	Target int64
}

func (*PokeElement) Type

func (e *PokeElement) Type() message.ElementType

Jump to

Keyboard shortcuts

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