SakanaBot

package module
v0.0.0-...-fe7beef Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

README

SakanaBot

独立的QQ bot 框架

Documentation

Index

Constants

View Source
const (
	MessageSyncFlagStart    uint32 = 0x00
	MessageSyncFlagContinue uint32 = 0x01
	MessageSyncFlagStop     uint32 = 0x02
)
View Source
const (
	MessageTypeVoice    uint16 = 0x01
	MessageTypeRichText uint16 = 0x02
)
View Source
const (
	RichTextElementTypeReply        uint16 = 0x01
	RichTextElementTypeAtAll        uint16 = 0x02
	RichTextElementTypeAt           uint16 = 0x03
	RichTextElementTypeText         uint16 = 0x03
	RichTextElementTypeOfflineImage uint16 = 0x04
)
View Source
const (
	RequestEncryptEMECDH uint8 = 0x00
	RequestEncryptEMST   uint8 = 0x01

	NetpackRequestTypeLogin  uint32 = 0x0A
	NetpackRequestTypeSimple uint32 = 0x0B
	NetpackEncryptNoEncrypt  byte   = 0x00
	NetpackEncryptD2Key      byte   = 0x01
	NetpackEncryptEmptyKey   byte   = 0x02

	GetMessageSyncFlagStart    uint32 = 0
	GetMessageSyncFlagContinue uint32 = 1
	GetMessageSyncFlagStop     uint32 = 2
)
View Source
const (
	LoginResponseNeedSlider    uint16 = 1
	LoginResponseNeedSMS       uint16 = 2
	LoginResponseNeedWebVerify uint16 = 3
	LoginResponseOtherError    uint16 = 4
)
View Source
const (
	LoginMethodPassword uint16 = 0
)

Variables

View Source
var (
	ErrorNoServerIsReachable = errors.New("error: No server is reachable")
	ErrorPackLengthError     = errors.New("error: Pack length error")
)
View Source
var (
	IPad = Protocol{
		ApkId:      "com.tencent.minihd.qq",
		AppId:      16,
		SubAppId:   537097188,
		Version:    "8.8.35",
		ApkSign:    []byte{0xAA, 0x39, 0x78, 0xE0, 0x1F, 0xD9, 0x6F, 0xF9, 0x91, 0x4A, 0x66, 0x9E, 0x18, 0x64, 0x74, 0xC7},
		BuildTime:  1595836208,
		SdkVersion: "6.0.0.2433",
		SsoVersion: 12,
		Bitmap:     150470524,
		MainSigmap: 1970400,
		SubSigmap:  0x10400,
		Name:       "IPad",
	}
	ProtocolMap = map[string]*Protocol{
		"IPad": &IPad,
	}
)
View Source
var (
	ErrNoIpAvailable = errors.New("error: No ip available")
)

Functions

func BytesToFloat32

func BytesToFloat32(bytes []byte) float32

func BytesToFloat64

func BytesToFloat64(bytes []byte) float64

func BytesToInt16

func BytesToInt16(bytes []byte) int16

func BytesToInt32

func BytesToInt32(bytes []byte) int32

func BytesToInt64

func BytesToInt64(bytes []byte) int64

func Float32ToByte

func Float32ToByte(float float32) []byte

func Float64ToByte

func Float64ToByte(float float64) []byte

func GetSliderTicket

func GetSliderTicket() string

func Int16ToBytes

func Int16ToBytes(i int16) []byte

func Int32ToBytes

func Int32ToBytes(i int32) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func StartSliderCaptchaServer

func StartSliderCaptchaServer() ([]string, error)

func TlvEncode

func TlvEncode(typeId uint16, data []byte) []byte

func TlvRead

func TlvRead(data []byte, tagSizeBitNum int) map[uint16][]byte

func TlvType0x100Encode

func TlvType0x100Encode(ssoVersion uint32, appId uint32, subAppId uint32, appClientVersion uint32, mainSigmap uint32) []byte

func TlvType0x104Encode

func TlvType0x104Encode(data []byte) []byte

func TlvType0x106Encode

