Created
May 22, 2024 14:06
-
-
Save nilsabdi/219f8db0867157d0d1c932faa3afff21 to your computer and use it in GitHub Desktop.
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
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "io/fs" | |
| "os" | |
| "reflect" | |
| "time" | |
| "github.com/paralin/go-dota2" | |
| "github.com/paralin/go-dota2/events" | |
| "github.com/paralin/go-steam" | |
| "github.com/sirupsen/logrus" | |
| ) | |
| func main() { | |
| logger := logrus.New() | |
| logger.SetLevel(logrus.DebugLevel) | |
| ctx := context.Background() | |
| loginInfo := new(steam.LogOnDetails) | |
| loginInfo.Username = "123" | |
| loginInfo.Password = "******" | |
| loginInfo.TwoFactorCode = "wb3vv" | |
| sc := steam.NewClient() | |
| dc := dota2.New(sc, logger) | |
| // Get latest Steam directory servers, this is required for Steam to work | |
| steam.InitializeSteamDirectory() | |
| sc.Connect() | |
| logger.Debug("Steam client initialized.") | |
| // Wait for the client to connect | |
| for event := range sc.Events() { | |
| switch e := event.(type) { | |
| case *steam.ConnectedEvent: | |
| logger.Debug("Connected to Steam, logging in...") | |
| // Replace with your Steam username and password | |
| sc.Auth.LogOn(loginInfo) | |
| case *steam.MachineAuthUpdateEvent: | |
| os.WriteFile("sentry", e.Hash, fs.FileMode(0666)) | |
| case *steam.LogOnDetails: | |
| logger.Debug("Logging on...") | |
| case *steam.LogOnFailedEvent: | |
| logger.Debug("Log on failed: ", e.Result) | |
| case *steam.LoggedOnEvent: | |
| logger.Debug("Logged in to Steam, initializing Dota2 sc...") | |
| dc.SetPlaying(true) | |
| time.Sleep(5 * time.Second) | |
| // Say hello the Dota GC | |
| dc.SayHello() | |
| case *events.ClientWelcomed: | |
| logger.Infoln("Client welcomed!") | |
| profileResp, err := dc.GetProfileCard(ctx, 92307178) | |
| if err != nil { | |
| logger.Errorln("Error getting profile card: ", err) | |
| } | |
| // Get doig's rank | |
| rankTier := profileResp.GetRankTier() | |
| // Doig is rank 71, which is divine 1 | |
| // 10-15: Herald, 20-25: Guardian, 30-35: Crusader, 40-45: Archon, 50-55: Legend, 60-65: Ancient, 70-75: Divine, 80-85: Immortal | |
| logger.Infoln("Rank tier: ", rankTier) | |
| matchId := uint64(7749534086) | |
| matchResp, err := dc.RequestMatchDetails(ctx, matchId) | |
| if err != nil { | |
| logger.Errorln("Error getting match details: ", err) | |
| } | |
| match := matchResp.GetMatch() | |
| url := fmt.Sprintf( | |
| "http://replay%d.valve.net/%d/%d_%d.dem.bz2", | |
| match.GetCluster(), | |
| dota2.AppID, | |
| matchId, | |
| match.GetReplaySalt(), | |
| ) | |
| logger.Infoln("Match URL: ", url) | |
| case *steam.FatalErrorEvent: | |
| logger.Fatalf("Error: %v", e) | |
| case *steam.PersonaStateEvent, *steam.AccountInfoEvent, *steam.LoginKeyEvent, | |
| *steam.FriendsListEvent, *events.GCConnectionStatusChanged, | |
| *events.ClientStateChanged: | |
| default: | |
| logger.Infoln(reflect.TypeOf(event)) | |
| logger.Infoln(event) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment