pgo

package module
v0.0.0-...-914b13e Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2016 License: MIT Imports: 18 Imported by: 0

README

Pokemon-Golang

Pokemon-Golang is not necessarily a bot, but it provides the set of tools in a very easy to use way to create your own bot that is custom to your needs. Examples will be released a long the way, and my own version of a bot built using this very simple API

Driven by Go's channels, concurrency, and amazingly fast protobuf interacting, this is aimed to be the fastest implementation of Pokemon-Gos API for easily building a fast, reliable, automated bot.

Please look at the dev branch if there haven't been any commits to the master branch in a bit.

TODO

  • Authentication with Google
  • Authentication with Pokemon Trainers Club
  • View Pokemon / Forts Nearby You
  • Visit Pokestops
  • Farm Pokestops
  • GPS Spoofing Interpolated As Human
  • Tasking System
  • Catch Pokemon
  • Catch Only Certain Pokemon
  • Remove Excess Items When Over X Quantities
  • Transfer Flagged Pokemon
  • Auto Hatch Eggs
  • Evolve Pokemon
  • Make Errors More Descriptive For Easier Debugging

TODO Extras

  • Add priority system to the tasking system to deem certain things more important so they run before other things (e.g. catch a rare pokemon over visiting a pokestop)

Example Usage

package main

import (
	"log"
	"reflect"

	"github.com/Gacnt/pokemon-go"
)

func main() {
	client := pgo.NewClient()
	loginInfo := new(pgo.LogOnDetails)
	loginInfo.Username = "Username"
	loginInfo.Password = "Password"
	loginInfo.AuthType = "ptc"

	client.Auth.GetToken(loginInfo)
	for event := range client.Events() {
		switch e := event.(type) {
		case *pgo.AuthedEvent:
			client.Auth.SetAuthToken(e.AuthToken)
			client.Location.SetByLocation("New York")
			client.Auth.Login()
		case *pgo.LoggedOnEvent:
			client.SetAPIUrl(e.APIUrl)
			go func() {
				for {
					go pgo.GetMapData(client)
					time.Sleep(2 * time.Second)
				}
			}()
		case *pgo.LocationSet:
			log.Println("Location has been set")
			log.Printf("%+v", *e.Location)
		case *pgo.MovingUpdateEvent:
			log.Println("Bot is walking")
			log.Println(e.DistanceTravelled, e.DistanceTotal)
		case *pgo.MovingDirectionChangedEvent:
			log.Println("Changed")
		case *pgo.FortSearchedEvent:
			log.Printf("%+v", e.Result)
		case *pgo.FortEvent:
			for _, fort := range e.Forts {
				client.Task.AddFunc(fort.Id, func() {
					fort.Search(client)
				}) // ADD OPTIONAL PRIORITY SETTING AS 3RD PARAMETER
			}
		case *pgo.FatalErrorEvent:
			log.Println(e.Err)
		default:

		}
	}
}

For documentation please visit https://godoc.org/github.com/Gacnt/pokemon-golang

This API structure was heavily inspired by Philipp15b's Go Steam API

Documentation

Index

Constants

View Source
const (
	WALKING_SPEED float64 = 1.3  // meters per second
	RUNNING_SPEED float64 = 6.4  // meters per second
	BIKING_SPEED  float64 = 12.3 // meters per second
	DRIVING_SPEED float64 = 16.7 // meters per second
)

Variables

This section is empty.

Functions

func GetMapData

func GetMapData(client *Client)

Types

type Auth

type Auth struct {
	AuthType string
	Token    string
	// contains filtered or unexported fields
}

func (*Auth) GetToken

func (a *Auth) GetToken(details *LogOnDetails)

func (*Auth) Login

func (a *Auth) Login()

func (*Auth) SetAuthToken

func (a *Auth) SetAuthToken(token string)

Helper function to set the authentication token

type AuthedEvent

type AuthedEvent struct {
	AuthToken string
}

type CatchablePokemon

type CatchablePokemon struct {
	Pokemon []*protos.MapPokemon
}

CatchablePokemon is a struct for any pokemon that are catchable

func (*CatchablePokemon) Catch

func (c *CatchablePokemon) Catch()

Catch all pokemon that are catchable

type CatchablePokemonEvent

type CatchablePokemonEvent struct {
	Pokemons *CatchablePokemon
}

type Client