func TlvType0x106Encode(uin uint32, hashSalt uint32, appId uint32, subAppId uint32, appClientVersion uint32,
	ssoVersion uint32, passwordHash [16]byte, guidAvailable bool, guid, tgtgtKey []byte) []byte

func TlvType0x107Encode

func TlvType0x107Encode(picType uint16) []byte

func TlvType0x109Encode

func TlvType0x109Encode(androidId []byte) []byte

func TlvType0x116Encode

func TlvType0x116Encode(bitmap uint32, subSigmap uint32) []byte

func TlvType0x124Encode

func TlvType0x124Encode(osType []byte, osVersion []byte, simInfo []byte, address []byte, apn []byte) []byte

func TlvType0x128Encode

func TlvType0x128Encode(isGuidFromFileNull bool, isGuidAvailable bool, isGuidChanged bool, model []byte, guid []byte, brand []byte) []byte

func TlvType0x141Encode

func TlvType0x141Encode(simInfo []byte, apn []byte) []byte

func TlvType0x142Encode

func TlvType0x142Encode(apkId []byte) []byte

func TlvType0x144Encode

func TlvType0x144Encode(deviceInfo *DeviceInfo, isGuidFromFileNull bool, isGuidAvailable bool, isGuidChanged bool) []byte

func TlvType0x145Encode

func TlvType0x145Encode(guid []byte) []byte

func TlvType0x147Encode

func TlvType0x147Encode(appId uint32, apkVersion []byte, apkSign []byte) []byte

func TlvType0x154Encode

func TlvType0x154Encode(seqence uint16) []byte

func TlvType0x16EEncode

func TlvType0x16EEncode(model []byte) []byte

func TlvType0x174Encode

func TlvType0x174Encode(data []byte) []byte

func TlvType0x177Encode

func TlvType0x177Encode(buildTime uint32, sdkVersion string) []byte

func TlvType0x17AEncode

func TlvType0x17AEncode(SMSAppId uint32) []byte

func TlvType0x17CEncode

func TlvType0x17CEncode(SMSCode string) []byte

func TlvType0x187Encode

func TlvType0x187Encode(macAddress []byte) []byte

func TlvType0x188Encode

func TlvType0x188Encode(androidId []byte) []byte

func TlvType0x18Encode

func TlvType0x18Encode(appId uint32, uin uint32) []byte

func TlvType0x191Encode

func TlvType0x191Encode(canWebVerify byte) []byte

func TlvType0x193Encode

func TlvType0x193Encode(ticket string) []byte

func TlvType0x194Encode

func TlvType0x194Encode(imsiHash []byte) []byte

func TlvType0x197Encode

func TlvType0x197Encode(data []byte) []byte

func TlvType0x198Encode

func TlvType0x198Encode() []byte

func TlvType0x1Encode

func TlvType0x1Encode(uin uint32, ip []byte) []byte

func TlvType0x202Encode

func TlvType0x202Encode(wifiBSSID []byte, wifiSSID []byte) []byte

func TlvType0x401Encode

func TlvType0x401Encode(data []byte) []byte

func TlvType0x511Encode

func TlvType0x511Encode(domains []string) []byte

func TlvType0x516Encode

func TlvType0x516Encode(sourceType uint32) []byte

func TlvType0x521Encode

func TlvType0x521Encode(productType uint32) []byte

func TlvType0x525Encode

func TlvType0x525Encode(type0x536 []byte) []byte

func TlvType0x52DEncode

func TlvType0x52DEncode(deviceInfo *DeviceInfo) []byte

func TlvType0x536Encode

func TlvType0x536Encode(loginExtraData []byte) []byte

func TlvType0x8Encode

func TlvType0x8Encode(localId uint32) []byte

Types

type AtElementStruct

type AtElementStruct struct {
	TargetUin int64
	Display   string
}

type DeviceInfo

