Last active
August 29, 2015 14:14
-
-
Save ewancook/9984041249affd9208ff to your computer and use it in GitHub Desktop.
Beginnings of a Steam Trade Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// callbacks.go | |
package main | |
import ( | |
"fmt" | |
"github.com/Philipp15b/go-steam" | |
"github.com/Philipp15b/go-steam/internal/steamlang" | |
"io/ioutil" | |
"time" | |
) | |
func ConnectedEvent(value *steam.ConnectedEvent) { | |
clientData.client.Auth.LogOn(clientData.logOnDetails) | |
} | |
func LoggedOnCallback(value *steam.LoggedOnEvent) { | |
t := int64(value.ServerTime) | |
fmt.Println("logged on at", time.Unix(t, 0)) | |
} | |
func WebSessionIdCallback(value *steam.WebSessionIdEvent) { | |
clientData.client.Web.LogOn() | |
} | |
func WebLoggedOnCallback(value *steam.WebLoggedOnEvent) { | |
clientData.client.Social.SetPersonaState(steamlang.EPersonaState_Online) | |
} | |
func NotificationCallback(value *steam.NotificationEvent) { | |
fmt.Printf("new notification (%d total)", value.Count) | |
} | |
func MachineAuthUpdateCallback(value *steam.MachineAuthUpdateEvent) { | |
ioutil.WriteFile("sentry", value.Hash, 0666) | |
} | |
func ChatMsgCallback(value *steam.ChatMsgEvent) { | |
if !value.IsMessage() { | |
return | |
} | |
fmt.Println(value.Message) | |
} | |
func FatalErrorCallback(value steam.FatalErrorEvent) { | |
panic(value.Error()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.go | |
package main | |
import ( | |
"fmt" | |
"github.com/Philipp15b/go-steam" | |
"io/ioutil" | |
) | |
type ClientData struct { | |
client *steam.Client | |
logOnDetails *steam.LogOnDetails | |
} | |
var clientData ClientData | |
func main() { | |
defer func() { | |
fmt.Println(recover()) | |
}() | |
loginInfo := new(steam.LogOnDetails) | |
loginInfo.Username = "***" | |
loginInfo.Password = "***" | |
sentryHash, e := ioutil.ReadFile("sentry") | |
if e != nil { | |
panic("no sentry file") | |
} | |
loginInfo.SentryFileHash = sentryHash | |
client := steam.NewClient() | |
client.ConnectEurope() | |
clientData.client = client | |
clientData.logOnDetails = loginInfo | |
for e := range client.Events() { | |
switch eventType := e.(type) { | |
case *steam.ConnectedEvent: | |
go ConnectedEvent(eventType) | |
case steam.FatalErrorEvent: | |
go FatalErrorCallback(eventType) | |
case *steam.LoggedOnEvent: | |
go LoggedOnCallback(eventType) | |
case *steam.WebSessionIdEvent: | |
go WebSessionIdCallback(eventType) | |
case *steam.MachineAuthUpdateEvent: | |
go MachineAuthUpdateCallback(eventType) | |
case *steam.ChatMsgEvent: | |
go ChatMsgCallback(eventType) | |
case *steam.WebLoggedOnEvent: | |
go WebLoggedOnCallback(eventType) | |
case *steam.NotificationEvent: | |
go NotificationCallback(eventType) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment