qbot

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

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

Go to latest
Published: Feb 20, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

README

qbot

基于webqq协议的qq机器人(2018-07-10测试可用)。参考借鉴SmartQQ,由于获取扫码状态url修改,原项目已经不能使用了。使用之前需要先在浏览器里登录一次webqq

注意

由于业务调整,Smart QQ从2019年1月1日起停止服务。

使用方法

go get -u -v github.com/wangsongyan/qbot
package main

import (
	"fmt"
	"io/ioutil"
	"os/exec"

	"github.com/wangsongyan/qbot"
)

func execCommand(path string) {
	c := exec.Command("cmd", "/C", "start", path)
	if err := c.Run(); err != nil {
		//fmt.Println("Error: ", err)
	}
}

func main() {
	r, _ := qbot.New()
	r.OnQRChange(func(r *qbot.Robot, qrdata []byte) {
		if err := ioutil.WriteFile("v.png", qrdata, 0666); err == nil {
			execCommand("v.png")
		}
	})
	r.OnMessage(func(r *qbot.Robot, message *qbot.Message) {
		fmt.Println(message)

		switch message.PollType {
		case "message":
			r.SendToBuddy(message.FromUin, message.Content+"\r\n\t--qbot")
		case "group_message":
			//r.SendToGroup(message.FromUin, message.Content)
		case "discu_message":
			//r.SendToDiscuss(message.FromUin, message.Content)
		}
	})
	r.Run()
}

TOLIST

  • 消息防撤回
  • 二维码发送到邮箱
  • 缓存登录信息,减少重复登录
  • 日志记录
  • 解决qq群信息、讨论组信息循环发送的问题

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseMessage

func ParseMessage(r *Robot, msg []byte) int

Types

type H

type H map[string]string

type Message

type Message struct {
	PollType string `json:"poll_type"`
	Content  string `json:"content"`
	FromUin  int    `json:"from_uin"`
	SendUin  int    `json:"send_uin"`
	MsgId    int    `json:"msg_id"`
	MsgType  int    `json:"msg_type"`
	Time     int    `json:"time"`
	ToUin    int    `json:"to_uin"`
	Atable   bool
}

type Robot

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

func New

func New() (*Robot, error)

func (*Robot) Get

func (r *Robot) Get(url string) ([]byte, error)

func (*Robot) GetCookie

func (r *Robot) GetCookie(requesturl, cookieName string) (value string)

func (*Robot) GetTimestamp

func (r *Robot) GetTimestamp() string

func (*Robot) GetToken

func (r *Robot) GetToken(t string) string

func (*Robot) OnCheckLogin

func (r *Robot) OnCheckLogin(fun func(*Robot) bool)

func (*Robot) OnLogin

func (r *Robot) OnLogin(fun func(*Robot))

func (*Robot) OnMessage

func (r *Robot) OnMessage(fun func(*Robot, *Message))

func (*Robot) OnQRChange

func (r *Robot) OnQRChange(fun func(*Robot, []byte))

func (*Robot) Post

func (r *Robot) Post(url string, param H) ([]byte, error)

func (*Robot) Request

func (r *Robot) Request(method, posturl string, param H) ([]byte, error)

func (*Robot) Run

func (r *Robot) Run()

func (*Robot) SendToBuddy

func (r *Robot) SendToBuddy(toUin int, message string) error

func (*Robot) SendToDiscuss

func (r *Robot) SendToDiscuss(toUin int, message string) error

func (*Robot) SendToGroup

func (r *Robot) SendToGroup(toUin int, message string) error

Jump to

Keyboard shortcuts

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