type DeviceInfo struct {
	Product      string
	Device       string
	Board        string
	Brand        string
	Model        string
	Bootloader   string
	BootId       string
	ProcVersion  string
	BaseBand     string
	VendorName   string
	VendorOSName string
	MacAddress   string
	IpAddress    []byte
	WIFISSID     string
	IMEI         string
	AndroidId    string
	FingerPrint  string
	SimInfo      string
	OsType       string
	Apn          string
	Guid         []byte
	TgtgtKey     []byte
	ImsiHash     []byte
	Version      OSVersion
	Protocol     *Protocol
}

func NewDevice

func NewDevice() *DeviceInfo

func (*DeviceInfo) FromJson

func (deviceInfo *DeviceInfo) FromJson(data []byte) error

func (*DeviceInfo) ToJson

func (deviceInfo *DeviceInfo) ToJson() []byte

type ECDHKey

type ECDHKey struct {
	ServerPublicKeyVersion uint16
	PublicKey              []byte
	ShareKey               []byte
}

func NewECDHKey

func NewECDHKey() *ECDHKey

func (*ECDHKey) GetPublicKey

func (key *ECDHKey) GetPublicKey(uin int64)

func (*ECDHKey) LoadKey

func (key *ECDHKey) LoadKey(publicKeyString string)

type LoginResponse

type LoginResponse struct {
	Success         bool
	Error           uint16
	SliderVerifyUrl string
	SMSPhoneNum     string
	Message         string
}

type NetworkPackStruct

type NetworkPackStruct struct {
	ResponseType uint32
	EncryptType  byte
	Uin          int64
	Seqence      uint16
	ReturnCode   int32
	Message      string
	CommandName  string
	SessionId    []byte
	Body         []byte
}

type OSVersion

type OSVersion struct {
	Incremental string
	Release     string
	CodeName    string
	SDK         uint32
}

type OfflineImageElementStruct

type OfflineImageElementStruct struct {
	ImageId   string
	ImageSize uint32
	ImageUrl  string
	Md5       []byte
}

type Protocol

type Protocol struct {
	ApkId      string
	AppId      uint32
	SubAppId   uint32
	Version    string
	ApkSign    []byte
	BuildTime  uint32
	SdkVersion string
	SsoVersion uint32
	Bitmap     uint32
	MainSigmap uint32
	SubSigmap  uint32
	Name       string
}

type QQClient

type QQClient struct {
	Uin                        int64
	PaswordHash                [16]byte
	Device                     *DeviceInfo
	SsoServerList              []goqqjce.SsoServerInfoStruct
	ResponsePackLock           sync.Mutex
	ResponsePackNotHandledMap  map[uint16]*NetworkPackStruct
	ResponsePackWaitChannelMap map[uint16]chan *NetworkPackStruct

	Connected         bool
	Conn              net.Conn
	PackageSequenceId *SafeInt32
	FriendSeqenceId   *SafeInt32
	SessionId         []byte
	Ksid              []byte

	Token              *Token
	WtSessionTicketKey []byte

	ECDHKey   *ECDHKey
	RandomKey []byte

	Age      byte
	Sex      byte
	NickName string

	FriendList []*goqqjce.FriendInfoStruct

	IsInit              bool
	SyncCookie          []byte
	PublicAccountCookie []byte

	Online bool
}

func NewClient

func NewClient(uin int64, paswordHash [16]byte, device *DeviceInfo) (*QQClient, error)

func (*QQClient) BuildClientRegisterPack

func (qqClient *QQClient) BuildClientRegisterPack() ([]byte, uint16)

func (*QQClient) BuildConfigPushResponsePack

func (qqClient *QQClient) BuildConfigPushResponsePack(configType int32, configBytes []byte, configSeqence int64) ([]byte, uint16)

func (*QQClient) BuildDeleteMessageRequestPack

func (qqClient *QQClient) BuildDeleteMessageRequestPack(deleteMessageList []*goqqprotobuf.MessageItem) ([]byte, uint16)

func (*QQClient) BuildFriendListRequestPack

func (qqClient *QQClient) BuildFriendListRequestPack(friendStartIndex uint16, friendListCount uint16, groupStartIndex uint8, groupListCount uint8) ([]byte, uint16)

func (*QQClient) BuildGetMessageRequestPack

func (qqClient *QQClient) BuildGetMessageRequestPack(syncFlag uint32) ([]byte, uint16)