type Client struct {
	Auth   *Auth
	APIUrl string

	Location *Location

	Task *Task

	MU sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Emit

func (c *Client) Emit(event interface{})

func (*Client) Events

func (c *Client) Events() <-chan interface{}

func (*Client) GetAPIUrl

func (c *Client) GetAPIUrl() string

func (*Client) SetAPIUrl

func (c *Client) SetAPIUrl(url string)

func (*Client) Token

func (c *Client) Token() string

Helper function to return the Authentication token recieved at login

func (*Client) Write

func (c *Client) Write(msg *Msg) (*protos.ResponseEnvelope, error)

Send messages to the server

type FatalErrorEvent

type FatalErrorEvent struct {
	Err error
}

This event is emitted when there is an error that will cause the bot to no longer run

type Fort

type Fort struct {
	*protos.FortData
}

func (*Fort) Search

func (f *Fort) Search(client *Client)

Search all forts

type FortEvent

type FortEvent struct {
	Forts []*Fort
}

type FortSearchedEvent

type FortSearchedEvent struct {
	Result *protos.FortSearchResponse
}

type FortSummariesEvent

type FortSummariesEvent struct {
	Summaries []*protos.FortSummary
}

type Forts

type Forts struct {
	Forts []*Fort
}

type FuncJob

type FuncJob func()

FuncJob .

func (FuncJob) Run

func (f FuncJob) Run()

Run the function task

type GymEvent

type GymEvent struct {
	Gyms *Gyms
}

type Gyms

type Gyms struct {
	Gyms []*protos.FortData
}

type Job

type Job interface {
	Run()
}

Job .

type JobToRun

type JobToRun struct {
	ID  string
	Job Job
}

type Location

type Location struct {
	Name string

	Latitude  float64
	Longitude float64
	Altitude  float64

	Moving *Moving

	MU sync.Mutex
	// contains filtered or unexported fields
}

func (*Location) GetAltitude

func (l *Location) GetAltitude() Locnum

func (*Location) GetAltitudeF

func (l *Location) GetAltitudeF() float64

func (*Location) GetLatitude

func (l *Location) GetLatitude() Locnum

func (*Location) GetLatitudeF

func (l *Location) GetLatitudeF() float64

func (*Location) GetLongitude

func (l *Location) GetLongitude() Locnum

func (*Location) GetLongitudeF

func (l *Location) GetLongitudeF() float64

func (*Location) GetNeighbors

func (l *Location) GetNeighbors() []uint64

func (*Location) Move

func (l *Location) Move(newLoc *Location, speed float64)

This will call the bot to move to a new location Note: calling this while the bot is already moving will cause its currently set destination to change to the new location. If you want your bot to visit both spots, wait until the `MovingDoneEvent` is fired before calling `Move` again This function WILL BLOCK THE EVENT LOOP if you want to move somewhere I suggest running this function in its own goroutine

func (*Location) SetAltitude

func (l *Location) SetAltitude(alt Locnum)

func (*Location) SetByCoords

func (l *Location) SetByCoords(lat, lng, alt float64)

func (*Location) SetByLocation

func (l *Location) SetByLocation(name string)

func (*Location) SetLatitude

func (l *Location) SetLatitude(lat Locnum)

func (*Location) SetLongitude

func (l *Location) SetLongitude(lon Locnum)

func (*Location) Teleport

func (l *Location) Teleport(newLoc *Location)

Teleport preferably a short distance, teleporting too far will probably result in the bot getting a soft lock which may result in unexpected and unidentifed behaviours like releasing Godzilla or worse yet, a Gyrados

type LocationSet

type LocationSet struct {
	Location *Location
}

type Locnum

type Locnum float64

func (*Locnum) String

func (l *Locnum) String() string

type LogOnDetails

type LogOnDetails struct {
	Username string
	Password string
	AuthType string
}

type LoggedOnEvent

type LoggedOnEvent struct {
	APIUrl string
}

This Event is fired once a successful authentication has been made either by connecting with Google, or Pokemon Trainer Club

type MapDataEvent

type MapDataEvent struct{}

type MapObjectsEvent

type MapObjectsEvent struct {
	MapCells []*protos.MapCell
}

type Moving

type Moving struct {
	IsMoving          bool
	Distance          float64
	DistanceTravelled float64
	Stop              chan interface{}
}

func (*Moving) Sit

func (m *Moving) Sit(client *Client)

Make the bot stop moving and sit in place

type MovingDirectionChangedEvent

type MovingDirectionChangedEvent struct {
	Location *Location
}

type MovingDoneEvent

type MovingDoneEvent struct {
	Location *Location
}

This Event is fired once the bot has reached its destination (using Location.Move)

type MovingUpdateEvent

type MovingUpdateEvent struct {
	Location          *Location
	DistanceTravelled float64
	DistanceTotal     float64
}

This Event is fired while the bot is in transit (using Location.Move)

type Msg

type Msg struct {
	RequestURL string
	Requests   []*protos.Request
}

type NearbyPokemon

type NearbyPokemon struct {
	Pokemon []*protos.NearbyPokemon
}

NearbyPokemon is a struct for any pokemon that are nearby (these pokemon will not show any latitude or longitude)

type NearbyPokemonEvent

type NearbyPokemonEvent struct {
	Pokemons *NearbyPokemon
}

type ResponseEnvelope

type ResponseEnvelope struct {
	Resp *protos.ResponseEnvelope
}

type SemiErrorEvent

type SemiErrorEvent struct {
	Err error
}

type Task

type Task struct {
	MaxTasks int

	Mu sync.Mutex
	// contains filtered or unexported fields
}

Task .

func (*Task) AddFunc

func (t *Task) AddFunc(id string, cmd func(), taskType ...string)

AddFunc Add the requested task These tasks will be processed in the order they are received taskType is optional, leaving the taskType blank will treat it as low priority taskType can be "URGENT" "HIGH" "MED" "LOW"

func (*Task) Clear

func (t *Task) Clear()

Clear removes all tasks from the queue

func (*Task) Start

func (t *Task) Start()

Start running tasks

type WildPokemon

type WildPokemon struct {
	Pokemon []*protos.WildPokemon
}

WildPokemon ...

type WildPokemonEvent

type WildPokemonEvent struct {
	Pokemons *WildPokemon
}

Jump to

Keyboard shortcuts

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