func (*QQClient) BuildGroupListRequestPack

func (qqClient *QQClient) BuildGroupListRequestPack(cookie []byte) ([]byte, uint16)

func (*QQClient) BuildHeartBeatPack

func (qqClient *QQClient) BuildHeartBeatPack() ([]byte, uint16)

func (*QQClient) BuildLoginDeviceLockPack

func (qqClient *QQClient) BuildLoginDeviceLockPack() ([]byte, uint16)

func (*QQClient) BuildLoginPack

func (qqClient *QQClient) BuildLoginPack() ([]byte, uint16)

func (*QQClient) BuildLoginSMSRequestPack

func (qqClient *QQClient) BuildLoginSMSRequestPack() ([]byte, uint16)

func (*QQClient) BuildLoginSMSSubmitPack

func (qqClient *QQClient) BuildLoginSMSSubmitPack(SMSCode string) ([]byte, uint16)

func (*QQClient) BuildLoginSliderSendPack

func (qqClient *QQClient) BuildLoginSliderSendPack(ticket string) ([]byte, uint16)

func (*QQClient) BuildNetworkPack

func (qqClient *QQClient) BuildNetworkPack(requestType uint32, encryptType byte, seqence uint16, uin int64, commandName string, body []byte) []byte

func (*QQClient) BuildOnlinePushMessageRequestPack

func (qqClient *QQClient) BuildOnlinePushMessageRequestPack(uin int64, seqence uint16, serverIp int32, pushToken []byte, onlinePushMessageInfoList []*goqqjce.OnlinePushMessageInfoStruct) ([]byte, uint16)

func (*QQClient) BuildRequestPack

func (qqClient *QQClient) BuildRequestPack(uin int64, command uint16, encryptMethod uint8, body []byte) []byte

func (*QQClient) ClientRegister

func (qqClient *QQClient) ClientRegister() error

func (*QQClient) Connect

func (qqClient *QQClient) Connect() error

func (*QQClient) DecodeFriendGroupListResponse

func (qqClient *QQClient) DecodeFriendGroupListResponse(data []byte) (uint16, []*goqqjce.FriendInfoStruct)

func (*QQClient) DecodeGetMessageRequestPack

func (qqClient *QQClient) DecodeGetMessageRequestPack(data []byte)

func (*QQClient) DecodeGroupListResponse

func (qqClient *QQClient) DecodeGroupListResponse(data []byte) ([]*goqqjce.TroopNumStruct, []byte)

func (*QQClient) DecodeLoginResponse

func (qqClient *QQClient) DecodeLoginResponse(data []byte) *LoginResponse

func (*QQClient) DecodeLoginResponseNetworkPack

func (qqClient *QQClient) DecodeLoginResponseNetworkPack(netpackStruct *NetworkPackStruct) *LoginResponse

func (*QQClient) DecodeLoginResponseSuccessTlv

func (qqClient *QQClient) DecodeLoginResponseSuccessTlv(payload []byte)

func (*QQClient) DecodeNetworkPack

func (qqClient *QQClient) DecodeNetworkPack(data []byte) (*NetworkPackStruct, error)

func (*QQClient) DecodeRegisterResponse

func (qqClient *QQClient) DecodeRegisterResponse(data []byte) error

func (*QQClient) DecodeResponsePack

func (qqClient *QQClient) DecodeResponsePack(data []byte) (uint16, int64, []byte)

func (*QQClient) FindFriend

func (qqClient *QQClient) FindFriend(uin int64) (bool, string)

func (*QQClient) GetFriendList

func (qqClient *QQClient) GetFriendList() []*goqqjce.FriendInfoStruct

func (*QQClient) GetGroupList

func (qqClient *QQClient) GetGroupList() []*goqqjce.TroopNumStruct

func (*QQClient) GetMessage

func (qqClient *QQClient) GetMessage(syncFlag uint32)

func (*QQClient) HandleConfigPushRequest

func (qqClient *QQClient) HandleConfigPushRequest(data []byte)

func (*QQClient) HandleOnlinePushRequest

func (qqClient *QQClient) HandleOnlinePushRequest(netpack *NetworkPackStruct)

func (*QQClient) HandlePushNotifyRequest

func (qqClient *QQClient) HandlePushNotifyRequest(netpack *NetworkPackStruct)

func (*QQClient) HeartBeat

func (qqClient *QQClient) HeartBeat()

func (*QQClient) Init

func (qqClient *QQClient) Init() error

func (*QQClient) Login

func (qqClient *QQClient) Login(method uint16) (*LoginResponse, error)

func (*QQClient) NextSeqence

func (qqClient *QQClient) NextSeqence() uint16

func (*QQClient) PackRecvLoop

func (qqClient *QQClient) PackRecvLoop()

func (*QQClient) PrivateMessageDecoder

func (qqClient *QQClient) PrivateMessageDecoder(pairMessage *goqqprotobuf.Message) *UniformMessageStruct

func (*QQClient) ProcessMessage

func (qqClient *QQClient) ProcessMessage(pairMessage *goqqprotobuf.Message) *UniformMessageStruct

func (*QQClient) RecvPack

func (qqClient *QQClient) RecvPack(seqence uint16) *NetworkPackStruct

func (*QQClient) RequestSMSCode

func (qqClient *QQClient) RequestSMSCode() bool

func (*QQClient) SendPack

func (qqClient *QQClient) SendPack(pack []byte, seqence uint16) uint16

func (*QQClient) SubmitSMSCode

func (qqClient *QQClient) SubmitSMSCode(SMSCode string) (*LoginResponse, error)

func (*QQClient) SubmitSliderTicket

func (qqClient *QQClient) SubmitSliderTicket(ticket string) *LoginResponse

func (*QQClient) SyncMessage

func (qqClient *QQClient) SyncMessage(responseStruct *goqqprotobuf.GetMessageResponseStruct)

type ReplyElementStruct

type ReplyElementStruct struct {
	ReplySeqence uint32
	Time         uint32
	SenderUin    int64
	TargetUin    int64
	Elements     []*UniformRichTextElementStruct
}

type SafeInt32

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

func (*SafeInt32) Add

func (safeInt32 *SafeInt32) Add(value int32) int32

func (*SafeInt32) Get

func (safeInt32 *SafeInt32) Get() int32

func (*SafeInt32) Set

func (safeInt32 *SafeInt32) Set(value int32)

type TextElementStruct

type TextElementStruct struct {
	Text string
}

type Token

type Token struct {
	TlvType0x104Data []byte
	TlvType0x133Data []byte
	TlvType0x174Data []byte
	TlvType0x402Data []byte
	RansSeed         []byte
	Dpwd             []byte
	G                []byte
	PsKeyMap         map[string][]byte
	Pt4TokenMap      map[string][]byte
	LoginBitMap      uint32
	SrmToken         []byte
	Tgt              []byte
	TgtKey           []byte
	UserSTKey        []byte
	UserSTWebSig     []byte
	SKey             []byte
	SKeyExpiredTime  int64
	D2               []byte
	D2Key            []byte
	DeviceToken      []byte
}

type UniformMessageStruct

type UniformMessageStruct struct {
	MessageType     uint16
	MessageSeqence  uint32
	Time            uint32
	TargetUin       int64
	SenderUin       int64
	SenderNickname  string
	SenderIsFriend  bool
	SelfUin         int64
	VoiceMessage    VoiceMessageStruct
	RichTextMessage []*UniformRichTextElementStruct
}

type UniformRichTextElementStruct

type UniformRichTextElementStruct struct {
	RichTextElementType uint16
	ReplyElement        ReplyElementStruct
	AtElement           AtElementStruct
	TextElement         TextElementStruct
	OfflineImageElement OfflineImageElementStruct
}

func DecodeRichTextElements

func DecodeRichTextElements(elements []*goqqprotobuf.Element) []*UniformRichTextElementStruct

type VoiceMessageStruct

type VoiceMessageStruct struct {
	Name string
	Md5  []byte
	Size uint32
	Url  string
}

Jump to

Keyboard shortcuts

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